Use the revamped random number routines
authorRichard Basch <probe@mit.edu>
Tue, 7 May 1996 20:19:59 +0000 (20:19 +0000)
committerRichard Basch <probe@mit.edu>
Tue, 7 May 1996 20:19:59 +0000 (20:19 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@7913 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/des425/ChangeLog
src/lib/des425/new_rnd_key.c
src/lib/des425/random_key.c

index 1e6f19b584c7d034e930ab11b4233ac9aefb8839..f4c4d07ec50d0075222b40617947b48fef9cf757 100644 (file)
@@ -1,3 +1,8 @@
+Thu May  2 18:44:02 1996  Richard Basch  <basch@lehman.com>
+
+       * random_key.c new_rnd_key.c:
+       Use the rewritten random number routines of libcrypto
+
 Fri Oct  6 22:01:18 1995  Theodore Y. Ts'o  <tytso@dcl>
 
        * Makefile.in: Remove ##DOS!include of config/windows.in.
index 99c92db46d1aeba4fcf4af8729154f60d8cbf2f4..066b56895537b88fc8ab6bdbd316f783af1dda27 100644 (file)
 
 #include "des.h"
 
-/*
- * The secret des key schedule and sequence number for the current
- * stream of random numbers
- */
-static mit_des_random_key_seed random_sequence_state;
+krb5_pointer des425_random_state = 0;
 
 /*
  * des_new_random_key: create a random des key
@@ -46,7 +42,15 @@ int
 des_new_random_key(key)
     mit_des_cblock key;
 {
-    return(mit_des_new_random_key(key, &random_sequence_state));
+    krb5_keyblock * keyblock;
+    krb5_error_code kret;
+
+    kret = mit_des_random_key(NULL, des425_random_state, &keyblock);
+    if (kret) return kret;
+    
+    memcpy(key, keyblock->contents, sizeof(key));
+    krb5_free_keyblock(NULL, keyblock);
+    return 0;
 }
 
 /*
@@ -65,9 +69,20 @@ des_new_random_key(key)
  */
 void
 des_init_random_number_generator(key)
-     mit_des_cblock key;
+    mit_des_cblock key;
 {
-     mit_des_init_random_number_generator(key, &random_sequence_state);
+    krb5_keyblock keyblock;
+    krb5_encrypt_block eblock;
+
+    krb5_use_enctype(NULL, &eblock, ENCTYPE_DES_CBC_CRC);
+
+    keyblock.enctype = ENCTYPE_DES_CBC_CRC;
+    keyblock.length = sizeof(mit_des_cblock);
+    keyblock.contents = (krb5_octet *)key;
+
+    if (des425_random_state)
+       mit_des_finish_random_key(&eblock, &des425_random_state);
+    mit_des_init_random_key(&eblock, &keyblock, &des425_random_state);
 }
 
 /*
@@ -89,9 +104,16 @@ des_init_random_number_generator(key)
  */
 void
 des_set_random_generator_seed(key)
-     mit_des_cblock key;
+    mit_des_cblock key;
 {
-     mit_des_set_random_generator_seed(key, &random_sequence_state);
+    krb5_data seed;
+
+    seed.length = sizeof(mit_des_cblock);
+    seed.data = (krb5_pointer) key;
+
+    if (!des425_random_state)
+       des_init_random_number_generator(key);
+    mit_des_set_random_generator_seed(&seed, des425_random_state);
 }
 
 
@@ -105,23 +127,11 @@ des_set_random_generator_seed(key)
  */
 void
 des_set_sequence_number(new_sequence_number)
-     mit_des_cblock new_sequence_number;
+    mit_des_cblock new_sequence_number;
 {
-     mit_des_set_sequence_number(new_sequence_number, &random_sequence_state);
-}
+    krb5_data sequence;
 
-/*
- * des_generate_random_block: routine to return the next random number
- *                            from the current random number stream.
- *                            The returned number is 64 bits long.
- *
- * Requires: des_set_random_generator_seed must have been called at least once
- *           before this routine is called.
- */
-void
-des_generate_random_block(block)
-     mit_des_cblock block;
-{
-    mit_des_generate_random_block(block, &random_sequence_state);
+    sequence.length = sizeof(new_sequence_number);
+    sequence.data = (krb5_octet *)new_sequence_number;
+    mit_des_set_random_sequence_number(&sequence, des425_random_state);
 }
-
index 9994302a9e317531e8cfb45cbc14964f37bb9d7a..04399c1f0526682e83fdb50ef253c1c1010ff61b 100644 (file)
 
 #include "des.h"
 
+extern krb5_pointer des425_random_state;
+
 /* random_key */
 int
 des_random_key(key)
     mit_des_cblock *key;
 {
-    mit_des_random_key_seed    p_seed;
-    mit_des_cblock             nullkey;
+    krb5_encrypt_block eblock;
+    krb5_keyblock      keyblock;
+    krb5_keyblock      *new_key;
+    krb5_error_code    kret;
+    mit_des_cblock     nullkey;
+
+    krb5_use_enctype(NULL, &eblock, ENCTYPE_DES_CBC_CRC);
 
     memset(nullkey, 0, sizeof(mit_des_cblock));
     mit_des_fixup_key_parity(*key);
-    mit_des_init_random_number_generator(nullkey,&p_seed);
-    do {
-       mit_des_generate_random_block(*key, &p_seed);
-       mit_des_fixup_key_parity(*key);
-    } while (mit_des_is_weak_key(*key));
 
+    keyblock.enctype = ENCTYPE_DES_CBC_CRC;
+    keyblock.length = sizeof(mit_des_cblock);
+    keyblock.contents = (krb5_octet *)nullkey;
+
+    if (! des425_random_state)
+       mit_des_init_random_key(&eblock, &keyblock, &des425_random_state);
+
+    kret = mit_des_random_key(NULL, des425_random_state, &new_key);
+    if (kret) return kret;
+
+    memcpy(key, new_key->contents, sizeof(mit_des_cblock));
+    krb5_free_keyblock(NULL, new_key);
     return(0);
 }