Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1264847 > unrolled thread
| Started by | Sandy Harris <sandyinchina@gmail.com> |
|---|---|
| First post | 2015-11-07 15:40 +0100 |
| Last post | 2015-11-07 19:00 +0100 |
| Articles | 11 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH 1/7] A couple of generated files Sandy Harris <sandyinchina@gmail.com> - 2015-11-07 15:40 +0100
[PATCH 3/7] Initialise pools randomly if CONFIG_RANDOM_INIT=y Sandy Harris <sandyinchina@gmail.com> - 2015-11-07 15:40 +0100
Re: [PATCH 3/7] Initialise pools randomly if CONFIG_RANDOM_INIT=y Jason Cooper <jason@lakedaemon.net> - 2015-11-07 18:20 +0100
[PATCH 7/7] Create generated/random_init.h, used by random driver Sandy Harris <sandyinchina@gmail.com> - 2015-11-07 15:40 +0100
[PATCH 2/7] Two new CONFIG options for the random(4) driver Sandy Harris <sandyinchina@gmail.com> - 2015-11-07 15:40 +0100
[PATCH 6/7] Produces generated/random_init.h for random driver Sandy Harris <sandyinchina@gmail.com> - 2015-11-07 15:40 +0100
[PATCH 5/7] Conditionals for CONFIG_RANDOM_INIT and CONFIG_RANDOM_GCM Sandy Harris <sandyinchina@gmail.com> - 2015-11-07 15:40 +0100
Re: [PATCH 1/7] A couple of generated files Jason Cooper <jason@lakedaemon.net> - 2015-11-07 18:00 +0100
Re: [PATCH 1/7] A couple of generated files Sandy Harris <sandyinchina@gmail.com> - 2015-11-07 20:00 +0100
Re: [PATCH 1/7] A couple of generated files Jason Cooper <jason@lakedaemon.net> - 2015-11-07 18:10 +0100
Re: [PATCH 1/7] A couple of generated files Sandy Harris <sandyinchina@gmail.com> - 2015-11-07 19:00 +0100
| From | Sandy Harris <sandyinchina@gmail.com> |
|---|---|
| Date | 2015-11-07 15:40 +0100 |
| Subject | [PATCH 1/7] A couple of generated files |
| Message-ID | <qscOR-3uH-1@gated-at.bofh.it> |
Signed-off-by: Sandy Harris <sandyinchina@gmail.com> --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index fd3a355..dd80bfd 100644 --- a/.gitignore +++ b/.gitignore @@ -112,3 +112,6 @@ all.config # Kdevelop4 *.kdev4 + +certs/x509_certificate_list +scripts/gen_random -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Sandy Harris <sandyinchina@gmail.com> |
|---|---|
| Date | 2015-11-07 15:40 +0100 |
| Subject | [PATCH 3/7] Initialise pools randomly if CONFIG_RANDOM_INIT=y |
| Message-ID | <qscOS-3uH-3@gated-at.bofh.it> |
| In reply to | #1264847 |
Signed-off-by: Sandy Harris <sandyinchina@gmail.com>
---
drivers/char/random.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 46 insertions(+), 4 deletions(-)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index d0da5d8..e222e0f 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -231,7 +231,7 @@
* not be attributed to the Phil, Colin, or any of authors of PGP.
*
* Further background information on this topic may be obtained from
- * RFC 1750, "Randomness Recommendations for Security", by Donald
+ * RFC 4086, "Randomness Requirements for Security", by Donald
* Eastlake, Steve Crocker, and Jeff Schiller.
*/
@@ -275,13 +275,19 @@
/*
* Configuration information
*/
+#ifdef CONFIG_RANDOM_INIT
+
+#include <generated/random_init.h>
+
+#else
#define INPUT_POOL_SHIFT 12
#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
#define OUTPUT_POOL_SHIFT 10
#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
-#define SEC_XFER_SIZE 512
-#define EXTRACT_SIZE 10
+#endif
+#define EXTRACT_SIZE 10
+#define SEC_XFER_SIZE 512
#define DEBUG_RANDOM_BOOT 0
#define LONGS(x) (((x) + sizeof(unsigned long) - 1)/sizeof(unsigned long))
@@ -296,6 +302,27 @@
#define ENTROPY_SHIFT 3
#define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
+/* sanity checks */
+
+#if ((ENTROPY_SHIFT+INPUT_POOL_SHIFT) >= 16)
+#ifndef CONFIG_64BIT
+#error *_SHIFT values problematic for credit_entropy_bits()
+#endif
+#endif
+
+#if ((INPUT_POOL_WORDS%16) || (OUTPUT_POOL_WORDS%16))
+#error Pool size not divisible by 16, which code assumes
+#endif
+
+#if (INPUT_POOL_WORDS < 32)
+#error Input pool less than a quarter of default size
+#endif
+
+#if (INPUT_POOL_WORDS < OUTPUT_POOL_WORDS)
+#error Strange configuration, input pool smalller than output
+#endif
+
+
/*
* The minimum number of bits of entropy before we wake up a read on
* /dev/random. Should be enough to do a significant reseed.
@@ -442,16 +469,23 @@ struct entropy_store {
};
static void push_to_pool(struct work_struct *work);
+
+#ifndef CONFIG_RANDOM_INIT
static __u32 input_pool_data[INPUT_POOL_WORDS];
static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
+#endif
static struct entropy_store input_pool = {
.poolinfo = &poolinfo_table[0],
.name = "input",
.limit = 1,
.lock = __SPIN_LOCK_UNLOCKED(input_pool.lock),
- .pool = input_pool_data
+#ifdef CONFIG_RANDOM_INIT
+ .pool = pools,
+#else
+ .pool = input_pool_data,
+#endif
};
static struct entropy_store blocking_pool = {
@@ -460,7 +494,11 @@ static struct entropy_store blocking_pool = {
.limit = 1,
.pull = &input_pool,
.lock = __SPIN_LOCK_UNLOCKED(blocking_pool.lock),
+#ifdef CONFIG_RANDOM_INIT
+ .pool = pools + INPUT_POOL_WORDS,
+#else
.pool = blocking_pool_data,
+#endif
.push_work = __WORK_INITIALIZER(blocking_pool.push_work,
push_to_pool),
};
@@ -470,7 +508,11 @@ static struct entropy_store nonblocking_pool = {
.name = "nonblocking",
.pull = &input_pool,
.lock = __SPIN_LOCK_UNLOCKED(nonblocking_pool.lock),
+#ifdef CONFIG_RANDOM_INIT
+ .pool = pools + INPUT_POOL_WORDS + OUTPUT_POOL_WORDS,
+#else
.pool = nonblocking_pool_data,
+#endif
.push_work = __WORK_INITIALIZER(nonblocking_pool.push_work,
push_to_pool),
};
--
2.5.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Jason Cooper <jason@lakedaemon.net> |
|---|---|
| Date | 2015-11-07 18:20 +0100 |
| Subject | Re: [PATCH 3/7] Initialise pools randomly if CONFIG_RANDOM_INIT=y |
| Message-ID | <qsfjI-5c8-3@gated-at.bofh.it> |
| In reply to | #1264848 |
On Sat, Nov 07, 2015 at 09:30:38AM -0500, Sandy Harris wrote:
> Signed-off-by: Sandy Harris <sandyinchina@gmail.com>
> ---
> drivers/char/random.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 46 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/char/random.c b/drivers/char/random.c
> index d0da5d8..e222e0f 100644
> --- a/drivers/char/random.c
> +++ b/drivers/char/random.c
> @@ -231,7 +231,7 @@
> * not be attributed to the Phil, Colin, or any of authors of PGP.
> *
> * Further background information on this topic may be obtained from
> - * RFC 1750, "Randomness Recommendations for Security", by Donald
> + * RFC 4086, "Randomness Requirements for Security", by Donald
I'm pretty sure you already sent this hunk separately. Please remove it
from the next version.
thx,
Jason.
> * Eastlake, Steve Crocker, and Jeff Schiller.
> */
>
> @@ -275,13 +275,19 @@
> /*
> * Configuration information
> */
> +#ifdef CONFIG_RANDOM_INIT
> +
> +#include <generated/random_init.h>
> +
> +#else
> #define INPUT_POOL_SHIFT 12
> #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
> #define OUTPUT_POOL_SHIFT 10
> #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
> -#define SEC_XFER_SIZE 512
> -#define EXTRACT_SIZE 10
> +#endif
>
> +#define EXTRACT_SIZE 10
> +#define SEC_XFER_SIZE 512
> #define DEBUG_RANDOM_BOOT 0
>
> #define LONGS(x) (((x) + sizeof(unsigned long) - 1)/sizeof(unsigned long))
> @@ -296,6 +302,27 @@
> #define ENTROPY_SHIFT 3
> #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
>
> +/* sanity checks */
> +
> +#if ((ENTROPY_SHIFT+INPUT_POOL_SHIFT) >= 16)
> +#ifndef CONFIG_64BIT
> +#error *_SHIFT values problematic for credit_entropy_bits()
> +#endif
> +#endif
> +
> +#if ((INPUT_POOL_WORDS%16) || (OUTPUT_POOL_WORDS%16))
> +#error Pool size not divisible by 16, which code assumes
> +#endif
> +
> +#if (INPUT_POOL_WORDS < 32)
> +#error Input pool less than a quarter of default size
> +#endif
> +
> +#if (INPUT_POOL_WORDS < OUTPUT_POOL_WORDS)
> +#error Strange configuration, input pool smalller than output
> +#endif
> +
> +
> /*
> * The minimum number of bits of entropy before we wake up a read on
> * /dev/random. Should be enough to do a significant reseed.
> @@ -442,16 +469,23 @@ struct entropy_store {
> };
>
> static void push_to_pool(struct work_struct *work);
> +
> +#ifndef CONFIG_RANDOM_INIT
> static __u32 input_pool_data[INPUT_POOL_WORDS];
> static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
> static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
> +#endif
>
> static struct entropy_store input_pool = {
> .poolinfo = &poolinfo_table[0],
> .name = "input",
> .limit = 1,
> .lock = __SPIN_LOCK_UNLOCKED(input_pool.lock),
> - .pool = input_pool_data
> +#ifdef CONFIG_RANDOM_INIT
> + .pool = pools,
> +#else
> + .pool = input_pool_data,
> +#endif
> };
>
> static struct entropy_store blocking_pool = {
> @@ -460,7 +494,11 @@ static struct entropy_store blocking_pool = {
> .limit = 1,
> .pull = &input_pool,
> .lock = __SPIN_LOCK_UNLOCKED(blocking_pool.lock),
> +#ifdef CONFIG_RANDOM_INIT
> + .pool = pools + INPUT_POOL_WORDS,
> +#else
> .pool = blocking_pool_data,
> +#endif
> .push_work = __WORK_INITIALIZER(blocking_pool.push_work,
> push_to_pool),
> };
> @@ -470,7 +508,11 @@ static struct entropy_store nonblocking_pool = {
> .name = "nonblocking",
> .pull = &input_pool,
> .lock = __SPIN_LOCK_UNLOCKED(nonblocking_pool.lock),
> +#ifdef CONFIG_RANDOM_INIT
> + .pool = pools + INPUT_POOL_WORDS + OUTPUT_POOL_WORDS,
> +#else
> .pool = nonblocking_pool_data,
> +#endif
> .push_work = __WORK_INITIALIZER(nonblocking_pool.push_work,
> push_to_pool),
> };
> --
> 2.5.0
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Sandy Harris <sandyinchina@gmail.com> |
|---|---|
| Date | 2015-11-07 15:40 +0100 |
| Subject | [PATCH 7/7] Create generated/random_init.h, used by random driver |
| Message-ID | <qscOS-3uH-9@gated-at.bofh.it> |
| In reply to | #1264847 |
Signed-off-by: Sandy Harris <sandyinchina@gmail.com> --- Kbuild | 21 +++++++++++++++++++++ scripts/Makefile | 1 + 2 files changed, 22 insertions(+) diff --git a/Kbuild b/Kbuild index f55cefd..494c665 100644 --- a/Kbuild +++ b/Kbuild @@ -5,6 +5,7 @@ # 2) Generate timeconst.h # 3) Generate asm-offsets.h (may need bounds.h and timeconst.h) # 4) Check for missing system calls +# 5) Generate random_init.h # Default sed regexp - multiline due to syntax constraints define sed-y @@ -98,3 +99,23 @@ missing-syscalls: scripts/checksyscalls.sh $(offsets-file) FORCE # Keep these three files during make clean no-clean-files := $(bounds-file) $(offsets-file) $(timeconst-file) + +##### +# 5) Generate random_init.h + +ifdef CONFIG_RANDOM_INIT +init-file := include/generated/random_init.h +used-file := scripts/gen_random +source-file := $(used-file).c +always += $(init-file) +targets += $(init-file) +$(init-file) : $(used-file) + $(Q) $(used-file) > $(init-file) +ifdef CONFIG_RANDOM_GCM +$(used-file) : $(source-file) + $(CC) $< -DCONFIG_RANDOM_GCM -o $@ +else +$(used-file) : $(source-file) + $(CC) $< -o $@ +endif +endif diff --git a/scripts/Makefile b/scripts/Makefile index 1b26617..3cea546 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -18,6 +18,7 @@ hostprogs-$(CONFIG_BUILDTIME_EXTABLE_SORT) += sortextable hostprogs-$(CONFIG_ASN1) += asn1_compiler hostprogs-$(CONFIG_MODULE_SIG) += sign-file hostprogs-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += extract-cert +hostprogs-$(CONFIG_RANDOM_INIT) += gen_random HOSTCFLAGS_sortextable.o = -I$(srctree)/tools/include HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Sandy Harris <sandyinchina@gmail.com> |
|---|---|
| Date | 2015-11-07 15:40 +0100 |
| Subject | [PATCH 2/7] Two new CONFIG options for the random(4) driver |
| Message-ID | <qscOS-3uH-21@gated-at.bofh.it> |
| In reply to | #1264847 |
Signed-off-by: Sandy Harris <sandyinchina@gmail.com> --- drivers/char/Kconfig | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index a043107..0e0e6b5 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -603,5 +603,28 @@ config TILE_SROM source "drivers/char/xillybus/Kconfig" + +config RANDOM_INIT + bool "Initialise random(4) pools with random data (NEW)" + default n + help + Use /dev/urandom on development machine to set + up pools, different for each compile. + Compiles scripts/gen_random_init.c + Creates include/generated/random_init.h + +config RANDOM_GCM + bool "modified random(4) driver (EXPERIMENTAL)" + depends on RANDOM_INIT + default n + help + New version using the hash from AES-GCM. + Main goal decoupling so that heavy use of + /dev/urandom cannot deplete entropy for + /dev/random. + Should not be used in production before much + more analysis and testing is done. + When in doubt, say "N". + endmenu -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Sandy Harris <sandyinchina@gmail.com> |
|---|---|
| Date | 2015-11-07 15:40 +0100 |
| Subject | [PATCH 6/7] Produces generated/random_init.h for random driver |
| Message-ID | <qscOS-3uH-23@gated-at.bofh.it> |
| In reply to | #1264847 |
Signed-off-by: Sandy Harris <sandyinchina@gmail.com>
---
scripts/gen_random.c | 260 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 260 insertions(+)
create mode 100644 scripts/gen_random.c
diff --git a/scripts/gen_random.c b/scripts/gen_random.c
new file mode 100644
index 0000000..07b447f
--- /dev/null
+++ b/scripts/gen_random.c
@@ -0,0 +1,260 @@
+/*
+ * Program to select random numbers for initialising things
+ * in the random(4) driver.
+ *
+ * A different implementation of basically the same idea is
+ * one of several kernel security enhancements at
+ * https://grsecurity.net/
+ *
+ * This program:
+ *
+ * limits the range of Hamming weights
+ * every byte has at least one bit 1, one 0
+ * different every time it runs
+ *
+ * data from /dev/urandom
+ * results suitable for inclusion by random.c
+ * writes to stdout, expecting makefile to redirect
+ *
+ * makefile should also delete the output file after it is
+ * used in compilation of random.c. This is more secure; it
+ * forces the file to be rebuilt and a new version used in
+ * every compile. It also prevents an enemy just reading an
+ * output file in the build directory and getting the data
+ * that is in use in the current kernel. This is not full
+ * protection since they might look in the kernel image,
+ * but it seems to be the best we can do.
+ *
+ * This falls well short of the ideal initialisation solution,
+ * which would give every installation (rather than every
+ * compiled kernel) a different seed. For that, see John
+ * Denker's suggestions at:
+ * http://www.av8n.com/computer/htm/secure-random.htm#sec-boot-image
+ *
+ * On the other hand, neither sort of seed is necessary if
+ * either you have a trustworthy hardware RNG
+ * or you have secure stored data
+ * In those cases, the device can easily be initialised well; the
+ * only difficulty is to ensure this is done early enough.
+ *
+ * Inserting random data at compile time can do no harm and may
+ * sometimes make attacks harder. It is not an ideal solution, and
+ * not always necessary, but cheap and probably the best we can do
+ * during the build (rather than install) process.
+ *
+ * This is certainly done early enough and the data is random
+ * enough, but it is not necessarily secret enough.
+ *
+ * In some cases -- for example, a firewall machine that compiles
+ * its own kernel -- this alone might be enough to ensure secure
+ * initialisation, since only an enemy who already has root could
+ * discover this data. Of course even in those cases it should not
+ * be used alone, only as one layer of a defense in depth.
+ *
+ * In other cases -- a kernel that is compiled once then used in
+ * a Linux distro or installed on many devices -- this is likely
+ * of very little value. It complicates an attack somewhat, but
+ * it clearly will not stop a serious attacker and may not even
+ * slow them down much.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <ctype.h>
+
+/*
+ * Configuration information
+ * moved from random.c
+ */
+#define INPUT_POOL_SHIFT 12
+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
+#define OUTPUT_POOL_SHIFT 10
+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
+
+#define TOTAL_POOL_WORDS (INPUT_POOL_WORDS + 2*OUTPUT_POOL_WORDS)
+
+typedef uint32_t u32 ;
+
+int accept(u32) ;
+int hamming(u32);
+void do_block( int, char * ) ;
+void usage(void) ;
+
+int urandom ;
+
+int main(int argc, char **argv)
+{
+ if( (urandom = open("/dev/urandom", O_RDONLY)) == -1 ) {
+ fprintf(stderr, "gen_random_init: no /dev/urandom, cannot continue\n") ;
+ exit(1) ;
+ }
+ printf("/* File generated by gen_random_init.c */\n\n") ;
+ /*
+ * print our constants into output file
+ * ensuring random.c has the same values
+ */
+ printf("#define INPUT_POOL_WORDS %d\n", INPUT_POOL_WORDS) ;
+ printf("#define OUTPUT_POOL_WORDS %d\n", OUTPUT_POOL_WORDS) ;
+ printf("#define INPUT_POOL_SHIFT %d\n\n", INPUT_POOL_SHIFT) ;
+
+ /*
+ * Initialise the pools with random data
+ * This is done unconditionally
+ */
+ do_block( TOTAL_POOL_WORDS, "pools" ) ;
+
+#ifdef CONFIG_RANDOM_GCM
+
+#define ARRAY_ROWS 8 /* 4 pools get 2 constants each */
+#define ARRAY_WORDS (4 * ARRAY_ROWS) /* 32-bit words, 128-bit constants */
+
+/*
+ * If we are using the GCM hash, set up an array of random
+ * constants for it.
+ *
+ * The choice of 32 words (eight 128-bit rows, 1024 bits) for
+ * this is partly arbitrary, partly reasoned. 256 bits would
+ * almost certainly be enough, but 1024 is convenient.
+ *
+ * The AES-GCM hash initialises its accumulator all-zero and uses
+ * a 128-bit multiplier, H. I chose instead to use two constants,
+ * one to initialise the accumulator and one in the role of H.
+ *
+ * This requires that a pair of 128-bit constants be used in each
+ * output operation. I have four pools and chose to give each pool
+ * its own pair instead of using one pair for all pools. I then
+ * chose to initialise all eight with random data.
+ *
+ * Any of those choices might be changed, but all seem reasonable.
+ *
+ * Add an extra 8 words for a counter used in the hashing
+ * 128-bit counter with some extra data for mixing
+ */
+ printf("#define ARRAY_WORDS %d\n\n", ARRAY_WORDS) ;
+
+ do_block( (ARRAY_WORDS + 8), "constants" ) ;
+ printf("static u32 *counter = constants + ARRAY_WORDS ;\n") ;
+
+#endif /* CONFIG_RANDOM_GCM */
+
+ exit(0) ;
+}
+
+/*
+ * each call outputs one array of nwords 32-bit words
+ * with the given array name
+ */
+
+#define PER_LINE 8
+
+void do_block( int nwords, char *name )
+{
+ int nbytes, i, x ;
+ u32 *p, *data ;
+
+ nbytes = 4 * nwords ;
+
+ if( (data = calloc( (size_t) nwords, 4)) == NULL ) {
+ fprintf(stderr, "gen_random_init: calloc() failed, cannot continue\n") ;
+ exit(1) ;
+ }
+
+ /* normal case: we have memory */
+ x = read( urandom, data, nbytes ) ;
+ if( x != nbytes ) {
+ fprintf(stderr,"gen_random_int: read() failed, cannot contiue\n") ;
+ exit(1) ;
+ }
+
+ /*
+ * Replace any array entries that fail criteria
+ *
+ * In theory, the while loop here could run for some
+ * ridiculously long time, or even go infinite
+ * In practice, this is astronomically unlikely
+ * given any sensible definition of accept() and
+ * input that is anywhere near random
+ */
+ for( i = 0, x = 1, p = data ; x && (i < nwords) ; i++, p++ ) {
+ while( !accept(*p) )
+ x = read( urandom, (char *) p, 4) ;
+ }
+
+ /* output an array of random data */
+ printf("static u32 %s[] = {\n", name ) ;
+ for( i = 0 ; i < nwords ; i ++ ) {
+ printf("0x%08x", data[i]) ;
+ if( i == (nwords-1) )
+ printf( " } ;\n" ) ;
+ else if( (i%PER_LINE) == (PER_LINE-1) )
+ printf( ",\n" ) ;
+ else printf( ", " ) ;
+ }
+ printf("\n") ;
+ free( data ) ;
+}
+
+void usage()
+{
+ fprintf(stderr, "usage: gen_random_init\n") ;
+ exit(1) ;
+}
+
+/*
+ * These tests are not strictly necessary
+ *
+ * We could just use the /dev/urandom output & take what comes
+ * Arguably, that would be the best course;
+ * "If it ain't broke, don't fix it."
+ *
+ * Applying any bias here makes output somewhat less random,
+ * so easier for an enemy to guess.
+ *
+ * However, a Hamming weight near 16 gives a chance close
+ * to 50/50 that using one of these numbers in arithmetic
+ * (+, xor or various forms of multiplication) will change
+ * any given bit. This is a highly desirable effect.
+ *
+ * Compromise: apply some bias, but not a very strong one
+ */
+
+#define MIN 8
+#define MAX (32-MIN)
+
+int accept( u32 u )
+{
+ int h, i ;
+ char *p ;
+
+ /* reject low or high Hamming weights */
+ h = hamming(u) ;
+ if( ( h < MIN ) || ( h > MAX ) )
+ return(0) ;
+
+ /* at least one 1 and at least one 0 in each byte */
+ for( i = 0, p = (char *) &u ; i < 4 ; i++, p++ ) {
+ switch(*p) {
+ case '\0':
+ case '\255':
+ return(0) ;
+ default:
+ break ;
+ }
+ }
+ return(1) ;
+}
+
+/*
+ * Kernighan's method
+ * http://graphics.stanford.edu/~seander/bithacks.html
+ */
+int hamming( u32 x )
+{
+ int h ;
+ for (h = 0 ; x ; h++)
+ x &= (x-1) ; /* clear the least significant bit set */
+ return(h) ;
+}
--
2.5.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Sandy Harris <sandyinchina@gmail.com> |
|---|---|
| Date | 2015-11-07 15:40 +0100 |
| Subject | [PATCH 5/7] Conditionals for CONFIG_RANDOM_INIT and CONFIG_RANDOM_GCM |
| Message-ID | <qscOS-3uH-19@gated-at.bofh.it> |
| In reply to | #1264847 |
Signed-off-by: Sandy Harris <sandyinchina@gmail.com> --- drivers/char/Makefile | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/char/Makefile b/drivers/char/Makefile index d8a7579..7d095e5 100644 --- a/drivers/char/Makefile +++ b/drivers/char/Makefile @@ -2,7 +2,30 @@ # Makefile for the kernel character device drivers. # -obj-y += mem.o random.o +obj-y += mem.o + +ifeq ($(CONFIG_RANDOM_GCM),y) + random_c = random_gcm.c + random_o = random_gcm.o + random_no = random.o +else + random_c = random.c + random_o = random.o + random_no = random_gcm.o +endif +obj-y += $(random_o) + +# remove the generated file after use so that +# a fresh one is built (by scripts/gen_random) +# for every compile +# remove random_no so it will not get linked +ifeq ($(CONFIG_RANDOM_INIT),y) +init-file = include/generated/random_init.h +$(random_o): $(random_c) $(init-file) + $(CC) $< -o $@ + $(Q) rm --force $(init-file) $(random_no) +endif + obj-$(CONFIG_TTY_PRINTK) += ttyprintk.o obj-y += misc.o obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Jason Cooper <jason@lakedaemon.net> |
|---|---|
| Date | 2015-11-07 18:00 +0100 |
| Message-ID | <qsf0l-4OL-1@gated-at.bofh.it> |
| In reply to | #1264847 |
Hey Sandy, I know we talked about this series offlist, but we need to fill in folks who are seeing it for the first time. Usually, this is done with a coverletter (--coverletter for git format-patch). No need to resend before receiving feedback, but would you mind replying with a description of the problem you're attempting to solve and how the series solves it? thx, Jason. On Sat, Nov 07, 2015 at 09:30:36AM -0500, Sandy Harris wrote: > Signed-off-by: Sandy Harris <sandyinchina@gmail.com> > --- > .gitignore | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/.gitignore b/.gitignore > index fd3a355..dd80bfd 100644 > --- a/.gitignore > +++ b/.gitignore > @@ -112,3 +112,6 @@ all.config > > # Kdevelop4 > *.kdev4 > + > +certs/x509_certificate_list > +scripts/gen_random > -- > 2.5.0 > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Sandy Harris <sandyinchina@gmail.com> |
|---|---|
| Date | 2015-11-07 20:00 +0100 |
| Message-ID | <qsgSu-631-9@gated-at.bofh.it> |
| In reply to | #1264886 |
Jason Cooper <jason@lakedaemon.net> wrote: > I know we talked about this series offlist, but we need to fill in > folks who are seeing it for the first time. Usually, this is done with > a coverletter (--coverletter for git format-patch). Yes, your help plus the O'Reilly book got me using git without too many errors, but I'm still getting things wrong & missing the cover letter was one. > No need to resend > before receiving feedback, but would you mind replying with a > description of the problem you're attempting to solve and how the series > solves it? There are two groups of changes, each controlled by a config variable. Default for both is 'n'. CONFIG_RANDOM_INIT: initialise the pools with data from /dev/urandom on the machine that compiles the kernel. Comments for the generator program scripts/gen_random.c have details. The main change in random.c is adding conditionals to make it use the random data if CONFIG_RANDOM_INIT is set. There is also a trivial fix updating a reference to an obsoleted in a comment, and I added some sanity-check #if tests for odd #define parameter values. This is a fairly simple change. I do not think it needs a config variable; it should just be the default. However I put it under config control for testing. CONFIG_RANDOM_GCM controls a much larger and less clearly desirable set of changes. It switches compilation between random.c and and a heavily modified version random_gcm.c This uses the hash from AES-GCM instead of SHA-1, and that allows a lot of other changes. The main design goal was to decouple the two output pools so that heavy use of the nonblocking pool cannot deplete entropy in the input pool. The nonblocking pool usually rekeys from the blocking pool instead. random_gcm.c has extensive comments on both the rationale for this approach & the details of my implementation. random_gcm.c is not close to being a finished product, in particular my code is not yet well integrated with existing driver code. Most of the code was developed and has been fairly well tested outside the kernel. Test program is at: https://github.com/sandy-harris/random.test I just dropped a large chunk of that code into a copy of random.c, made modifications to make the style match better & to get it to compile in the kernel context, then deleted a few chunks of existing driver code and replaced them with calls to my stuff. Proper integration would involve both replacing more of the existing code with new and moving a few important bits of the existing code into some of my functions. In particular, my stuff does not yet block in the right places. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Jason Cooper <jason@lakedaemon.net> |
|---|---|
| Date | 2015-11-07 18:10 +0100 |
| Message-ID | <qsfa2-58t-9@gated-at.bofh.it> |
| In reply to | #1264847 |
On Sat, Nov 07, 2015 at 09:30:36AM -0500, Sandy Harris wrote: > Signed-off-by: Sandy Harris <sandyinchina@gmail.com> > --- > .gitignore | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/.gitignore b/.gitignore > index fd3a355..dd80bfd 100644 > --- a/.gitignore > +++ b/.gitignore > @@ -112,3 +112,6 @@ all.config > > # Kdevelop4 > *.kdev4 > + > +certs/x509_certificate_list > +scripts/gen_random Is there a .gitignore file in scripts/ ? thx, Jason. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Sandy Harris <sandyinchina@gmail.com> |
|---|---|
| Date | 2015-11-07 19:00 +0100 |
| Message-ID | <qsfWq-5pJ-13@gated-at.bofh.it> |
| In reply to | #1264887 |
On Sat, Nov 7, 2015 at 12:01 PM, Jason Cooper <jason@lakedaemon.net> wrote: > On Sat, Nov 07, 2015 at 09:30:36AM -0500, Sandy Harris wrote: >> Signed-off-by: Sandy Harris <sandyinchina@gmail.com> >> --- >> .gitignore | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/.gitignore b/.gitignore >> index fd3a355..dd80bfd 100644 >> --- a/.gitignore >> +++ b/.gitignore >> @@ -112,3 +112,6 @@ all.config >> >> # Kdevelop4 >> *.kdev4 >> + >> +certs/x509_certificate_list >> +scripts/gen_random > > Is there a .gitignore file in scripts/ ? > Yes, though I wasn't aware of that. I guess gen_random should be there instead of in the global file. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web