aboutsummaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-29 19:09:22 +0000
committerlloyd <[email protected]>2008-09-29 19:09:22 +0000
commitee9965d3a59112d042df7569fde6a45302491499 (patch)
tree26ca5230867cdda27dde0100265ec3d5bb91ff7d /src/core
parent1371cecdcf42e1070512b888307871f81421469b (diff)
Move KDF, EME, and EMSA base classes from pubkey to core to remove a
false dependency on BigInt in the KDF/padding code.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/get_pbe.cpp3
-rw-r--r--src/core/info.txt8
-rw-r--r--src/core/kdf.cpp70
-rw-r--r--src/core/kdf.h50
-rw-r--r--src/core/lookup.h10
-rw-r--r--src/core/pk_pad.cpp48
6 files changed, 177 insertions, 12 deletions
diff --git a/src/core/get_pbe.cpp b/src/core/get_pbe.cpp
index 6bd85b3e1..cd1ed2aa4 100644
--- a/src/core/get_pbe.cpp
+++ b/src/core/get_pbe.cpp
@@ -3,8 +3,7 @@
* (C) 1999-2007 Jack Lloyd *
*************************************************/
-#include <botan/lookup.h>
-#include <botan/pbe.h>
+#include <botan/get_pbe.h>
#include <botan/oids.h>
#include <botan/parsing.h>
diff --git a/src/core/info.txt b/src/core/info.txt
index 16f2a041f..a77165072 100644
--- a/src/core/info.txt
+++ b/src/core/info.txt
@@ -23,15 +23,17 @@ def_powm.cpp
eng_base.cpp
engine.cpp
exceptn.cpp
-lookup.cpp
get_enc.cpp
get_pbe.cpp
init_def.cpp
init_opt.cpp
+kdf.cpp
libstate.cpp
look_pk.cpp
+lookup.cpp
modules.cpp
oids.cpp
+pk_pad.cpp
policy.cpp
rng.cpp
s2k.cpp
@@ -45,15 +47,17 @@ engine.h
enums.h
exceptn.h
init.h
+kdf.h
libstate.h
look_add.h
look_pk.h
+get_pbe.h
lookup.h
modules.h
mutex.h
oids.h
+pk_pad.h
rng.h
s2k.h
symkey.h
</add>
-
diff --git a/src/core/kdf.cpp b/src/core/kdf.cpp
new file mode 100644
index 000000000..2d24d896c
--- /dev/null
+++ b/src/core/kdf.cpp
@@ -0,0 +1,70 @@
+/*************************************************
+* KDF Base Class Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/kdf.h>
+#include <botan/lookup.h>
+#include <botan/loadstor.h>
+#include <algorithm>
+#include <memory>
+
+namespace Botan {
+
+/*************************************************
+* Derive a key *
+*************************************************/
+SecureVector<byte> KDF::derive_key(u32bit key_len,
+ const MemoryRegion<byte>& secret,
+ const std::string& salt) const
+ {
+ return derive_key(key_len, secret, secret.size(),
+ reinterpret_cast<const byte*>(salt.data()),
+ salt.length());
+ }
+
+/*************************************************
+* Derive a key *
+*************************************************/
+SecureVector<byte> KDF::derive_key(u32bit key_len,
+ const MemoryRegion<byte>& secret,
+ const byte salt[], u32bit salt_len) const
+ {
+ return derive_key(key_len, secret.begin(), secret.size(),
+ salt, salt_len);
+ }
+
+/*************************************************
+* Derive a key *
+*************************************************/
+SecureVector<byte> KDF::derive_key(u32bit key_len,
+ const MemoryRegion<byte>& secret,
+ const MemoryRegion<byte>& salt) const
+ {
+ return derive_key(key_len, secret.begin(), secret.size(),
+ salt.begin(), salt.size());
+ }
+
+/*************************************************
+* Derive a key *
+*************************************************/
+SecureVector<byte> KDF::derive_key(u32bit key_len,
+ const byte secret[], u32bit secret_len,
+ const std::string& salt) const
+ {
+ return derive_key(key_len, secret, secret_len,
+ reinterpret_cast<const byte*>(salt.data()),
+ salt.length());
+ }
+
+/*************************************************
+* Derive a key *
+*************************************************/
+SecureVector<byte> KDF::derive_key(u32bit key_len,
+ const byte secret[], u32bit secret_len,
+ const byte salt[], u32bit salt_len) const
+ {
+ return derive(key_len, secret, secret_len, salt, salt_len);
+ }
+
+}
diff --git a/src/core/kdf.h b/src/core/kdf.h
new file mode 100644
index 000000000..7d0c1866b
--- /dev/null
+++ b/src/core/kdf.h
@@ -0,0 +1,50 @@
+/*************************************************
+* KDF/MGF Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_KDF_BASE_H__
+#define BOTAN_KDF_BASE_H__
+
+#include <botan/secmem.h>
+#include <botan/types.h>
+
+namespace Botan {
+
+/*************************************************
+* Key Derivation Function *
+*************************************************/
+class BOTAN_DLL KDF
+ {
+ public:
+ SecureVector<byte> derive_key(u32bit, const MemoryRegion<byte>&,
+ const std::string& = "") const;
+ SecureVector<byte> derive_key(u32bit, const MemoryRegion<byte>&,
+ const MemoryRegion<byte>&) const;
+ SecureVector<byte> derive_key(u32bit, const MemoryRegion<byte>&,
+ const byte[], u32bit) const;
+
+ SecureVector<byte> derive_key(u32bit, const byte[], u32bit,
+ const std::string& = "") const;
+ SecureVector<byte> derive_key(u32bit, const byte[], u32bit,
+ const byte[], u32bit) const;
+
+ virtual ~KDF() {}
+ private:
+ virtual SecureVector<byte> derive(u32bit, const byte[], u32bit,
+ const byte[], u32bit) const = 0;
+ };
+
+/*************************************************
+* Mask Generation Function *
+*************************************************/
+class BOTAN_DLL MGF
+ {
+ public:
+ virtual void mask(const byte[], u32bit, byte[], u32bit) const = 0;
+ virtual ~MGF() {}
+ };
+
+}
+
+#endif
diff --git a/src/core/lookup.h b/src/core/lookup.h
index fb163342a..016ad4618 100644
--- a/src/core/lookup.h
+++ b/src/core/lookup.h
@@ -10,10 +10,10 @@
#include <botan/enums.h>
#include <botan/filters.h>
#include <botan/mode_pad.h>
-#include <botan/pk_util.h>
+#include <botan/kdf.h>
+#include <botan/pk_pad.h>
#include <botan/libstate.h>
#include <botan/s2k.h>
-#include <botan/pbe.h>
namespace Botan {
@@ -48,12 +48,6 @@ BOTAN_DLL S2K* get_s2k(const std::string&);
BOTAN_DLL const BlockCipherModePaddingMethod* get_bc_pad(const std::string&);
/*************************************************
-* Get a PBE object *
-*************************************************/
-BOTAN_DLL PBE* get_pbe(const std::string&);
-BOTAN_DLL PBE* get_pbe(const OID&, DataSource&);
-
-/*************************************************
* Get an EMSA/EME/KDF/MGF function *
*************************************************/
BOTAN_DLL EME* get_eme(const std::string&);
diff --git a/src/core/pk_pad.cpp b/src/core/pk_pad.cpp
new file mode 100644
index 000000000..23dc9a95b
--- /dev/null
+++ b/src/core/pk_pad.cpp
@@ -0,0 +1,48 @@
+/*************************************************
+* EME/EMSA Base Class Source File *
+* (C) 1999-2008 Jack Lloyd *
+*************************************************/
+
+#include <botan/pk_pad.h>
+
+namespace Botan {
+
+/*************************************************
+* Encode a message *
+*************************************************/
+SecureVector<byte> EME::encode(const byte msg[], u32bit msg_len,
+ u32bit key_bits,
+ RandomNumberGenerator& rng) const
+ {
+ return pad(msg, msg_len, key_bits, rng);
+ }
+
+/*************************************************
+* Encode a message *
+*************************************************/
+SecureVector<byte> EME::encode(const MemoryRegion<byte>& msg,
+ u32bit key_bits,
+ RandomNumberGenerator& rng) const
+ {
+ return pad(msg, msg.size(), key_bits, rng);
+ }
+
+/*************************************************
+* Decode a message *
+*************************************************/
+SecureVector<byte> EME::decode(const byte msg[], u32bit msg_len,
+ u32bit key_bits) const
+ {
+ return unpad(msg, msg_len, key_bits);
+ }
+
+/*************************************************
+* Decode a message *
+*************************************************/
+SecureVector<byte> EME::decode(const MemoryRegion<byte>& msg,
+ u32bit key_bits) const
+ {
+ return unpad(msg, msg.size(), key_bits);
+ }
+
+}