aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-10-26 21:07:44 +0000
committerlloyd <[email protected]>2008-10-26 21:07:44 +0000
commit88b872f2afb9d71b91a155d05d517dbd593d30ca (patch)
tree6f0b8978fc73950b7e8822c03634d2b51cf23b2d /src
parenta5572385088e399eecf5531074aecabadf24d611 (diff)
In KDF instead of lookup, instantiate fixed hashes (MD5, SHA-1) directly
Diffstat (limited to 'src')
-rw-r--r--src/kdf/ssl_prf/info.txt2
-rw-r--r--src/kdf/ssl_prf/prf_ssl3.cpp29
-rw-r--r--src/kdf/x942_prf/info.txt4
-rw-r--r--src/kdf/x942_prf/prf_x942.cpp10
4 files changed, 24 insertions, 21 deletions
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
<requires>
kdf
+md5
+sha1
</requires>
<add>
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 <botan/prf_ssl3.h>
-#include <botan/lookup.h>
+#include <botan/sha160.h>
+#include <botan/md5.h>
#include <memory>
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<byte> sha1_hash = sha1->final();
+ sha1.update(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();
+ md5.update(secret, secret_len);
+ md5.update(sha1_hash);
+ SecureVector<byte> md5_hash = md5.final();
return OctetString(md5_hash, want);
}
@@ -49,17 +50,17 @@ SecureVector<byte> SSL3_PRF::derive(u32bit key_len,
if(key_len > 416)
throw Internal_Error("SSL3_PRF: Requested key length is too large");
- std::auto_ptr<HashFunction> md5(get_hash("MD5"));
- std::auto_ptr<HashFunction> 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;
diff --git a/src/kdf/x942_prf/info.txt b/src/kdf/x942_prf/info.txt
index 7c61317b0..df5719de4 100644
--- a/src/kdf/x942_prf/info.txt
+++ b/src/kdf/x942_prf/info.txt
@@ -5,8 +5,8 @@ define X942_PRF
load_on auto
<requires>
-core
-#kdf
+md5
+sha1
#oid_lookup
</requires>
diff --git a/src/kdf/x942_prf/prf_x942.cpp b/src/kdf/x942_prf/prf_x942.cpp
index 3a7298771..f0b578764 100644
--- a/src/kdf/x942_prf/prf_x942.cpp
+++ b/src/kdf/x942_prf/prf_x942.cpp
@@ -6,7 +6,7 @@
#include <botan/prf_x942.h>
#include <botan/der_enc.h>
#include <botan/oids.h>
-#include <botan/lookup.h>
+#include <botan/sha160.h>
#include <botan/loadstor.h>
#include <algorithm>
#include <memory>
@@ -34,7 +34,7 @@ SecureVector<byte> X942_PRF::derive(u32bit key_len,
const byte secret[], u32bit secret_len,
const byte salt[], u32bit salt_len) const
{
- std::auto_ptr<HashFunction> hash(get_hash("SHA-1"));
+ SHA_160 hash;
const OID kek_algo(key_wrap_oid);
SecureVector<byte> key;
@@ -42,9 +42,9 @@ SecureVector<byte> X942_PRF::derive(u32bit key_len,
while(key.size() != key_len && counter)
{
- hash->update(secret, secret_len);
+ hash.update(secret, secret_len);
- hash->update(
+ hash.update(
DER_Encoder().start_cons(SEQUENCE)
.start_cons(SEQUENCE)
@@ -66,7 +66,7 @@ SecureVector<byte> X942_PRF::derive(u32bit key_len,
.end_cons().get_contents()
);
- SecureVector<byte> digest = hash->final();
+ SecureVector<byte> digest = hash.final();
key.append(digest, std::min(digest.size(), key_len - key.size()));
++counter;