diff options
author | Stephan Mueller <smueller@chronox.de> | 2015-06-08 22:08:49 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2015-06-09 10:26:00 -0400 |
commit | fbb145bc0a1c03b90a96cca99dc07c33aaad2318 (patch) | |
tree | 27e29447feac622abe0553ab12e695d94b0f48f6 | |
parent | 70c3c8a96a85d333b3ff1f24df84c0e179261a8a (diff) |
crypto: drbg - use pragmas for disabling optimization
Replace the global -O0 compiler flag from the Makefile with GCC
pragmas to mark only the functions required to be compiled without
optimizations.
This patch also adds a comment describing the rationale for the
functions chosen to be compiled without optimizations.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/Makefile | 1 | ||||
-rw-r--r-- | crypto/jitterentropy.c | 30 |
2 files changed, 26 insertions, 5 deletions
diff --git a/crypto/Makefile b/crypto/Makefile index 83b3c4496ec7..c84203572477 100644 --- a/crypto/Makefile +++ b/crypto/Makefile | |||
@@ -97,7 +97,6 @@ obj-$(CONFIG_CRYPTO_842) += 842.o | |||
97 | obj-$(CONFIG_CRYPTO_RNG2) += rng.o | 97 | obj-$(CONFIG_CRYPTO_RNG2) += rng.o |
98 | obj-$(CONFIG_CRYPTO_ANSI_CPRNG) += ansi_cprng.o | 98 | obj-$(CONFIG_CRYPTO_ANSI_CPRNG) += ansi_cprng.o |
99 | obj-$(CONFIG_CRYPTO_DRBG) += drbg.o | 99 | obj-$(CONFIG_CRYPTO_DRBG) += drbg.o |
100 | CFLAGS_jitterentropy.o = -O0 | ||
101 | obj-$(CONFIG_CRYPTO_JITTERENTROPY) += jitterentropy.o | 100 | obj-$(CONFIG_CRYPTO_JITTERENTROPY) += jitterentropy.o |
102 | obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o | 101 | obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o |
103 | obj-$(CONFIG_CRYPTO_GHASH) += ghash-generic.o | 102 | obj-$(CONFIG_CRYPTO_GHASH) += ghash-generic.o |
diff --git a/crypto/jitterentropy.c b/crypto/jitterentropy.c index a60147e4bb3f..d3c30452edee 100644 --- a/crypto/jitterentropy.c +++ b/crypto/jitterentropy.c | |||
@@ -57,10 +57,6 @@ | |||
57 | #include <linux/crypto.h> | 57 | #include <linux/crypto.h> |
58 | #include <crypto/internal/rng.h> | 58 | #include <crypto/internal/rng.h> |
59 | 59 | ||
60 | #ifdef __OPTIMIZE__ | ||
61 | #error "The CPU Jitter random number generator must not be compiled with optimizations. See documentation. Use the compiler switch -O0 for compiling jitterentropy.c." | ||
62 | #endif | ||
63 | |||
64 | /* The entropy pool */ | 60 | /* The entropy pool */ |
65 | struct rand_data { | 61 | struct rand_data { |
66 | /* all data values that are vital to maintain the security | 62 | /* all data values that are vital to maintain the security |
@@ -188,6 +184,20 @@ static __u64 jent_loop_shuffle(struct rand_data *ec, | |||
188 | * Noise sources | 184 | * Noise sources |
189 | ***************************************************************************/ | 185 | ***************************************************************************/ |
190 | 186 | ||
187 | /* | ||
188 | * The disabling of the optimizations is performed as documented and assessed | ||
189 | * thoroughly in http://www.chronox.de/jent.html. However, instead of disabling | ||
190 | * the optimization of the entire C file, only the main functions the jitter is | ||
191 | * measured for are not optimized. These functions include the noise sources as | ||
192 | * well as the main functions triggering the noise sources. As the time | ||
193 | * measurement is done from one invocation of the jitter noise source to the | ||
194 | * next, even the execution jitter of the code invoking the noise sources | ||
195 | * contribute to the overall randomness as well. The behavior of the RNG and the | ||
196 | * statistical characteristics when only the mentioned functions are not | ||
197 | * optimized is almost equal to the a completely non-optimized RNG compilation | ||
198 | * as tested with the test tools provided at the initially mentioned web site. | ||
199 | */ | ||
200 | |||
191 | /** | 201 | /** |
192 | * CPU Jitter noise source -- this is the noise source based on the CPU | 202 | * CPU Jitter noise source -- this is the noise source based on the CPU |
193 | * execution time jitter | 203 | * execution time jitter |
@@ -222,6 +232,8 @@ static __u64 jent_loop_shuffle(struct rand_data *ec, | |||
222 | * | 232 | * |
223 | * @return Number of loops the folding operation is performed | 233 | * @return Number of loops the folding operation is performed |
224 | */ | 234 | */ |
235 | #pragma GCC push_options | ||
236 | #pragma GCC optimize ("-O0") | ||
225 | static __u64 jent_fold_time(struct rand_data *ec, __u64 time, | 237 | static __u64 jent_fold_time(struct rand_data *ec, __u64 time, |
226 | __u64 *folded, __u64 loop_cnt) | 238 | __u64 *folded, __u64 loop_cnt) |
227 | { | 239 | { |
@@ -251,6 +263,7 @@ static __u64 jent_fold_time(struct rand_data *ec, __u64 time, | |||
251 | *folded = new; | 263 | *folded = new; |
252 | return fold_loop_cnt; | 264 | return fold_loop_cnt; |
253 | } | 265 | } |
266 | #pragma GCC pop_options | ||
254 | 267 | ||
255 | /** | 268 | /** |
256 | * Memory Access noise source -- this is a noise source based on variations in | 269 | * Memory Access noise source -- this is a noise source based on variations in |
@@ -279,6 +292,8 @@ static __u64 jent_fold_time(struct rand_data *ec, __u64 time, | |||
279 | * | 292 | * |
280 | * @return Number of memory access operations | 293 | * @return Number of memory access operations |
281 | */ | 294 | */ |
295 | #pragma GCC push_options | ||
296 | #pragma GCC optimize ("-O0") | ||
282 | static unsigned int jent_memaccess(struct rand_data *ec, __u64 loop_cnt) | 297 | static unsigned int jent_memaccess(struct rand_data *ec, __u64 loop_cnt) |
283 | { | 298 | { |
284 | unsigned char *tmpval = NULL; | 299 | unsigned char *tmpval = NULL; |
@@ -318,6 +333,7 @@ static unsigned int jent_memaccess(struct rand_data *ec, __u64 loop_cnt) | |||
318 | } | 333 | } |
319 | return i; | 334 | return i; |
320 | } | 335 | } |
336 | #pragma GCC pop_options | ||
321 | 337 | ||
322 | /*************************************************************************** | 338 | /*************************************************************************** |
323 | * Start of entropy processing logic | 339 | * Start of entropy processing logic |
@@ -366,6 +382,8 @@ static void jent_stuck(struct rand_data *ec, __u64 current_delta) | |||
366 | * | 382 | * |
367 | * @return One random bit | 383 | * @return One random bit |
368 | */ | 384 | */ |
385 | #pragma GCC push_options | ||
386 | #pragma GCC optimize ("-O0") | ||
369 | static __u64 jent_measure_jitter(struct rand_data *ec) | 387 | static __u64 jent_measure_jitter(struct rand_data *ec) |
370 | { | 388 | { |
371 | __u64 time = 0; | 389 | __u64 time = 0; |
@@ -395,6 +413,7 @@ static __u64 jent_measure_jitter(struct rand_data *ec) | |||
395 | 413 | ||
396 | return data; | 414 | return data; |
397 | } | 415 | } |
416 | #pragma GCC pop_options | ||
398 | 417 | ||
399 | /** | 418 | /** |
400 | * Von Neuman unbias as explained in RFC 4086 section 4.2. As shown in the | 419 | * Von Neuman unbias as explained in RFC 4086 section 4.2. As shown in the |
@@ -495,6 +514,8 @@ static void jent_stir_pool(struct rand_data *entropy_collector) | |||
495 | * Input: | 514 | * Input: |
496 | * @ec Reference to entropy collector | 515 | * @ec Reference to entropy collector |
497 | */ | 516 | */ |
517 | #pragma GCC push_options | ||
518 | #pragma GCC optimize ("-O0") | ||
498 | static void jent_gen_entropy(struct rand_data *ec) | 519 | static void jent_gen_entropy(struct rand_data *ec) |
499 | { | 520 | { |
500 | unsigned int k = 0; | 521 | unsigned int k = 0; |
@@ -556,6 +577,7 @@ static void jent_gen_entropy(struct rand_data *ec) | |||
556 | if (ec->stir) | 577 | if (ec->stir) |
557 | jent_stir_pool(ec); | 578 | jent_stir_pool(ec); |
558 | } | 579 | } |
580 | #pragma GCC pop_options | ||
559 | 581 | ||
560 | /** | 582 | /** |
561 | * The continuous test required by FIPS 140-2 -- the function automatically | 583 | * The continuous test required by FIPS 140-2 -- the function automatically |