diff options
author | lloyd <[email protected]> | 2008-10-08 15:16:16 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-10-08 15:16:16 +0000 |
commit | 123f1dc39d54eaa144a746293921396e257903c6 (patch) | |
tree | fc0af1cd4cdd0d5fa6ff1fbd0e9cb0ff479362fc /src/kdf/tls_prf | |
parent | d40700c4b96c2f503991cbb36d72426d4b67a490 (diff) |
Append _prf to sslv3, tlsv1, x932 module names
Diffstat (limited to 'src/kdf/tls_prf')
-rw-r--r-- | src/kdf/tls_prf/info.txt | 10 | ||||
-rw-r--r-- | src/kdf/tls_prf/prf_tls.cpp | 79 | ||||
-rw-r--r-- | src/kdf/tls_prf/prf_tls.h | 37 |
3 files changed, 126 insertions, 0 deletions
diff --git a/src/kdf/tls_prf/info.txt b/src/kdf/tls_prf/info.txt new file mode 100644 index 000000000..9f05f8729 --- /dev/null +++ b/src/kdf/tls_prf/info.txt @@ -0,0 +1,10 @@ +realname "TLS v1.0 PRF" + +define TLS_V10_PRF + +load_on auto + +<add> +prf_tls.h +prf_tls.cpp +</add> diff --git a/src/kdf/tls_prf/prf_tls.cpp b/src/kdf/tls_prf/prf_tls.cpp new file mode 100644 index 000000000..8f7063f9f --- /dev/null +++ b/src/kdf/tls_prf/prf_tls.cpp @@ -0,0 +1,79 @@ +/************************************************* +* TLS PRF Source File * +* (C) 2004-2006 Jack Lloyd * +*************************************************/ + +#include <botan/prf_tls.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, + const byte secret[], u32bit secret_len, + const byte seed[], u32bit seed_len) const + { + u32bit S1_len = (secret_len + 1) / 2, + S2_len = (secret_len + 1) / 2; + const byte* S1 = secret; + const byte* S2 = secret + (secret_len - S2_len); + + SecureVector<byte> key1, key2; + 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()); + + return key1; + } + +/************************************************* +* TLS PRF P_hash function * +*************************************************/ +SecureVector<byte> TLS_PRF::P_hash(MessageAuthenticationCode* mac, + u32bit len, + const byte secret[], u32bit secret_len, + const byte seed[], u32bit seed_len) + { + SecureVector<byte> out; + + mac->set_key(secret, secret_len); + + SecureVector<byte> A(seed, seed_len); + while(len) + { + const u32bit this_block_len = std::min(mac->OUTPUT_LENGTH, len); + + A = mac->process(A); + + mac->update(A); + mac->update(seed, seed_len); + SecureVector<byte> block = mac->final(); + + out.append(block, this_block_len); + len -= this_block_len; + } + return out; + } + +} diff --git a/src/kdf/tls_prf/prf_tls.h b/src/kdf/tls_prf/prf_tls.h new file mode 100644 index 000000000..9bd221ca4 --- /dev/null +++ b/src/kdf/tls_prf/prf_tls.h @@ -0,0 +1,37 @@ +/************************************************* +* TLS v1.0 PRF Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_TLS_PRF__ +#define BOTAN_TLS_PRF__ + +#include <botan/kdf.h> +#include <botan/base.h> + +namespace Botan { + +/************************************************* +* TLS PRF * +*************************************************/ +class BOTAN_DLL TLS_PRF : public KDF + { + public: + SecureVector<byte> derive(u32bit, const byte[], u32bit, + const byte[], u32bit) const; + + TLS_PRF(); + ~TLS_PRF(); + private: + static SecureVector<byte> P_hash(MessageAuthenticationCode*, + u32bit, + const byte[], u32bit, + const byte[], u32bit); + + MessageAuthenticationCode* hmac_md5; + MessageAuthenticationCode* hmac_sha1; + }; + +} + +#endif |