[PATCH v3 1/7] SP800-90A Deterministic Random Bit Generator

Stephan Mueller smueller at chronox.de
Sat Jun 21 14:40:13 CEST 2014


Am Mittwoch, 19. März 2014, 08:35:42 schrieb Stephan Mueller:

Hi,

after the kernel version of the DRBG is now added to the cryptodev branch 
maintained by Herbert Xu with the potential to be included into 3.17, the 
kernel version of the code was subjected to a static code analysis.

One potential NULL pointer deference was identified which I ported to the 
libgcrypt DRBG implementation.

diff --git a/random/drbg.c b/random/drbg.c
index 2352d1d..703f117 100644
--- a/random/drbg.c
+++ b/random/drbg.c
@@ -689,14 +689,18 @@ drbg_ctr_df (struct drbg_state *drbg, unsigned char 
*df_da
   drbg_string_fill (&S2, L_N, sizeof (L_N));
   drbg_string_fill (&S4, pad, padlen);
   S1.next = &S2;
-  S2.next = addtl;
+
+  if (NULL == addtl) {
+    S2.next = &S4;
+  } else {
   /* splice in addtl between S2 and S4 -- we place S4 at the end of the
    * input data chain */
-  tempstr = addtl;
-  for (; NULL != tempstr; tempstr = tempstr->next)
-    if (NULL == tempstr->next)
-      break;
-  tempstr->next = &S4;
+    S2.next = addtl;
+    tempstr = addtl;
+    while (tempstr->next)
+      tempstr = tempstr->next;
+    tempstr->next = &S4;
+  }
 
   /* 10.4.2 step 9 */
   while (templen < (drbg_keylen (drbg) + (drbg_blocklen (drbg))))

The update will be included in a new patch set, if it is requested.

Ciao
Stephan
-- 
| Cui bono? |



More information about the Gcrypt-devel mailing list