aboutsummaryrefslogtreecommitdiffstats
path: root/src/kdf/prf_ssl3
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-06-03 14:19:16 +0000
committerlloyd <[email protected]>2011-06-03 14:19:16 +0000
commit4e760a188e8cc280277dfdd44253ca1ad6252b7f (patch)
tree70ce95fb10981900d28fcb0b58127e707dbd8c3e /src/kdf/prf_ssl3
parent7aaa90c33101a729e7ef3b888562f8dcbe68372d (diff)
Rename some dirs for shorter object files where configure will
coalesce the dir and file name if identical.
Diffstat (limited to 'src/kdf/prf_ssl3')
-rw-r--r--src/kdf/prf_ssl3/info.txt7
-rw-r--r--src/kdf/prf_ssl3/prf_ssl3.cpp76
-rw-r--r--src/kdf/prf_ssl3/prf_ssl3.h30
3 files changed, 113 insertions, 0 deletions
diff --git a/src/kdf/prf_ssl3/info.txt b/src/kdf/prf_ssl3/info.txt
new file mode 100644
index 000000000..0ef297119
--- /dev/null
+++ b/src/kdf/prf_ssl3/info.txt
@@ -0,0 +1,7 @@
+define SSL_V3_PRF
+
+<requires>
+md5
+sha1
+algo_base
+</requires>
diff --git a/src/kdf/prf_ssl3/prf_ssl3.cpp b/src/kdf/prf_ssl3/prf_ssl3.cpp
new file mode 100644
index 000000000..72cf023e2
--- /dev/null
+++ b/src/kdf/prf_ssl3/prf_ssl3.cpp
@@ -0,0 +1,76 @@
+/*
+* SSLv3 PRF
+* (C) 2004-2006 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/prf_ssl3.h>
+#include <botan/symkey.h>
+#include <botan/exceptn.h>
+#include <botan/sha160.h>
+#include <botan/md5.h>
+#include <botan/internal/assert.h>
+#include <memory>
+
+namespace Botan {
+
+namespace {
+
+/*
+* Return the next inner hash
+*/
+OctetString next_hash(size_t where, size_t want,
+ HashFunction& md5, HashFunction& sha1,
+ const byte secret[], size_t secret_len,
+ const byte seed[], size_t seed_len)
+ {
+ BOTAN_ASSERT(want <= md5.output_length(), "Desired output too large");
+
+ const byte ASCII_A_CHAR = 0x41;
+
+ for(size_t j = 0; j != where + 1; j++)
+ sha1.update(static_cast<byte>(ASCII_A_CHAR + where));
+ sha1.update(secret, secret_len);
+ sha1.update(seed, seed_len);
+ SecureVector<byte> sha1_hash = sha1.final();
+
+ md5.update(secret, secret_len);
+ md5.update(sha1_hash);
+ SecureVector<byte> md5_hash = md5.final();
+
+ return OctetString(&md5_hash[0], want);
+ }
+
+}
+
+/*
+* SSL3 PRF
+*/
+SecureVector<byte> SSL3_PRF::derive(size_t key_len,
+ const byte secret[], size_t secret_len,
+ const byte seed[], size_t seed_len) const
+ {
+ if(key_len > 416)
+ throw Invalid_Argument("SSL3_PRF: Requested key length is too large");
+
+ MD5 md5;
+ SHA_160 sha1;
+
+ OctetString output;
+
+ int counter = 0;
+ while(key_len)
+ {
+ const size_t produce = std::min<size_t>(key_len, md5.output_length());
+
+ output = output + next_hash(counter++, produce, md5, sha1,
+ secret, secret_len, seed, seed_len);
+
+ key_len -= produce;
+ }
+
+ return output.bits_of();
+ }
+
+}
diff --git a/src/kdf/prf_ssl3/prf_ssl3.h b/src/kdf/prf_ssl3/prf_ssl3.h
new file mode 100644
index 000000000..b07454be2
--- /dev/null
+++ b/src/kdf/prf_ssl3/prf_ssl3.h
@@ -0,0 +1,30 @@
+/*
+* SSLv3 PRF
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_SSLV3_PRF_H__
+#define BOTAN_SSLV3_PRF_H__
+
+#include <botan/kdf.h>
+
+namespace Botan {
+
+/**
+* PRF used in SSLv3
+*/
+class BOTAN_DLL SSL3_PRF : public KDF
+ {
+ public:
+ SecureVector<byte> derive(size_t, const byte[], size_t,
+ const byte[], size_t) const;
+
+ std::string name() const { return "SSL3-PRF"; }
+ KDF* clone() const { return new SSL3_PRF; }
+ };
+
+}
+
+#endif