diff options
author | lloyd <[email protected]> | 2008-09-28 18:11:26 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-28 18:11:26 +0000 |
commit | d59f6a2c9e797ee22c21b2d85c662e0fe8d1cf35 (patch) | |
tree | adfe8935b8a92bead174fb9f472c95a5eae1ab35 | |
parent | 47ffeed7f8270855596c4f1d7b2d405172d78e8c (diff) |
Add missing files
-rw-r--r-- | modules/kdf/kdf1/kdf1.cpp | 35 | ||||
-rw-r--r-- | modules/kdf/kdf1/kdf1.h | 29 | ||||
-rw-r--r-- | modules/kdf/kdf1/modinfo.txt | 10 | ||||
-rw-r--r-- | modules/kdf/kdf2/kdf2.cpp | 51 | ||||
-rw-r--r-- | modules/kdf/kdf2/modinfo.txt | 10 | ||||
-rw-r--r-- | modules/kdf/pbkdf1/modinfo.txt | 10 | ||||
-rw-r--r-- | modules/kdf/pbkdf1/pbkdf1.cpp | 57 | ||||
-rw-r--r-- | modules/kdf/pbkdf1/pbkdf1.h | 30 | ||||
-rw-r--r-- | modules/kdf/pbkdf2/modinfo.txt | 10 | ||||
-rw-r--r-- | modules/kdf/pgps2k/modinfo.txt | 10 | ||||
-rw-r--r-- | modules/kdf/sslv3/modinfo.txt | 10 | ||||
-rw-r--r-- | modules/kdf/sslv3/prf_ssl3.h | 25 | ||||
-rw-r--r-- | modules/kdf/tlsv1/modinfo.txt | 10 | ||||
-rw-r--r-- | modules/kdf/tlsv1/prf_tls.h | 29 | ||||
-rw-r--r-- | modules/kdf/x942/modinfo.txt | 10 | ||||
-rw-r--r-- | modules/kdf/x942/prf_x942.h | 29 |
16 files changed, 365 insertions, 0 deletions
diff --git a/modules/kdf/kdf1/kdf1.cpp b/modules/kdf/kdf1/kdf1.cpp new file mode 100644 index 000000000..aac32db80 --- /dev/null +++ b/modules/kdf/kdf1/kdf1.cpp @@ -0,0 +1,35 @@ +/************************************************* +* KDF1 Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include <botan/kdf1.h> +#include <botan/lookup.h> +#include <memory> + +namespace Botan { + +/************************************************* +* KDF1 Key Derivation Mechanism * +*************************************************/ +SecureVector<byte> KDF1::derive(u32bit, + const byte secret[], u32bit secret_len, + const byte P[], u32bit P_len) const + { + std::auto_ptr<HashFunction> hash(get_hash(hash_name)); + + hash->update(secret, secret_len); + hash->update(P, P_len); + return hash->final(); + } + +/************************************************* +* KDF1 Constructor * +*************************************************/ +KDF1::KDF1(const std::string& h_name) : hash_name(h_name) + { + if(!have_hash(hash_name)) + throw Algorithm_Not_Found(hash_name); + } + +} diff --git a/modules/kdf/kdf1/kdf1.h b/modules/kdf/kdf1/kdf1.h new file mode 100644 index 000000000..ebc1979fc --- /dev/null +++ b/modules/kdf/kdf1/kdf1.h @@ -0,0 +1,29 @@ +/************************************************* +* KDF1 Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_KDF1_H__ +#define BOTAN_KDF1_H__ + +#include <botan/pk_util.h> + +namespace Botan { + +/************************************************* +* KDF1 * +*************************************************/ +class BOTAN_DLL KDF1 : public KDF + { + public: + SecureVector<byte> derive(u32bit, const byte[], u32bit, + const byte[], u32bit) const; + + KDF1(const std::string&); + private: + const std::string hash_name; + }; + +} + +#endif diff --git a/modules/kdf/kdf1/modinfo.txt b/modules/kdf/kdf1/modinfo.txt new file mode 100644 index 000000000..802df67d0 --- /dev/null +++ b/modules/kdf/kdf1/modinfo.txt @@ -0,0 +1,10 @@ +realname "KDF1" + +define KDF1 + +load_on auto + +<add> +kdf1.h +kdf1.cpp +</add> diff --git a/modules/kdf/kdf2/kdf2.cpp b/modules/kdf/kdf2/kdf2.cpp new file mode 100644 index 000000000..fa975ccb9 --- /dev/null +++ b/modules/kdf/kdf2/kdf2.cpp @@ -0,0 +1,51 @@ +/************************************************* +* KDF2 Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include <botan/kdf2.h> +#include <botan/lookup.h> +#include <botan/loadstor.h> +#include <memory> + +namespace Botan { + +/************************************************* +* KDF2 Key Derivation Mechanism * +*************************************************/ +SecureVector<byte> KDF2::derive(u32bit out_len, + const byte secret[], u32bit secret_len, + const byte P[], u32bit P_len) const + { + SecureVector<byte> output; + u32bit counter = 1; + + std::auto_ptr<HashFunction> hash(get_hash(hash_name)); + while(out_len && counter) + { + hash->update(secret, secret_len); + for(u32bit j = 0; j != 4; ++j) + hash->update(get_byte(j, counter)); + hash->update(P, P_len); + SecureVector<byte> hash_result = hash->final(); + + u32bit added = std::min(hash_result.size(), out_len); + output.append(hash_result, added); + out_len -= added; + + ++counter; + } + + return output; + } + +/************************************************* +* KDF2 Constructor * +*************************************************/ +KDF2::KDF2(const std::string& h_name) : hash_name(h_name) + { + if(!have_hash(hash_name)) + throw Algorithm_Not_Found(hash_name); + } + +} diff --git a/modules/kdf/kdf2/modinfo.txt b/modules/kdf/kdf2/modinfo.txt new file mode 100644 index 000000000..7fceffb18 --- /dev/null +++ b/modules/kdf/kdf2/modinfo.txt @@ -0,0 +1,10 @@ +realname "KDF2" + +define KDF2 + +load_on auto + +<add> +kdf2.cpp +kdf2.h +</add> diff --git a/modules/kdf/pbkdf1/modinfo.txt b/modules/kdf/pbkdf1/modinfo.txt new file mode 100644 index 000000000..3c1ae802c --- /dev/null +++ b/modules/kdf/pbkdf1/modinfo.txt @@ -0,0 +1,10 @@ +realname "Pbkdf1" + +define PBKDF1 + +load_on auto + +<add> +pbkdf1.cpp +pbkdf1.h +</add> diff --git a/modules/kdf/pbkdf1/pbkdf1.cpp b/modules/kdf/pbkdf1/pbkdf1.cpp new file mode 100644 index 000000000..70cff9eee --- /dev/null +++ b/modules/kdf/pbkdf1/pbkdf1.cpp @@ -0,0 +1,57 @@ +/************************************************* +* PBKDF1 Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include <botan/pbkdf1.h> +#include <botan/lookup.h> +#include <memory> + +namespace Botan { + +/************************************************* +* Return a PKCS#5 PBKDF1 derived key * +*************************************************/ +OctetString PKCS5_PBKDF1::derive(u32bit key_len, + const std::string& passphrase, + const byte salt[], u32bit salt_size, + u32bit iterations) const + { + if(iterations == 0) + throw Invalid_Argument("PKCS#5 PBKDF1: Invalid iteration count"); + + std::auto_ptr<HashFunction> hash(get_hash(hash_name)); + if(key_len > hash->OUTPUT_LENGTH) + throw Exception("PKCS#5 PBKDF1: Requested output length too long"); + + hash->update(passphrase); + hash->update(salt, salt_size); + SecureVector<byte> key = hash->final(); + + for(u32bit j = 1; j != iterations; ++j) + { + hash->update(key); + hash->final(key); + } + + return OctetString(key, std::min(key_len, key.size())); + } + +/************************************************* +* Return the name of this type * +*************************************************/ +std::string PKCS5_PBKDF1::name() const + { + return "PBKDF1(" + hash_name + ")"; + } + +/************************************************* +* PKCS5_PBKDF1 Constructor * +*************************************************/ +PKCS5_PBKDF1::PKCS5_PBKDF1(const std::string& h_name) : hash_name(h_name) + { + if(!have_hash(hash_name)) + throw Algorithm_Not_Found(hash_name); + } + +} diff --git a/modules/kdf/pbkdf1/pbkdf1.h b/modules/kdf/pbkdf1/pbkdf1.h new file mode 100644 index 000000000..3608bb470 --- /dev/null +++ b/modules/kdf/pbkdf1/pbkdf1.h @@ -0,0 +1,30 @@ +/************************************************* +* PBKDF1 Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_PBKDF1_H__ +#define BOTAN_PBKDF1_H__ + +#include <botan/s2k.h> + +namespace Botan { + +/************************************************* +* PKCS #5 PBKDF1 * +*************************************************/ +class BOTAN_DLL PKCS5_PBKDF1 : public S2K + { + public: + std::string name() const; + S2K* clone() const { return new PKCS5_PBKDF1(hash_name); } + PKCS5_PBKDF1(const std::string&); + private: + OctetString derive(u32bit, const std::string&, + const byte[], u32bit, u32bit) const; + const std::string hash_name; + }; + +} + +#endif diff --git a/modules/kdf/pbkdf2/modinfo.txt b/modules/kdf/pbkdf2/modinfo.txt new file mode 100644 index 000000000..e51a331c6 --- /dev/null +++ b/modules/kdf/pbkdf2/modinfo.txt @@ -0,0 +1,10 @@ +realname "Pbkdf2" + +define PBKDF2 + +load_on auto + +<add> +pbkdf2.cpp +pbkdf2.h +</add> diff --git a/modules/kdf/pgps2k/modinfo.txt b/modules/kdf/pgps2k/modinfo.txt new file mode 100644 index 000000000..a3d5a146f --- /dev/null +++ b/modules/kdf/pgps2k/modinfo.txt @@ -0,0 +1,10 @@ +realname "Pgps2k" + +define PGPS2K + +load_on auto + +<add> +pgp_s2k.cpp +pgp_s2k.h +</add> diff --git a/modules/kdf/sslv3/modinfo.txt b/modules/kdf/sslv3/modinfo.txt new file mode 100644 index 000000000..c41b59b12 --- /dev/null +++ b/modules/kdf/sslv3/modinfo.txt @@ -0,0 +1,10 @@ +realname "SSLv3 PRF" + +define SSL_V3_PRF + +load_on auto + +<add> +prf_ssl3.h +prf_ssl3.cpp +</add> diff --git a/modules/kdf/sslv3/prf_ssl3.h b/modules/kdf/sslv3/prf_ssl3.h new file mode 100644 index 000000000..951ccfe92 --- /dev/null +++ b/modules/kdf/sslv3/prf_ssl3.h @@ -0,0 +1,25 @@ +/************************************************* +* SSLv3 PRF Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_SSLV3_PRF_H__ +#define BOTAN_SSLV3_PRF_H__ + +#include <botan/pk_util.h> + +namespace Botan { + +/************************************************* +* SSL3 PRF * +*************************************************/ +class BOTAN_DLL SSL3_PRF : public KDF + { + public: + SecureVector<byte> derive(u32bit, const byte[], u32bit, + const byte[], u32bit) const; + }; + +} + +#endif diff --git a/modules/kdf/tlsv1/modinfo.txt b/modules/kdf/tlsv1/modinfo.txt new file mode 100644 index 000000000..9f05f8729 --- /dev/null +++ b/modules/kdf/tlsv1/modinfo.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/modules/kdf/tlsv1/prf_tls.h b/modules/kdf/tlsv1/prf_tls.h new file mode 100644 index 000000000..ebd0815ca --- /dev/null +++ b/modules/kdf/tlsv1/prf_tls.h @@ -0,0 +1,29 @@ +/************************************************* +* TLS v1.0 PRF Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_TLS_PRF__ +#define BOTAN_TLS_PRF__ + +#include <botan/pk_util.h> + +namespace Botan { + +/************************************************* +* TLS PRF * +*************************************************/ +class BOTAN_DLL TLS_PRF : public KDF + { + public: + SecureVector<byte> derive(u32bit, const byte[], u32bit, + const byte[], u32bit) const; + private: + SecureVector<byte> P_hash(const std::string&, u32bit, + const byte[], u32bit, + const byte[], u32bit) const; + }; + +} + +#endif diff --git a/modules/kdf/x942/modinfo.txt b/modules/kdf/x942/modinfo.txt new file mode 100644 index 000000000..32057fe94 --- /dev/null +++ b/modules/kdf/x942/modinfo.txt @@ -0,0 +1,10 @@ +realname "X942 PRF" + +define X942_PRF + +load_on auto + +<add> +prf_x942.cpp +prf_x942.h +</add> diff --git a/modules/kdf/x942/prf_x942.h b/modules/kdf/x942/prf_x942.h new file mode 100644 index 000000000..9b78d1f86 --- /dev/null +++ b/modules/kdf/x942/prf_x942.h @@ -0,0 +1,29 @@ +/************************************************* +* X9.42 PRF Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_ANSI_X942_PRF_H__ +#define BOTAN_ANSI_X942_PRF_H__ + +#include <botan/pk_util.h> + +namespace Botan { + +/************************************************* +* X9.42 PRF * +*************************************************/ +class BOTAN_DLL X942_PRF : public KDF + { + public: + SecureVector<byte> derive(u32bit, const byte[], u32bit, + const byte[], u32bit) const; + + X942_PRF(const std::string&); + private: + std::string key_wrap_oid; + }; + +} + +#endif |