aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/drbg.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/drbg.c')
-rw-r--r--crypto/drbg.c34
1 files changed, 13 insertions, 21 deletions
diff --git a/crypto/drbg.c b/crypto/drbg.c
index d748a1d0ca24..d8ff16e5c322 100644
--- a/crypto/drbg.c
+++ b/crypto/drbg.c
@@ -98,7 +98,6 @@
98 */ 98 */
99 99
100#include <crypto/drbg.h> 100#include <crypto/drbg.h>
101#include <linux/string.h>
102 101
103/*************************************************************** 102/***************************************************************
104 * Backend cipher definitions available to DRBG 103 * Backend cipher definitions available to DRBG
@@ -223,15 +222,6 @@ static inline unsigned short drbg_sec_strength(drbg_flag_t flags)
223 * function. Thus, the function implicitly knows the size of the 222 * function. Thus, the function implicitly knows the size of the
224 * buffer. 223 * buffer.
225 * 224 *
226 * The FIPS test can be called in an endless loop until it returns
227 * true. Although the code looks like a potential for a deadlock, it
228 * is not the case, because returning a false cannot mathematically
229 * occur (except once when a reseed took place and the updated state
230 * would is now set up such that the generation of new value returns
231 * an identical one -- this is most unlikely and would happen only once).
232 * Thus, if this function repeatedly returns false and thus would cause
233 * a deadlock, the integrity of the entire kernel is lost.
234 *
235 * @drbg DRBG handle 225 * @drbg DRBG handle
236 * @buf output buffer of random data to be checked 226 * @buf output buffer of random data to be checked
237 * 227 *
@@ -258,6 +248,8 @@ static bool drbg_fips_continuous_test(struct drbg_state *drbg,
258 return false; 248 return false;
259 } 249 }
260 ret = memcmp(drbg->prev, buf, drbg_blocklen(drbg)); 250 ret = memcmp(drbg->prev, buf, drbg_blocklen(drbg));
251 if (!ret)
252 panic("DRBG continuous self test failed\n");
261 memcpy(drbg->prev, buf, drbg_blocklen(drbg)); 253 memcpy(drbg->prev, buf, drbg_blocklen(drbg));
262 /* the test shall pass when the two compared values are not equal */ 254 /* the test shall pass when the two compared values are not equal */
263 return ret != 0; 255 return ret != 0;
@@ -498,9 +490,9 @@ static int drbg_ctr_df(struct drbg_state *drbg,
498 ret = 0; 490 ret = 0;
499 491
500out: 492out:
501 memzero_explicit(iv, drbg_blocklen(drbg)); 493 memset(iv, 0, drbg_blocklen(drbg));
502 memzero_explicit(temp, drbg_statelen(drbg)); 494 memset(temp, 0, drbg_statelen(drbg));
503 memzero_explicit(pad, drbg_blocklen(drbg)); 495 memset(pad, 0, drbg_blocklen(drbg));
504 return ret; 496 return ret;
505} 497}
506 498
@@ -574,9 +566,9 @@ static int drbg_ctr_update(struct drbg_state *drbg, struct list_head *seed,
574 ret = 0; 566 ret = 0;
575 567
576out: 568out:
577 memzero_explicit(temp, drbg_statelen(drbg) + drbg_blocklen(drbg)); 569 memset(temp, 0, drbg_statelen(drbg) + drbg_blocklen(drbg));
578 if (2 != reseed) 570 if (2 != reseed)
579 memzero_explicit(df_data, drbg_statelen(drbg)); 571 memset(df_data, 0, drbg_statelen(drbg));
580 return ret; 572 return ret;
581} 573}
582 574
@@ -634,7 +626,7 @@ static int drbg_ctr_generate(struct drbg_state *drbg,
634 len = ret; 626 len = ret;
635 627
636out: 628out:
637 memzero_explicit(drbg->scratchpad, drbg_blocklen(drbg)); 629 memset(drbg->scratchpad, 0, drbg_blocklen(drbg));
638 return len; 630 return len;
639} 631}
640 632
@@ -872,7 +864,7 @@ static int drbg_hash_df(struct drbg_state *drbg,
872 } 864 }
873 865
874out: 866out:
875 memzero_explicit(tmp, drbg_blocklen(drbg)); 867 memset(tmp, 0, drbg_blocklen(drbg));
876 return ret; 868 return ret;
877} 869}
878 870
@@ -916,7 +908,7 @@ static int drbg_hash_update(struct drbg_state *drbg, struct list_head *seed,
916 ret = drbg_hash_df(drbg, drbg->C, drbg_statelen(drbg), &datalist2); 908 ret = drbg_hash_df(drbg, drbg->C, drbg_statelen(drbg), &datalist2);
917 909
918out: 910out:
919 memzero_explicit(drbg->scratchpad, drbg_statelen(drbg)); 911 memset(drbg->scratchpad, 0, drbg_statelen(drbg));
920 return ret; 912 return ret;
921} 913}
922 914
@@ -951,7 +943,7 @@ static int drbg_hash_process_addtl(struct drbg_state *drbg,
951 drbg->scratchpad, drbg_blocklen(drbg)); 943 drbg->scratchpad, drbg_blocklen(drbg));
952 944
953out: 945out:
954 memzero_explicit(drbg->scratchpad, drbg_blocklen(drbg)); 946 memset(drbg->scratchpad, 0, drbg_blocklen(drbg));
955 return ret; 947 return ret;
956} 948}
957 949
@@ -998,7 +990,7 @@ static int drbg_hash_hashgen(struct drbg_state *drbg,
998 } 990 }
999 991
1000out: 992out:
1001 memzero_explicit(drbg->scratchpad, 993 memset(drbg->scratchpad, 0,
1002 (drbg_statelen(drbg) + drbg_blocklen(drbg))); 994 (drbg_statelen(drbg) + drbg_blocklen(drbg)));
1003 return len; 995 return len;
1004} 996}
@@ -1047,7 +1039,7 @@ static int drbg_hash_generate(struct drbg_state *drbg,
1047 drbg_add_buf(drbg->V, drbg_statelen(drbg), u.req, 8); 1039 drbg_add_buf(drbg->V, drbg_statelen(drbg), u.req, 8);
1048 1040
1049out: 1041out:
1050 memzero_explicit(drbg->scratchpad, drbg_blocklen(drbg)); 1042 memset(drbg->scratchpad, 0, drbg_blocklen(drbg));
1051 return len; 1043 return len;
1052} 1044}
1053 1045