From 88b872f2afb9d71b91a155d05d517dbd593d30ca Mon Sep 17 00:00:00 2001 From: lloyd Date: Sun, 26 Oct 2008 21:07:44 +0000 Subject: In KDF instead of lookup, instantiate fixed hashes (MD5, SHA-1) directly --- src/kdf/ssl_prf/info.txt | 2 ++ src/kdf/ssl_prf/prf_ssl3.cpp | 29 +++++++++++++++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'src/kdf/ssl_prf') diff --git a/src/kdf/ssl_prf/info.txt b/src/kdf/ssl_prf/info.txt index 8c85745c2..890789988 100644 --- a/src/kdf/ssl_prf/info.txt +++ b/src/kdf/ssl_prf/info.txt @@ -6,6 +6,8 @@ load_on auto kdf +md5 +sha1 diff --git a/src/kdf/ssl_prf/prf_ssl3.cpp b/src/kdf/ssl_prf/prf_ssl3.cpp index b241bf60f..29c29ba7e 100644 --- a/src/kdf/ssl_prf/prf_ssl3.cpp +++ b/src/kdf/ssl_prf/prf_ssl3.cpp @@ -4,7 +4,8 @@ *************************************************/ #include -#include +#include +#include #include namespace Botan { @@ -15,24 +16,24 @@ namespace { * Return the next inner hash * *************************************************/ OctetString next_hash(u32bit where, u32bit want, - HashFunction* md5, HashFunction* sha1, + HashFunction& md5, HashFunction& sha1, const byte secret[], u32bit secret_len, const byte seed[], u32bit seed_len) { - if(want > md5->OUTPUT_LENGTH) + if(want > md5.OUTPUT_LENGTH) throw Internal_Error("SSL3_PRF:next_hash: want is too big"); const byte ASCII_A_CHAR = 0x41; for(u32bit j = 0; j != where + 1; j++) - sha1->update(ASCII_A_CHAR + where); - sha1->update(secret, secret_len); - sha1->update(seed, seed_len); - SecureVector sha1_hash = sha1->final(); + sha1.update(ASCII_A_CHAR + where); + sha1.update(secret, secret_len); + sha1.update(seed, seed_len); + SecureVector sha1_hash = sha1.final(); - md5->update(secret, secret_len); - md5->update(sha1_hash); - SecureVector md5_hash = md5->final(); + md5.update(secret, secret_len); + md5.update(sha1_hash); + SecureVector md5_hash = md5.final(); return OctetString(md5_hash, want); } @@ -49,17 +50,17 @@ SecureVector SSL3_PRF::derive(u32bit key_len, if(key_len > 416) throw Internal_Error("SSL3_PRF: Requested key length is too large"); - std::auto_ptr md5(get_hash("MD5")); - std::auto_ptr sha1(get_hash("SHA-1")); + MD5 md5; + SHA_160 sha1; OctetString output; int counter = 0; while(key_len) { - const u32bit produce = std::min(key_len, md5->OUTPUT_LENGTH); + const u32bit produce = std::min(key_len, md5.OUTPUT_LENGTH); - output = output + next_hash(counter++, produce, md5.get(), sha1.get(), + output = output + next_hash(counter++, produce, md5, sha1, secret, secret_len, seed, seed_len); key_len -= produce; -- cgit v1.2.3