From 887cb723a6043ab39add9b1c66df644724c7b732 Mon Sep 17 00:00:00 2001 From: Richard Basch Date: Tue, 7 May 1996 20:19:59 +0000 Subject: [PATCH] Use the revamped random number routines git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@7913 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/des425/ChangeLog | 5 +++ src/lib/des425/new_rnd_key.c | 64 +++++++++++++++++++++--------------- src/lib/des425/random_key.c | 28 ++++++++++++---- 3 files changed, 63 insertions(+), 34 deletions(-) diff --git a/src/lib/des425/ChangeLog b/src/lib/des425/ChangeLog index 1e6f19b58..f4c4d07ec 100644 --- a/src/lib/des425/ChangeLog +++ b/src/lib/des425/ChangeLog @@ -1,3 +1,8 @@ +Thu May 2 18:44:02 1996 Richard Basch + + * 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 * Makefile.in: Remove ##DOS!include of config/windows.in. diff --git a/src/lib/des425/new_rnd_key.c b/src/lib/des425/new_rnd_key.c index 99c92db46..066b56895 100644 --- a/src/lib/des425/new_rnd_key.c +++ b/src/lib/des425/new_rnd_key.c @@ -26,11 +26,7 @@ #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); } - diff --git a/src/lib/des425/random_key.c b/src/lib/des425/random_key.c index 9994302a9..04399c1f0 100644 --- a/src/lib/des425/random_key.c +++ b/src/lib/des425/random_key.c @@ -26,22 +26,36 @@ #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); } -- 2.26.2