]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
gnutls_key_generate() is restricted by the size of the initial RNG seed in FIPS140...
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Fri, 22 Nov 2013 11:27:57 +0000 (12:27 +0100)
committerNikos Mavrogiannopoulos <nmav@redhat.com>
Wed, 27 Nov 2013 10:41:44 +0000 (11:41 +0100)
lib/crypto-api.c
lib/fips.h
lib/nettle/rnd-fips.c

index 354dd14b6c60c667f679f864fc2e478847d8bd4a..0f421fae22c11c7754090c9c266b473d0a4075b8 100644 (file)
@@ -28,6 +28,7 @@
 #include <algorithms.h>
 #include <random.h>
 #include <crypto.h>
+#include <fips.h>
 
 typedef struct api_cipher_hd_st {
        cipher_hd_st ctx_enc;
@@ -576,6 +577,14 @@ int gnutls_key_generate(gnutls_datum_t * key, unsigned int key_size)
 {
        int ret;
 
+#ifdef ENABLE_FIPS140
+       /* The FIPS140 approved RNGs are not allowed to be used
+        * to extract key sizes longer than their original seed.
+        */
+       if (key_size > FIPS140_RND_KEY_SIZE)
+               return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+#endif
+
        key->size = key_size;
        key->data = gnutls_malloc(key->size);
        if (!key->data) {
index c94cb078634b657aeb05317c64dcfec27b843a58..867431c5e7930bf0f13fbaa1b86eeb394d1229b3 100644 (file)
@@ -29,6 +29,8 @@
 /* This must be removed when finished */
 #define FIPS140_TEST
 
+#define FIPS140_RND_KEY_SIZE 32
+
 typedef enum {
   FIPS_STATE_POWERON,
   FIPS_STATE_INIT,
index 20d86b15402c9f40f03bf9be88df6c2fc188efcc..8b2097048dd83c7d6d6da9bccaa11d493502a8f7 100644 (file)
@@ -81,9 +81,6 @@ static void *rnd_mutex;
 #define SEED_TTL 1000
 
 
-/* The length of the key we use:  16 bytes (128 bit) for AES128.  */
-#define X931_AES_KEYLEN  16
-
 /* This random context type is used to track properties of one random
    generator. Thee context are usually allocated in secure memory so
    that the seed value is well protected.  There are a couble of guard
@@ -312,7 +309,7 @@ x931_aes_driver(struct rng_context* rng_ctx, unsigned char *output, size_t lengt
    the standard generator.  On error NULL is returned.  */
 static int x931_generate_key(struct aes_ctx* ctx)
 {
-       uint8_t buffer[X931_AES_KEYLEN];
+       uint8_t buffer[FIPS140_RND_KEY_SIZE];
        int ret;
 
        /* Get a key from the standard RNG or from the entropy source.  */