Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/tls-earlyentropy]: src Replace "ccrand" ChaCha implementation of cprng_f...
details: https://anonhg.NetBSD.org/src/rev/04b1c6e68cda
branches: tls-earlyentropy
changeset: 795275:04b1c6e68cda
user: tls <tls%NetBSD.org@localhost>
date: Sat Aug 09 06:19:50 2014 +0000
description:
Replace "ccrand" ChaCha implementation of cprng_fast with Taylor's smaller
and somewhat simpler one. Fix rump builds so we can build a distribution.
diffstat:
sys/conf/files | 6 +-
sys/crypto/ccrand/ccrand.h | 196 ---------
sys/crypto/ccrand/ccrand2.c | 47 --
sys/crypto/ccrand/ccrand32.c | 47 --
sys/crypto/ccrand/ccrand64.c | 47 --
sys/crypto/ccrand/ccrand_bytes.c | 148 -------
sys/crypto/ccrand/ccrand_gen16.c | 149 -------
sys/crypto/ccrand/ccrand_reseed.c | 123 -----
sys/crypto/ccrand/ccrand_seed.c | 186 ---------
sys/crypto/ccrand/ccrand_seed32.c | 51 --
sys/crypto/ccrand/ccrand_seed64.c | 56 --
sys/crypto/ccrand/ccrand_use.c | 53 --
sys/crypto/ccrand/ccrand_var.h | 135 ------
sys/crypto/ccrand/ccrand_words.c | 106 -----
sys/crypto/ccrand/ccrandn.c | 47 --
sys/crypto/ccrand/files.ccrand | 15 -
sys/crypto/cprng_fast/cprng_fast.c | 496 ++++++++++++++++++++++++
sys/crypto/cprng_fast/cprng_fast.h | 9 +
sys/crypto/cprng_fast/files.cprng_fast | 3 +
sys/kern/subr_cprng.c | 167 +-------
sys/rump/librump/rumpkern/Makefile.rumpkern | 6 +-
sys/sys/cprng.h | 11 +-
sys/sys/rnd.h | 4 +-
usr.sbin/npf/npftest/libnpftest/npf_test_subr.c | 6 +-
24 files changed, 527 insertions(+), 1587 deletions(-)
diffs (truncated from 2337 to 300 lines):
diff -r cefa65dd3836 -r 04b1c6e68cda sys/conf/files
--- a/sys/conf/files Thu Jul 17 14:03:33 2014 +0000
+++ b/sys/conf/files Sat Aug 09 06:19:50 2014 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.1090.2.1 2014/07/17 14:03:33 tls Exp $
+# $NetBSD: files,v 1.1090.2.2 2014/08/09 06:19:50 tls Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
version 20100430
@@ -160,13 +160,15 @@
include "crypto/rijndael/files.rijndael"
include "crypto/skipjack/files.skipjack"
include "crypto/camellia/files.camellia"
-include "crypto/ccrand/files.ccrand"
# General-purpose crypto processing framework.
include "opencrypto/files.opencrypto"
# NIST SP800.90 CTR DRBG
include "crypto/nist_ctr_drbg/files.nist_ctr_drbg"
+# ChaCha-based fast PRNG
+include "crypto/cprng_fast/files.cprng_fast"
+
#
# Kernel history/tracing. Old UVMHIST depends upon this.
#
diff -r cefa65dd3836 -r 04b1c6e68cda sys/crypto/ccrand/ccrand.h
--- a/sys/crypto/ccrand/ccrand.h Thu Jul 17 14:03:33 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,196 +0,0 @@
-/* $NetBSD: ccrand.h,v 1.1.2.1 2014/07/17 14:03:33 tls Exp $ */
-
-/*
- * Copyright (c) 2014 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Dennis Ferguson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * ccrand.h
- *
- * Definitions for the chacha-based pseudo-random number generator
- */
-#ifndef __CCRAND_H__
-#define __CCRAND_H__
-#include <sys/types.h>
-#include <sys/null.h>
-
-/*
- * Context structure. Just 32 words. The first 16 buffer previously
- * generated but unused values, the last 16 are our key state.
- */
-typedef struct __ccrand_t {
- uint32_t v[32];
-} ccrand_t;
-
-
-/*
- * Declarations of functions which are always external
- */
-void ccrand_copy_state(ccrand_t * __restrict, const ccrand_t * __restrict);
-void ccrand_seed(ccrand_t *, const uint32_t *, unsigned int);
-void ccrand_reseed(ccrand_t *, const uint32_t *, unsigned int);
-void ccrand_seed32(ccrand_t *, uint32_t);
-void ccrand_seed64(ccrand_t *, uint64_t);
-void ccrand_bytes(ccrand_t * __restrict, void * __restrict, size_t);
-void ccrand_words(ccrand_t *, uint32_t *, unsigned int);
-uint64_t ccrand_use(ccrand_t *);
-
-uint32_t __ccrand_gen16(uint32_t *, uint32_t *);
-
-/*
- * __ccrand_getword_inline()
- *
- * Internal function to get a 32 bit random word. It
- * doesn't check whether the cipher has been seeded.
- */
-static inline uint32_t
-__ccrand_getword_inline(ccrand_t *x)
-{
- uint32_t r;
-
- if (x->v[0] == 16) {
- r = __ccrand_gen16(&x->v[0], &x->v[16]);
- } else {
- r = x->v[x->v[0]++];
- }
-
- return (r);
-}
-
-
-/*
- * __ccrand32_inline()
- *
- * Return a 32 bit random value.
- */
-static inline uint32_t
-__ccrand32_inline(ccrand_t *x)
-{
-
- if ((x->v[0] - 1) >= 16) {
- ccrand_seed(x, 0, 0);
- }
-
- return (__ccrand_getword_inline(x));
-}
-
-
-/*
- * __ccrand64_inline()
- *
- * Return a 64 bit random value.
- */
-static inline uint64_t
-__ccrand64_inline(ccrand_t *x)
-{
- uint32_t r0, r1;
-
- if ((x->v[0] - 1) >= 16) {
- ccrand_seed(x, 0, 0);
- }
-
- switch (x->v[0]) {
- case 16:
- r0 = __ccrand_gen16(&x->v[0], &x->v[16]);
- r1 = x->v[x->v[0]++];
- break;
-
- case 15:
- r0 = x->v[15];
- r1 = __ccrand_gen16(&x->v[0], &x->v[16]);
- break;
-
- default:
- r0 = x->v[x->v[0]++];
- r1 = x->v[x->v[0]++];
- break;
- }
-
- return (((uint64_t) r1 << 32) | (uint64_t) r0);
-}
-
-
-/*
- * __ccrand2_inline()
- *
- * Return a 32 bit value betweeen 0 and (2^n - 1), inclusive
- */
-static inline uint32_t
-__ccrand2_inline(ccrand_t *x, unsigned int n)
-{
- uint32_t r;
-
- if ((n - 1) > 31) {
- r = 0;
- } else {
- r = __ccrand32_inline(x);
- r &= 0xffffffff >> (32 - n);
- }
-
- return (r);
-}
-
-
-/*
- * __ccrandn_inline()
- *
- * Return a 32 bit value between 0 and n-1, inclusive. The results
- * will be a wee bit biased when n is not a power of 2, with the worst
- * case being values just under 2048 where the bias will approach
- * 2^-21.
- */
-static inline uint32_t
-__ccrandn_inline(ccrand_t *x, uint32_t n)
-{
- uint64_t rl;
-
- rl = (uint64_t) n * __ccrand32_inline(x);
- if (n > 2048) {
- rl += ((uint64_t) n * __ccrand_getword_inline(x)) >> 32;
- }
- return ((uint32_t) (rl >> 32));
-}
-
-/*
- * Now the remaining declarations. Define them as the inline versions
- * if he wants that, or as externals otherwise.
- */
-#ifdef CCRAND_INLINE
-#define ccrand32(x) __ccrand32_inline((x))
-#define ccrand64(x) __ccrand64_inline((x))
-#define ccrand2(x, n) __ccrand2_inline((x), (n))
-#define ccrandn(x, n) __ccrandn_inline((x), (n))
-#else /* CCRAND_INLINE */
-uint32_t ccrand32(ccrand_t *);
-uint64_t ccrand64(ccrand_t *);
-uint32_t ccrand2(ccrand_t *, unsigned int);
-uint32_t ccrandn(ccrand_t *, uint32_t);
-#endif /* CCRAND_INLINE */
-
-#endif /* __CCRAND_H__ */
-
diff -r cefa65dd3836 -r 04b1c6e68cda sys/crypto/ccrand/ccrand2.c
--- a/sys/crypto/ccrand/ccrand2.c Thu Jul 17 14:03:33 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/* $NetBSD: ccrand2.c,v 1.1.2.1 2014/07/17 14:03:33 tls Exp $ */
-
-/*
- * Copyright (c) 2014 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Dennis Ferguson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * ccrand2.c
- */
-#include <crypto/ccrand/ccrand_var.h>
-
-/*
- * ccrand2()
- *
- * Call the inline function to instantiate it in the library.
- */
-uint32_t
-ccrand2(ccrand_t *x, unsigned int n)
-{
-
- return (__ccrand2_inline(x, n));
-}
diff -r cefa65dd3836 -r 04b1c6e68cda sys/crypto/ccrand/ccrand32.c
--- a/sys/crypto/ccrand/ccrand32.c Thu Jul 17 14:03:33 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/* $NetBSD: ccrand32.c,v 1.1.2.1 2014/07/17 14:03:33 tls Exp $ */
-
-/*
- * Copyright (c) 2014 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Dennis Ferguson.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
Home |
Main Index |
Thread Index |
Old Index