From 33bb3dca54ecef2599b756d27b66781e14d06ae3 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 30 Sep 2008 06:20:10 +0000 Subject: Remove lookup from Randpool, HMAC, CMAC, CBC-MAC, TLS-PRF, and PBKDF2 --- src/kdf/tlsv1/prf_tls.cpp | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'src/kdf/tlsv1/prf_tls.cpp') diff --git a/src/kdf/tlsv1/prf_tls.cpp b/src/kdf/tlsv1/prf_tls.cpp index e035ac85e..8f7063f9f 100644 --- a/src/kdf/tlsv1/prf_tls.cpp +++ b/src/kdf/tlsv1/prf_tls.cpp @@ -4,12 +4,28 @@ *************************************************/ #include -#include #include #include +#include +#include namespace Botan { +/************************************************* +* TLS PRF Constructor and Destructor * +*************************************************/ +TLS_PRF::TLS_PRF() + { + hmac_md5 = new HMAC(new MD5); + hmac_sha1 = new HMAC(new SHA_160); + } + +TLS_PRF::~TLS_PRF() + { + delete hmac_md5; + delete hmac_sha1; + } + /************************************************* * TLS PRF * *************************************************/ @@ -23,8 +39,8 @@ SecureVector TLS_PRF::derive(u32bit key_len, const byte* S2 = secret + (secret_len - S2_len); SecureVector key1, key2; - key1 = P_hash("MD5", key_len, S1, S1_len, seed, seed_len); - key2 = P_hash("SHA-1", key_len, S2, S2_len, seed, seed_len); + key1 = P_hash(hmac_md5, key_len, S1, S1_len, seed, seed_len); + key2 = P_hash(hmac_sha1, key_len, S2, S2_len, seed, seed_len); xor_buf(key1.begin(), key2.begin(), key2.size()); @@ -34,25 +50,25 @@ SecureVector TLS_PRF::derive(u32bit key_len, /************************************************* * TLS PRF P_hash function * *************************************************/ -SecureVector TLS_PRF::P_hash(const std::string& hash, u32bit len, +SecureVector TLS_PRF::P_hash(MessageAuthenticationCode* mac, + u32bit len, const byte secret[], u32bit secret_len, - const byte seed[], u32bit seed_len) const + const byte seed[], u32bit seed_len) { SecureVector out; - HMAC hmac(hash); - hmac.set_key(secret, secret_len); + mac->set_key(secret, secret_len); SecureVector A(seed, seed_len); while(len) { - const u32bit this_block_len = std::min(hmac.OUTPUT_LENGTH, len); + const u32bit this_block_len = std::min(mac->OUTPUT_LENGTH, len); - A = hmac.process(A); + A = mac->process(A); - hmac.update(A); - hmac.update(seed, seed_len); - SecureVector block = hmac.final(); + mac->update(A); + mac->update(seed, seed_len); + SecureVector block = mac->final(); out.append(block, this_block_len); len -= this_block_len; -- cgit v1.2.3