aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-11-11 00:00:10 +0000
committerlloyd <[email protected]>2008-11-11 00:00:10 +0000
commit894a225d14043cbd0cbd42c677ab4063b461fa24 (patch)
treed86973c4bc9bcddf4ac1970728479bf04e8f6522 /src
parente6abb0fd8289619d559ff430dff84f0de4f82808 (diff)
Remove lookup.h use from DLIES, PK key agreement, DSA param gen, get_enc.cpp
Diffstat (limited to 'src')
-rw-r--r--src/cert/x509/x509_ca.cpp1
-rw-r--r--src/cert/x509/x509_ext.cpp6
-rw-r--r--src/filters/algo_filt.cpp13
-rw-r--r--src/libstate/engine/def_engine/def_mode.cpp1
-rw-r--r--src/libstate/get_enc.cpp3
-rw-r--r--src/math/numbertheory/dsa_gen.cpp8
-rw-r--r--src/pubkey/dlies/dlies.cpp57
-rw-r--r--src/pubkey/dlies/dlies.h34
-rw-r--r--src/pubkey/pk_lookup/look_pk.cpp2
-rw-r--r--src/pubkey/pubkey/pubkey.cpp13
-rw-r--r--src/pubkey/pubkey/pubkey.h9
11 files changed, 87 insertions, 60 deletions
diff --git a/src/cert/x509/x509_ca.cpp b/src/cert/x509/x509_ca.cpp
index 82f854649..2f158e27f 100644
--- a/src/cert/x509/x509_ca.cpp
+++ b/src/cert/x509/x509_ca.cpp
@@ -7,7 +7,6 @@
#include <botan/x509stor.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
-#include <botan/lookup.h>
#include <botan/look_pk.h>
#include <botan/bigint.h>
#include <botan/parsing.h>
diff --git a/src/cert/x509/x509_ext.cpp b/src/cert/x509/x509_ext.cpp
index 3595a0492..54e8be8bd 100644
--- a/src/cert/x509/x509_ext.cpp
+++ b/src/cert/x509/x509_ext.cpp
@@ -4,9 +4,9 @@
*************************************************/
#include <botan/x509_ext.h>
+#include <botan/sha160.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
-#include <botan/lookup.h>
#include <botan/oids.h>
#include <botan/libstate.h>
#include <botan/bit_ops.h>
@@ -303,8 +303,8 @@ void Subject_Key_ID::contents_to(Data_Store& subject, Data_Store&) const
*************************************************/
Subject_Key_ID::Subject_Key_ID(const MemoryRegion<byte>& pub_key)
{
- std::auto_ptr<HashFunction> hash(get_hash("SHA-1"));
- key_id = hash->process(pub_key);
+ SHA_160 hash;
+ key_id = hash.process(pub_key);
}
/*************************************************
diff --git a/src/filters/algo_filt.cpp b/src/filters/algo_filt.cpp
index 3a1f1d5da..17b0b8440 100644
--- a/src/filters/algo_filt.cpp
+++ b/src/filters/algo_filt.cpp
@@ -4,7 +4,6 @@
*************************************************/
#include <botan/filters.h>
-#include <botan/lookup.h>
#include <botan/libstate.h>
#include <algorithm>
@@ -16,7 +15,8 @@ namespace Botan {
StreamCipher_Filter::StreamCipher_Filter(const std::string& sc_name) :
buffer(DEFAULT_BUFFERSIZE)
{
- base_ptr = cipher = get_stream_cipher(sc_name);
+ Algorithm_Factory& af = global_state().algo_factory();
+ base_ptr = cipher = af.make_stream_cipher(sc_name);
}
/*************************************************
@@ -35,7 +35,8 @@ StreamCipher_Filter::StreamCipher_Filter(const std::string& sc_name,
const SymmetricKey& key) :
buffer(DEFAULT_BUFFERSIZE)
{
- base_ptr = cipher = get_stream_cipher(sc_name);
+ Algorithm_Factory& af = global_state().algo_factory();
+ base_ptr = cipher = af.make_stream_cipher(sc_name);
cipher->set_key(key);
}
@@ -90,7 +91,8 @@ void Hash_Filter::end_msg()
MAC_Filter::MAC_Filter(const std::string& mac_name, u32bit len) :
OUTPUT_LENGTH(len)
{
- base_ptr = mac = get_mac(mac_name);
+ Algorithm_Factory& af = global_state().algo_factory();
+ base_ptr = mac = af.make_mac(mac_name);
}
/*************************************************
@@ -99,7 +101,8 @@ MAC_Filter::MAC_Filter(const std::string& mac_name, u32bit len) :
MAC_Filter::MAC_Filter(const std::string& mac_name, const SymmetricKey& key,
u32bit len) : OUTPUT_LENGTH(len)
{
- base_ptr = mac = get_mac(mac_name);
+ Algorithm_Factory& af = global_state().algo_factory();
+ base_ptr = mac = af.make_mac(mac_name);
mac->set_key(key);
}
diff --git a/src/libstate/engine/def_engine/def_mode.cpp b/src/libstate/engine/def_engine/def_mode.cpp
index 52470080b..7933fbb84 100644
--- a/src/libstate/engine/def_engine/def_mode.cpp
+++ b/src/libstate/engine/def_engine/def_mode.cpp
@@ -7,7 +7,6 @@
#include <botan/parsing.h>
#include <botan/filters.h>
#include <botan/libstate.h>
-#include <botan/lookup.h>
#include <botan/mode_pad.h>
#include <memory>
diff --git a/src/libstate/get_enc.cpp b/src/libstate/get_enc.cpp
index ea02dd092..143cec21c 100644
--- a/src/libstate/get_enc.cpp
+++ b/src/libstate/get_enc.cpp
@@ -190,6 +190,9 @@ KDF* get_kdf(const std::string& algo_spec)
{
SCAN_Name request(algo_spec);
+ if(request.algo_name() == "Raw")
+ return 0; // No KDF
+
#if defined(BOTAN_HAS_KDF1)
if(request.algo_name() == "KDF1" && request.arg_count() == 1)
return new KDF1(get_hash(request.arg(0)));
diff --git a/src/math/numbertheory/dsa_gen.cpp b/src/math/numbertheory/dsa_gen.cpp
index 14f62dab3..6f4a7cefa 100644
--- a/src/math/numbertheory/dsa_gen.cpp
+++ b/src/math/numbertheory/dsa_gen.cpp
@@ -4,7 +4,8 @@
*************************************************/
#include <botan/numthry.h>
-#include <botan/lookup.h>
+#include <botan/libstate.h>
+#include <botan/hash.h>
#include <botan/parsing.h>
#include <algorithm>
#include <memory>
@@ -50,7 +51,10 @@ bool generate_dsa_primes(RandomNumberGenerator& rng,
"Generating a DSA parameter set with a " + to_string(qbits) +
"long q requires a seed at least as many bits long");
- std::auto_ptr<HashFunction> hash(get_hash("SHA-" + to_string(qbits)));
+ Algorithm_Factory& af = global_state().algo_factory();
+
+ std::auto_ptr<HashFunction> hash(
+ af.make_hash_function("SHA-" + to_string(qbits)));
const u32bit HASH_SIZE = hash->OUTPUT_LENGTH;
diff --git a/src/pubkey/dlies/dlies.cpp b/src/pubkey/dlies/dlies.cpp
index 2a2f33925..06a08f7f9 100644
--- a/src/pubkey/dlies/dlies.cpp
+++ b/src/pubkey/dlies/dlies.cpp
@@ -4,7 +4,6 @@
*************************************************/
#include <botan/dlies.h>
-#include <botan/lookup.h>
#include <botan/look_pk.h>
#include <botan/xor_buf.h>
#include <memory>
@@ -15,12 +14,19 @@ namespace Botan {
* DLIES_Encryptor Constructor *
*************************************************/
DLIES_Encryptor::DLIES_Encryptor(const PK_Key_Agreement_Key& k,
- const std::string& kdf,
- const std::string& mac, u32bit mk_len) :
- key(k), kdf_algo(kdf), mac_algo(mac), MAC_KEYLEN(mk_len)
+ KDF* kdf_obj,
+ MessageAuthenticationCode* mac_obj,
+ u32bit mac_kl) :
+ key(k), kdf(kdf_obj), mac(mac_obj), mac_keylen(mac_kl)
{
}
+DLIES_Encryptor::~DLIES_Encryptor()
+ {
+ delete kdf;
+ delete mac;
+ }
+
/*************************************************
* DLIES Encryption *
*************************************************/
@@ -32,9 +38,6 @@ SecureVector<byte> DLIES_Encryptor::enc(const byte in[], u32bit length,
if(other_key.is_empty())
throw Invalid_State("DLIES: The other key was never set");
- std::auto_ptr<KDF> kdf(get_kdf(kdf_algo));
- std::auto_ptr<MessageAuthenticationCode> mac(get_mac(mac_algo));
-
MemoryVector<byte> v = key.public_value();
SecureVector<byte> out(v.size() + length + mac->OUTPUT_LENGTH);
@@ -43,14 +46,14 @@ SecureVector<byte> DLIES_Encryptor::enc(const byte in[], u32bit length,
SecureVector<byte> vz(v, key.derive_key(other_key, other_key.size()));
- const u32bit K_LENGTH = length + MAC_KEYLEN;
+ const u32bit K_LENGTH = length + mac_keylen;
OctetString K = kdf->derive_key(K_LENGTH, vz, vz.size());
if(K.length() != K_LENGTH)
throw Encoding_Error("DLIES: KDF did not provide sufficient output");
byte* C = out + v.size();
- xor_buf(C, K.begin() + MAC_KEYLEN, length);
- mac->set_key(K.begin(), MAC_KEYLEN);
+ xor_buf(C, K.begin() + mac_keylen, length);
+ mac->set_key(K.begin(), mac_keylen);
mac->update(C, length);
for(u32bit j = 0; j != 8; ++j)
@@ -81,39 +84,43 @@ u32bit DLIES_Encryptor::maximum_input_size() const
* DLIES_Decryptor Constructor *
*************************************************/
DLIES_Decryptor::DLIES_Decryptor(const PK_Key_Agreement_Key& k,
- const std::string& kdf,
- const std::string& mac, u32bit mk_len) :
- key(k), kdf_algo(kdf), mac_algo(mac),
- MAC_KEYLEN(mk_len), PUBLIC_LEN(key.public_value().size())
+ KDF* kdf_obj,
+ MessageAuthenticationCode* mac_obj,
+ u32bit mac_kl) :
+ key(k), kdf(kdf_obj), mac(mac_obj), mac_keylen(mac_kl)
{
}
+DLIES_Decryptor::~DLIES_Decryptor()
+ {
+ delete kdf;
+ delete mac;
+ }
+
/*************************************************
* DLIES Decryption *
*************************************************/
SecureVector<byte> DLIES_Decryptor::dec(const byte msg[], u32bit length) const
{
- std::auto_ptr<MessageAuthenticationCode> mac(get_mac(mac_algo));
+ const u32bit public_len = key.public_value().size();
- if(length < PUBLIC_LEN + mac->OUTPUT_LENGTH)
+ if(length < public_len + mac->OUTPUT_LENGTH)
throw Decoding_Error("DLIES decryption: ciphertext is too short");
- std::auto_ptr<KDF> kdf(get_kdf(kdf_algo));
-
- const u32bit CIPHER_LEN = length - PUBLIC_LEN - mac->OUTPUT_LENGTH;
+ const u32bit CIPHER_LEN = length - public_len - mac->OUTPUT_LENGTH;
- SecureVector<byte> v(msg, PUBLIC_LEN);
- SecureVector<byte> C(msg + PUBLIC_LEN, CIPHER_LEN);
- SecureVector<byte> T(msg + PUBLIC_LEN + CIPHER_LEN, mac->OUTPUT_LENGTH);
+ SecureVector<byte> v(msg, public_len);
+ SecureVector<byte> C(msg + public_len, CIPHER_LEN);
+ SecureVector<byte> T(msg + public_len + CIPHER_LEN, mac->OUTPUT_LENGTH);
SecureVector<byte> vz(v, key.derive_key(v, v.size()));
- const u32bit K_LENGTH = C.size() + MAC_KEYLEN;
+ const u32bit K_LENGTH = C.size() + mac_keylen;
OctetString K = kdf->derive_key(K_LENGTH, vz, vz.size());
if(K.length() != K_LENGTH)
throw Encoding_Error("DLIES: KDF did not provide sufficient output");
- mac->set_key(K.begin(), MAC_KEYLEN);
+ mac->set_key(K.begin(), mac_keylen);
mac->update(C);
for(u32bit j = 0; j != 8; ++j)
mac->update(0);
@@ -121,7 +128,7 @@ SecureVector<byte> DLIES_Decryptor::dec(const byte msg[], u32bit length) const
if(T != T2)
throw Integrity_Failure("DLIES: message authentication failed");
- xor_buf(C, K.begin() + MAC_KEYLEN, C.size());
+ xor_buf(C, K.begin() + mac_keylen, C.size());
return C;
}
diff --git a/src/pubkey/dlies/dlies.h b/src/pubkey/dlies/dlies.h
index ef0f4d493..d452f1a4f 100644
--- a/src/pubkey/dlies/dlies.h
+++ b/src/pubkey/dlies/dlies.h
@@ -7,6 +7,8 @@
#define BOTAN_DLIES_H__
#include <botan/pubkey.h>
+#include <botan/mac.h>
+#include <botan/kdf.h>
namespace Botan {
@@ -17,18 +19,24 @@ class BOTAN_DLL DLIES_Encryptor : public PK_Encryptor
{
public:
DLIES_Encryptor(const PK_Key_Agreement_Key&,
- const std::string& = "KDF2(SHA-160)",
- const std::string& = "HMAC(SHA-160)", u32bit = 20);
+ KDF* kdf,
+ MessageAuthenticationCode* mac,
+ u32bit mac_key_len = 20);
+
+ ~DLIES_Encryptor();
+
void set_other_key(const MemoryRegion<byte>&);
private:
SecureVector<byte> enc(const byte[], u32bit,
RandomNumberGenerator&) const;
u32bit maximum_input_size() const;
+
const PK_Key_Agreement_Key& key;
SecureVector<byte> other_key;
- const std::string kdf_algo;
- const std::string mac_algo;
- const u32bit MAC_KEYLEN;
+
+ KDF* kdf;
+ MessageAuthenticationCode* mac;
+ u32bit mac_keylen;
};
/*************************************************
@@ -38,14 +46,20 @@ class BOTAN_DLL DLIES_Decryptor : public PK_Decryptor
{
public:
DLIES_Decryptor(const PK_Key_Agreement_Key&,
- const std::string& = "KDF2(SHA-160)",
- const std::string& = "HMAC(SHA-160)", u32bit = 20);
+ KDF* kdf,
+ MessageAuthenticationCode* mac,
+ u32bit mac_key_len = 20);
+
+ ~DLIES_Decryptor();
+
private:
SecureVector<byte> dec(const byte[], u32bit) const;
+
const PK_Key_Agreement_Key& key;
- const std::string kdf_algo;
- const std::string mac_algo;
- const u32bit MAC_KEYLEN, PUBLIC_LEN;
+
+ KDF* kdf;
+ MessageAuthenticationCode* mac;
+ u32bit mac_keylen;
};
}
diff --git a/src/pubkey/pk_lookup/look_pk.cpp b/src/pubkey/pk_lookup/look_pk.cpp
index 1a90eb82c..d72c1ce0f 100644
--- a/src/pubkey/pk_lookup/look_pk.cpp
+++ b/src/pubkey/pk_lookup/look_pk.cpp
@@ -68,7 +68,7 @@ PK_Verifier* get_pk_verifier(const PK_Verifying_wo_MR_Key& key,
PK_Key_Agreement* get_pk_kas(const PK_Key_Agreement_Key& key,
const std::string& kdf)
{
- return new PK_Key_Agreement(key, kdf);
+ return new PK_Key_Agreement(key, get_kdf(kdf));
}
}
diff --git a/src/pubkey/pubkey/pubkey.cpp b/src/pubkey/pubkey/pubkey.cpp
index 61b51d081..0e7890c5d 100644
--- a/src/pubkey/pubkey/pubkey.cpp
+++ b/src/pubkey/pubkey/pubkey.cpp
@@ -4,7 +4,6 @@
*************************************************/
#include <botan/pubkey.h>
-#include <botan/lookup.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/bigint.h>
@@ -361,8 +360,8 @@ bool PK_Verifier_wo_MR::validate_signature(const MemoryRegion<byte>& msg,
* PK_Key_Agreement Constructor *
*************************************************/
PK_Key_Agreement::PK_Key_Agreement(const PK_Key_Agreement_Key& k,
- const std::string& k_name) :
- key(k), kdf_name(k_name)
+ KDF* kdf_obj) :
+ key(k), kdf(kdf_obj)
{
}
@@ -385,13 +384,11 @@ SymmetricKey PK_Key_Agreement::derive_key(u32bit key_len, const byte in[],
u32bit in_len, const byte params[],
u32bit params_len) const
{
- std::auto_ptr<KDF> kdf((kdf_name == "Raw") ? 0 : get_kdf(kdf_name));
OctetString z = key.derive_key(in, in_len);
+ if(!kdf)
+ return z;
- if(kdf.get())
- z = kdf->derive_key(key_len, z.bits_of(), params, params_len);
-
- return z;
+ return kdf->derive_key(key_len, z.bits_of(), params, params_len);
}
}
diff --git a/src/pubkey/pubkey/pubkey.h b/src/pubkey/pubkey/pubkey.h
index 7e8de9f4c..6073fef21 100644
--- a/src/pubkey/pubkey/pubkey.h
+++ b/src/pubkey/pubkey/pubkey.h
@@ -11,6 +11,7 @@
#include <botan/rng.h>
#include <botan/eme.h>
#include <botan/emsa.h>
+#include <botan/kdf.h>
namespace Botan {
@@ -268,17 +269,17 @@ class BOTAN_DLL PK_Key_Agreement
/**
* Construct a PK Key Agreement.
* @param key the key to use
- * @param kdf_name the name of the key derivation function to use
+ * @param kdf the KDF to use
*/
- PK_Key_Agreement(const PK_Key_Agreement_Key& key,
- const std::string& kdf_name);
+ PK_Key_Agreement(const PK_Key_Agreement_Key& key, KDF* kdf);
+ ~PK_Key_Agreement() { delete kdf; }
private:
PK_Key_Agreement(const PK_Key_Agreement_Key&);
PK_Key_Agreement& operator=(const PK_Key_Agreement&);
const PK_Key_Agreement_Key& key;
- const std::string kdf_name;
+ KDF* kdf;
};
/**