diff options
author | lloyd <[email protected]> | 2008-09-30 06:20:10 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-30 06:20:10 +0000 |
commit | 33bb3dca54ecef2599b756d27b66781e14d06ae3 (patch) | |
tree | 4c7b07a1b1b3f40e82202570c7aec298a672339c /src/kdf/tlsv1/prf_tls.cpp | |
parent | c9749d5d4693b5d93171f6085b29fc72c1e12ba0 (diff) |
Remove lookup from Randpool, HMAC, CMAC, CBC-MAC, TLS-PRF, and PBKDF2
Diffstat (limited to 'src/kdf/tlsv1/prf_tls.cpp')
-rw-r--r-- | src/kdf/tlsv1/prf_tls.cpp | 40 |
1 files changed, 28 insertions, 12 deletions
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,13 +4,29 @@ *************************************************/ #include <botan/prf_tls.h> -#include <botan/lookup.h> #include <botan/xor_buf.h> #include <botan/hmac.h> +#include <botan/md5.h> +#include <botan/sha160.h> 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 * *************************************************/ SecureVector<byte> TLS_PRF::derive(u32bit key_len, @@ -23,8 +39,8 @@ SecureVector<byte> TLS_PRF::derive(u32bit key_len, const byte* S2 = secret + (secret_len - S2_len); SecureVector<byte> 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<byte> TLS_PRF::derive(u32bit key_len, /************************************************* * TLS PRF P_hash function * *************************************************/ -SecureVector<byte> TLS_PRF::P_hash(const std::string& hash, u32bit len, +SecureVector<byte> 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<byte> out; - HMAC hmac(hash); - hmac.set_key(secret, secret_len); + mac->set_key(secret, secret_len); SecureVector<byte> 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<byte> block = hmac.final(); + mac->update(A); + mac->update(seed, seed_len); + SecureVector<byte> block = mac->final(); out.append(block, this_block_len); len -= this_block_len; |