]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Updates in the DRBG-CTR-AES random number generator.
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Wed, 22 Jan 2014 10:38:07 +0000 (11:38 +0100)
committerNikos Mavrogiannopoulos <nmav@redhat.com>
Wed, 22 Jan 2014 10:38:07 +0000 (11:38 +0100)
lib/libgnutls.map
lib/nettle/int/drbg-aes.c
lib/nettle/int/drbg-aes.h

index 908587e3815194127925407e06abbfe1a4ef8b66..da0118bb5868ed166c5e1fe4d2fb57e42b666113 100644 (file)
@@ -989,6 +989,10 @@ GNUTLS_PRIVATE {
     # Internal symbols needed by tests/pkcs12_s2k:
     _gnutls_pkcs12_string_to_key;
     _gnutls_bin2hex;
+    #for FIPS140-2 validation
+    drbg_aes_reseed;
+    drbg_aes_init;
+    drbg_aes_generate;
   local:
     *;
 };
index fa2b6a1f279fb65bdae08b99e27ece6d646655df..a8ed9d629c97511d3576c95ba123c0ba80df4f09 100644 (file)
@@ -1,6 +1,6 @@
 /* drbg-aes.c */
 
-/* Copyright (C) 2013 Red Hat
+/* Copyright (C) 2013, 2014 Red Hat
  *
  * This file is part of GnuTLS.
  *  
@@ -47,7 +47,7 @@ drbg_aes_init(struct drbg_aes_ctx *ctx,
 /* Sets V and key based on pdata */
 static void
 drbg_aes_update(struct drbg_aes_ctx *ctx,
-               unsigned pdata_size, const uint8_t * pdata)
+               const uint8_t pdata[DRBG_AES_SEED_SIZE])
 {
        unsigned len = 0;
        uint8_t tmp[DRBG_AES_SEED_SIZE];
@@ -64,9 +64,7 @@ drbg_aes_update(struct drbg_aes_ctx *ctx,
 
        aes_set_encrypt_key(&ctx->key, DRBG_AES_KEY_SIZE, tmp);
 
-       ctx->prev_block_present = 0;
-
-       memcpy(ctx->v, &tmp[AES_BLOCK_SIZE], AES_BLOCK_SIZE);
+       memcpy(ctx->v, &tmp[DRBG_AES_KEY_SIZE], AES_BLOCK_SIZE);
 
        ctx->reseed_counter = 1;
        ctx->seeded = 1;
@@ -93,21 +91,36 @@ drbg_aes_reseed(struct drbg_aes_ctx *ctx,
 
        memxor(tmp, entropy, entropy_size);
 
-       drbg_aes_update(ctx, DRBG_AES_SEED_SIZE, tmp);
+       drbg_aes_update(ctx, tmp);
 
        return 1;
 }
 
 /* we don't use additional input */
-int drbg_aes_random(struct drbg_aes_ctx *ctx, unsigned length, uint8_t * dst)
+int drbg_aes_generate(struct drbg_aes_ctx *ctx, unsigned length, uint8_t * dst,
+                       unsigned add_size, const uint8_t *add)
 {
        uint8_t tmp[AES_BLOCK_SIZE];
+       uint8_t seed[DRBG_AES_SEED_SIZE];
        unsigned left;
 
        if (ctx->seeded == 0)
                return 0;
 
-       /* Throw the first block generated. FIPS 140-2 requirement 
+       if (add_size > 0) {
+               if (add_size > DRBG_AES_SEED_SIZE)
+                       return 0;
+               memcpy(seed, add, add_size);
+               if (add_size != DRBG_AES_SEED_SIZE)
+                       memset(&seed[add_size], 0, DRBG_AES_SEED_SIZE - add_size);
+
+               drbg_aes_update(ctx, seed);
+       } else {
+               memset(seed, 0, DRBG_AES_SEED_SIZE);
+       }
+
+       /* Throw the first block generated. FIPS 140-2 requirement (see 
+        * the continuous random number generator test in 4.9.2)
         */
        if (ctx->prev_block_present == 0) {
                INCREMENT(sizeof(ctx->v), ctx->v);
@@ -147,6 +160,8 @@ int drbg_aes_random(struct drbg_aes_ctx *ctx, unsigned length, uint8_t * dst)
                return 0;
        ctx->reseed_counter++;
 
+       drbg_aes_update(ctx, seed);
+
        return 1;
 }
 
index 1c6ff5974c4046f0c82d9f1653f7651287bcc8c3..0775d0a163f6f7569729d4a89159ee41beb11420 100644 (file)
@@ -74,9 +74,11 @@ drbg_aes_reseed(struct drbg_aes_ctx *ctx,
        unsigned entropy_size, const uint8_t *entropy, 
        unsigned add_size, const uint8_t* add);
 
+#define drbg_aes_random(ctx, l, dst) drbg_aes_generate(ctx, l, dst, 0, NULL)
+
 int
-drbg_aes_random(struct drbg_aes_ctx *ctx, unsigned length,
-               uint8_t * dst);
+drbg_aes_generate(struct drbg_aes_ctx *ctx, unsigned length,
+               uint8_t * dst, unsigned add_size, const uint8_t* add);
 
 int drbg_aes_is_seeded(struct drbg_aes_ctx *ctx);