aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-04 22:09:07 +0000
committerlloyd <[email protected]>2010-03-04 22:09:07 +0000
commit664e00a6d51cf7d6f3fefbbb3500a113d21288ab (patch)
tree32db25ebf468a2c75ec4578d83f8c41e0197bfaf /src/pubkey
parentf5cfe2857acb30ece3f01fbc98a83e8b82e4907a (diff)
This checkin represents a pretty major change in how PK operations are
performed. Up until now, each key object (eg DSA_PublicKey or ECDH_PrivateKey) had two jobs: contain the key material, and know how to perform any operations on that key. However because of a desire to support alternative implementations (GNU MP, hardware, whatever), there was a notion of operations, with the key objects containing an op that they got via engine rather than actually implementing the underlying algorithms directly. Now, represent the operation as an abstract interface (typically mapping a byte string to a byte string), and pass a plain Public_Key& or Private_Key& to the engine. The engine does any checks it wants (eg based on name, typeid, key sizes, etc), and either returns nothing (I'll pass) or a pointer to a new operation that represents signatures or encryption or what-have-you using that key. This means that plain key objects no longer contain operations. This is a major break with the traditional interface. On the other hand, using these 'bare' operations without padding, KDFs, etc is 99% of the time a bad idea anyway (and if you really need them, there are options so you get the bare op but via the pubkey.h interfaces). Currently this change is only implemented for DH and ECDH (ie, key agreement algorithms). Additionally the optional engines (gnump and openssl) have not been updated. I'll probably wait to touch those until after I can change them all in one go for all algos.
Diffstat (limited to 'src/pubkey')
-rw-r--r--src/pubkey/dh/dh.cpp40
-rw-r--r--src/pubkey/dh/dh.h33
-rw-r--r--src/pubkey/dh/dh_core.cpp65
-rw-r--r--src/pubkey/dh/dh_core.h38
-rw-r--r--src/pubkey/dh/dh_op.h45
-rw-r--r--src/pubkey/dh/info.txt3
-rw-r--r--src/pubkey/dlies/dlies.cpp45
-rw-r--r--src/pubkey/dlies/dlies.h7
-rw-r--r--src/pubkey/ecdh/ecdh.cpp21
-rw-r--r--src/pubkey/ecdh/ecdh.h17
-rw-r--r--src/pubkey/info.txt1
-rw-r--r--src/pubkey/pk_keys.h2
-rw-r--r--src/pubkey/pk_ops.h38
-rw-r--r--src/pubkey/pubkey.cpp25
-rw-r--r--src/pubkey/pubkey.h39
15 files changed, 189 insertions, 230 deletions
diff --git a/src/pubkey/dh/dh.cpp b/src/pubkey/dh/dh.cpp
index 4ebe1fa1c..70791fee4 100644
--- a/src/pubkey/dh/dh.cpp
+++ b/src/pubkey/dh/dh.cpp
@@ -21,14 +21,6 @@ DH_PublicKey::DH_PublicKey(const DL_Group& grp, const BigInt& y1)
}
/*
-* Return the maximum input size in bits
-*/
-u32bit DH_PublicKey::max_input_bits() const
- {
- return group_p().bits();
- }
-
-/*
* Return the public value for key agreement
*/
MemoryVector<byte> DH_PublicKey::public_value() const
@@ -55,8 +47,6 @@ DH_PrivateKey::DH_PrivateKey(RandomNumberGenerator& rng,
if(y == 0)
y = power_mod(group_g(), x, group_p());
- core = DH_Core(rng, group, x);
-
if(x == 0)
gen_check(rng);
else
@@ -74,8 +64,6 @@ DH_PrivateKey::DH_PrivateKey(const AlgorithmIdentifier& alg_id,
if(y == 0)
y = power_mod(group_g(), x, group_p());
- core = DH_Core(rng, group, x);
-
load_check(rng);
}
@@ -87,32 +75,4 @@ MemoryVector<byte> DH_PrivateKey::public_value() const
return DH_PublicKey::public_value();
}
-/*
-* Derive a key
-*/
-SecureVector<byte> DH_PrivateKey::derive_key(const byte w[],
- u32bit w_len) const
- {
- return derive_key(BigInt::decode(w, w_len));
- }
-
-/*
-* Derive a key
-*/
-SecureVector<byte> DH_PrivateKey::derive_key(const DH_PublicKey& key) const
- {
- return derive_key(key.get_y());
- }
-
-/*
-* Derive a key
-*/
-SecureVector<byte> DH_PrivateKey::derive_key(const BigInt& w) const
- {
- const BigInt& p = group_p();
- if(w <= 1 || w >= p-1)
- throw Invalid_Argument(algo_name() + "::derive_key: Invalid key input");
- return BigInt::encode_1363(core.agree(w), p.bytes());
- }
-
}
diff --git a/src/pubkey/dh/dh.h b/src/pubkey/dh/dh.h
index 14bc916a7..318a6215c 100644
--- a/src/pubkey/dh/dh.h
+++ b/src/pubkey/dh/dh.h
@@ -9,7 +9,8 @@
#define BOTAN_DIFFIE_HELLMAN_H__
#include <botan/dl_algo.h>
-#include <botan/dh_core.h>
+#include <botan/pow_mod.h>
+#include <botan/pk_ops.h>
namespace Botan {
@@ -22,7 +23,7 @@ class BOTAN_DLL DH_PublicKey : public virtual DL_Scheme_PublicKey
std::string algo_name() const { return "DH"; }
MemoryVector<byte> public_value() const;
- u32bit max_input_bits() const;
+ u32bit max_input_bits() const { return group_p().bits(); }
DL_Group::Format group_format() const { return DL_Group::ANSI_X9_42; }
@@ -48,10 +49,6 @@ class BOTAN_DLL DH_PrivateKey : public DH_PublicKey,
public virtual DL_Scheme_PrivateKey
{
public:
- SecureVector<byte> derive_key(const byte other[], u32bit length) const;
- SecureVector<byte> derive_key(const DH_PublicKey& other) const;
- SecureVector<byte> derive_key(const BigInt& other) const;
-
MemoryVector<byte> public_value() const;
/**
@@ -72,8 +69,30 @@ class BOTAN_DLL DH_PrivateKey : public DH_PublicKey,
*/
DH_PrivateKey(RandomNumberGenerator& rng, const DL_Group& grp,
const BigInt& x = 0);
+ };
+
+/**
+* DH operation
+*/
+class BOTAN_DLL DH_KA_Operation : public PK_Ops::KA_Operation
+ {
+ public:
+
+ DH_KA_Operation(const DH_PrivateKey& key) :
+ powermod_x_p(key.get_x(), key.get_domain().get_p()),
+ p_bytes(key.get_domain().get_p().bytes())
+ {}
+
+ SecureVector<byte> agree(const byte w[], u32bit w_len) const
+ {
+ return BigInt::encode_1363(
+ powermod_x_p(BigInt::decode(w, w_len)),
+ p_bytes);
+ }
+
private:
- DH_Core core;
+ Fixed_Exponent_Power_Mod powermod_x_p;
+ u32bit p_bytes;
};
}
diff --git a/src/pubkey/dh/dh_core.cpp b/src/pubkey/dh/dh_core.cpp
deleted file mode 100644
index cbe2dc9f1..000000000
--- a/src/pubkey/dh/dh_core.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
-* PK Algorithm Core
-* (C) 1999-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#include <botan/dh_core.h>
-#include <botan/numthry.h>
-#include <botan/internal/pk_engine.h>
-#include <botan/parsing.h>
-#include <algorithm>
-
-namespace Botan {
-
-/*
-* DH_Core Constructor
-*/
-DH_Core::DH_Core(RandomNumberGenerator& rng,
- const DL_Group& group, const BigInt& x)
- {
- const u32bit BLINDING_BITS = BOTAN_PRIVATE_KEY_OP_BLINDING_BITS;
-
- op = Engine_Core::dh_op(group, x);
-
- const BigInt& p = group.get_p();
-
- BigInt k(rng, std::min(p.bits()-1, BLINDING_BITS));
-
- if(k != 0)
- blinder = Blinder(k, power_mod(inverse_mod(k, p), x, p), p);
- }
-
-/*
-* DH_Core Copy Constructor
-*/
-DH_Core::DH_Core(const DH_Core& core)
- {
- op = 0;
- if(core.op)
- op = core.op->clone();
- blinder = core.blinder;
- }
-
-/*
-* DH_Core Assignment Operator
-*/
-DH_Core& DH_Core::operator=(const DH_Core& core)
- {
- delete op;
- if(core.op)
- op = core.op->clone();
- blinder = core.blinder;
- return (*this);
- }
-
-/*
-* DH Operation
-*/
-BigInt DH_Core::agree(const BigInt& i) const
- {
- return blinder.unblind(op->agree(blinder.blind(i)));
- }
-
-}
diff --git a/src/pubkey/dh/dh_core.h b/src/pubkey/dh/dh_core.h
deleted file mode 100644
index 91b50a27a..000000000
--- a/src/pubkey/dh/dh_core.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
-* DH Core
-* (C) 1999-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#ifndef BOTAN_DH_CORE_H__
-#define BOTAN_DH_CORE_H__
-
-#include <botan/dh_op.h>
-#include <botan/blinding.h>
-
-namespace Botan {
-
-/*
-* DH Core
-*/
-class BOTAN_DLL DH_Core
- {
- public:
- BigInt agree(const BigInt&) const;
-
- DH_Core& operator=(const DH_Core&);
-
- DH_Core() { op = 0; }
- DH_Core(const DH_Core&);
- DH_Core(RandomNumberGenerator& rng,
- const DL_Group&, const BigInt&);
- ~DH_Core() { delete op; }
- private:
- DH_Operation* op;
- Blinder blinder;
- };
-
-}
-
-#endif
diff --git a/src/pubkey/dh/dh_op.h b/src/pubkey/dh/dh_op.h
deleted file mode 100644
index 50f3d7825..000000000
--- a/src/pubkey/dh/dh_op.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-* DH Operations
-* (C) 1999-2008 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#ifndef BOTAN_DH_OPS_H__
-#define BOTAN_DH_OPS_H__
-
-#include <botan/dl_group.h>
-#include <botan/reducer.h>
-#include <botan/pow_mod.h>
-
-namespace Botan {
-
-/*
-* DH Operation Interface
-*/
-class BOTAN_DLL DH_Operation
- {
- public:
- virtual BigInt agree(const BigInt&) const = 0;
- virtual DH_Operation* clone() const = 0;
- virtual ~DH_Operation() {}
- };
-
-/*
-* Botan's Default DH Operation
-*/
-class BOTAN_DLL Default_DH_Op : public DH_Operation
- {
- public:
- BigInt agree(const BigInt& i) const { return powermod_x_p(i); }
- DH_Operation* clone() const { return new Default_DH_Op(*this); }
-
- Default_DH_Op(const DL_Group& group, const BigInt& x) :
- powermod_x_p(x, group.get_p()) {}
- private:
- Fixed_Exponent_Power_Mod powermod_x_p;
- };
-
-}
-
-#endif
diff --git a/src/pubkey/dh/info.txt b/src/pubkey/dh/info.txt
index ca8f74fa1..e1e460cd0 100644
--- a/src/pubkey/dh/info.txt
+++ b/src/pubkey/dh/info.txt
@@ -1,14 +1,11 @@
define DIFFIE_HELLMAN
<header:public>
-dh_core.h
-dh_op.h
dh.h
</header:public>
<source>
dh.cpp
-dh_core.cpp
</source>
<requires>
diff --git a/src/pubkey/dlies/dlies.cpp b/src/pubkey/dlies/dlies.cpp
index 6ef3292e1..2253f84d5 100644
--- a/src/pubkey/dlies/dlies.cpp
+++ b/src/pubkey/dlies/dlies.cpp
@@ -14,16 +14,21 @@ namespace Botan {
/*
* DLIES_Encryptor Constructor
*/
-DLIES_Encryptor::DLIES_Encryptor(const PK_Key_Agreement_Key& k,
+DLIES_Encryptor::DLIES_Encryptor(const PK_Key_Agreement_Key& key,
KDF* kdf_obj,
MessageAuthenticationCode* mac_obj,
u32bit mac_kl) :
- key(k), kdf(kdf_obj), mac(mac_obj), mac_keylen(mac_kl)
+ ka(get_pk_kas(key, "Raw")),
+ kdf(kdf_obj),
+ mac(mac_obj),
+ mac_keylen(mac_kl)
{
+ my_key = key.public_value();
}
DLIES_Encryptor::~DLIES_Encryptor()
{
+ delete ka;
delete kdf;
delete mac;
}
@@ -39,19 +44,18 @@ SecureVector<byte> DLIES_Encryptor::enc(const byte in[], u32bit length,
if(other_key.empty())
throw Invalid_State("DLIES: The other key was never set");
- MemoryVector<byte> v = key.public_value();
+ SecureVector<byte> out(my_key.size() + length + mac->OUTPUT_LENGTH);
+ out.copy(my_key, my_key.size());
+ out.copy(my_key.size(), in, length);
- SecureVector<byte> out(v.size() + length + mac->OUTPUT_LENGTH);
- out.copy(v, v.size());
- out.copy(v.size(), in, length);
-
- SecureVector<byte> vz(v, key.derive_key(other_key, other_key.size()));
+ SecureVector<byte> vz(my_key, ka->derive_key(0, other_key).bits_of());
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();
+ byte* C = out + my_key.size();
xor_buf(C, K.begin() + mac_keylen, length);
mac->set_key(K.begin(), mac_keylen);
@@ -84,16 +88,21 @@ u32bit DLIES_Encryptor::maximum_input_size() const
/*
* DLIES_Decryptor Constructor
*/
-DLIES_Decryptor::DLIES_Decryptor(const PK_Key_Agreement_Key& k,
+DLIES_Decryptor::DLIES_Decryptor(const PK_Key_Agreement_Key& key,
KDF* kdf_obj,
MessageAuthenticationCode* mac_obj,
u32bit mac_kl) :
- key(k), kdf(kdf_obj), mac(mac_obj), mac_keylen(mac_kl)
+ ka(get_pk_kas(key, "Raw")),
+ kdf(kdf_obj),
+ mac(mac_obj),
+ mac_keylen(mac_kl)
{
+ my_key = key.public_value();
}
DLIES_Decryptor::~DLIES_Decryptor()
{
+ delete ka;
delete kdf;
delete mac;
}
@@ -103,18 +112,16 @@ DLIES_Decryptor::~DLIES_Decryptor()
*/
SecureVector<byte> DLIES_Decryptor::dec(const byte msg[], u32bit length) const
{
- const u32bit public_len = key.public_value().size();
-
- if(length < public_len + mac->OUTPUT_LENGTH)
+ if(length < my_key.size() + mac->OUTPUT_LENGTH)
throw Decoding_Error("DLIES decryption: ciphertext is too short");
- const u32bit CIPHER_LEN = length - public_len - mac->OUTPUT_LENGTH;
+ const u32bit CIPHER_LEN = length - my_key.size() - 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, my_key.size());
+ SecureVector<byte> C(msg + my_key.size(), CIPHER_LEN);
+ SecureVector<byte> T(msg + my_key.size() + CIPHER_LEN, mac->OUTPUT_LENGTH);
- SecureVector<byte> vz(v, key.derive_key(v, v.size()));
+ SecureVector<byte> vz(v, ka->derive_key(0, v).bits_of());
const u32bit K_LENGTH = C.size() + mac_keylen;
OctetString K = kdf->derive_key(K_LENGTH, vz, vz.size());
diff --git a/src/pubkey/dlies/dlies.h b/src/pubkey/dlies/dlies.h
index 88a22b9de..e8b87a091 100644
--- a/src/pubkey/dlies/dlies.h
+++ b/src/pubkey/dlies/dlies.h
@@ -33,9 +33,9 @@ class BOTAN_DLL DLIES_Encryptor : public PK_Encryptor
RandomNumberGenerator&) const;
u32bit maximum_input_size() const;
- const PK_Key_Agreement_Key& key;
- SecureVector<byte> other_key;
+ SecureVector<byte> other_key, my_key;
+ PK_Key_Agreement* ka;
KDF* kdf;
MessageAuthenticationCode* mac;
u32bit mac_keylen;
@@ -57,8 +57,9 @@ class BOTAN_DLL DLIES_Decryptor : public PK_Decryptor
private:
SecureVector<byte> dec(const byte[], u32bit) const;
- const PK_Key_Agreement_Key& key;
+ SecureVector<byte> my_key;
+ PK_Key_Agreement* ka;
KDF* kdf;
MessageAuthenticationCode* mac;
u32bit mac_keylen;
diff --git a/src/pubkey/ecdh/ecdh.cpp b/src/pubkey/ecdh/ecdh.cpp
index 7ecc40ae4..37dc7c392 100644
--- a/src/pubkey/ecdh/ecdh.cpp
+++ b/src/pubkey/ecdh/ecdh.cpp
@@ -11,6 +11,27 @@
namespace Botan {
+ECDH_KA_Operation::ECDH_KA_Operation(const ECDH_PrivateKey& key)
+ {
+ cofactor = key.domain().get_cofactor();
+
+ curve = key.domain().get_curve();
+
+ l_times_priv = inverse_mod(cofactor, key.domain().get_order()) *
+ key.private_value();
+ }
+
+SecureVector<byte> ECDH_KA_Operation::agree(const byte w[], u32bit w_len) const
+ {
+ PointGFp point = OS2ECP(w, w_len, curve);
+
+ PointGFp S = (cofactor * point) * l_times_priv;
+ S.check_invariants();
+
+ return BigInt::encode_1363(S.get_affine_x(),
+ curve.get_p().bytes());
+ }
+
/**
* Derive a key
*/
diff --git a/src/pubkey/ecdh/ecdh.h b/src/pubkey/ecdh/ecdh.h
index 8185e25f2..ad7efdc13 100644
--- a/src/pubkey/ecdh/ecdh.h
+++ b/src/pubkey/ecdh/ecdh.h
@@ -11,6 +11,7 @@
#define BOTAN_ECDH_KEY_H__
#include <botan/ecc_key.h>
+#include <botan/pk_ops.h>
namespace Botan {
@@ -75,7 +76,7 @@ class BOTAN_DLL ECDH_PrivateKey : public ECDH_PublicKey,
MemoryVector<byte> public_value() const
{ return EC2OSP(public_point(), PointGFp::UNCOMPRESSED); }
-
+ private:
/**
* Derive a shared key with the other parties public key.
* @param key the other partys public key
@@ -96,6 +97,20 @@ class BOTAN_DLL ECDH_PrivateKey : public ECDH_PublicKey,
SecureVector<byte> derive_key(const PointGFp& point) const;
};
+/**
+* ECDH operation
+*/
+class BOTAN_DLL ECDH_KA_Operation : public PK_Ops::KA_Operation
+ {
+ public:
+ ECDH_KA_Operation(const ECDH_PrivateKey& key);
+
+ SecureVector<byte> agree(const byte w[], u32bit w_len) const;
+ private:
+ CurveGFp curve;
+ BigInt l_times_priv, cofactor;
+ };
+
}
#endif
diff --git a/src/pubkey/info.txt b/src/pubkey/info.txt
index 4d7105e9d..01378b856 100644
--- a/src/pubkey/info.txt
+++ b/src/pubkey/info.txt
@@ -12,6 +12,7 @@ x509_key.cpp
<header:public>
pk_keys.h
+pk_ops.h
pkcs8.h
pubkey.h
pubkey_enums.h
diff --git a/src/pubkey/pk_keys.h b/src/pubkey/pk_keys.h
index 8015c1076..c37ce46a5 100644
--- a/src/pubkey/pk_keys.h
+++ b/src/pubkey/pk_keys.h
@@ -158,8 +158,8 @@ class BOTAN_DLL PK_Verifying_wo_MR_Key : public virtual Public_Key
class BOTAN_DLL PK_Key_Agreement_Key : public virtual Private_Key
{
public:
- virtual SecureVector<byte> derive_key(const byte[], u32bit) const = 0;
virtual MemoryVector<byte> public_value() const = 0;
+
virtual ~PK_Key_Agreement_Key() {}
};
diff --git a/src/pubkey/pk_ops.h b/src/pubkey/pk_ops.h
new file mode 100644
index 000000000..2b9ac4366
--- /dev/null
+++ b/src/pubkey/pk_ops.h
@@ -0,0 +1,38 @@
+/*
+* PK Operation Types
+* (C) 2010 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_PK_OPERATIONS_H__
+#define BOTAN_PK_OPERATIONS_H__
+
+#include <botan/secmem.h>
+
+namespace Botan {
+
+namespace PK_Ops {
+
+/*
+* A generic Key Agreement Operation (eg DH or ECDH)
+*/
+class BOTAN_DLL KA_Operation
+ {
+ public:
+ /*
+ * Perform a key agreement operation
+ * @param w the other key value
+ * @param w_len the length of w in bytes
+ * @returns the agreed key
+ */
+ virtual SecureVector<byte> agree(const byte w[], u32bit w_len) const = 0;
+
+ virtual ~KA_Operation() {}
+ };
+
+}
+
+}
+
+#endif
diff --git a/src/pubkey/pubkey.cpp b/src/pubkey/pubkey.cpp
index feb33a361..6932caa34 100644
--- a/src/pubkey/pubkey.cpp
+++ b/src/pubkey/pubkey.cpp
@@ -1,6 +1,6 @@
/*
* Public Key Base
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2010 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -10,6 +10,8 @@
#include <botan/ber_dec.h>
#include <botan/bigint.h>
#include <botan/parsing.h>
+#include <botan/libstate.h>
+#include <botan/engine.h>
#include <botan/internal/bit_ops.h>
#include <memory>
@@ -356,21 +358,34 @@ 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,
+PK_Key_Agreement::PK_Key_Agreement(const PK_Key_Agreement_Key& key,
KDF* kdf_obj) :
- key(k), kdf(kdf_obj)
+ kdf(kdf_obj)
{
+ Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory());
+
+ while(const Engine* engine = i.next())
+ {
+ op = engine->get_key_agreement_op(key);
+ if(op)
+ break;
+ }
+
+ if(op == 0)
+ throw Lookup_Error("PK_Key_Agreement: No working engine for " +
+ key.algo_name());
}
SymmetricKey PK_Key_Agreement::derive_key(u32bit key_len, const byte in[],
u32bit in_len, const byte params[],
u32bit params_len) const
{
- OctetString z = key.derive_key(in, in_len);
+ SecureVector<byte> z = op->agree(in, in_len);
+
if(!kdf)
return z;
- return kdf->derive_key(key_len, z.bits_of(), params, params_len);
+ return kdf->derive_key(key_len, z, params, params_len);
}
}
diff --git a/src/pubkey/pubkey.h b/src/pubkey/pubkey.h
index 6d48faa4f..4d6490919 100644
--- a/src/pubkey/pubkey.h
+++ b/src/pubkey/pubkey.h
@@ -1,6 +1,6 @@
/*
* Public Key Interface
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2010 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -9,6 +9,7 @@
#define BOTAN_PUBKEY_H__
#include <botan/pk_keys.h>
+#include <botan/pk_ops.h>
#include <botan/symkey.h>
#include <botan/rng.h>
#include <botan/eme.h>
@@ -284,6 +285,23 @@ class BOTAN_DLL PK_Key_Agreement
* @param in the other parties key
* @param in_len the length of in in bytes
* @param params extra derivation params
+ * @param params_len the length of params in bytes
+ */
+ SymmetricKey derive_key(u32bit key_len,
+ const MemoryRegion<byte>& in,
+ const byte params[],
+ u32bit params_len) const
+ {
+ return derive_key(key_len, &in[0], in.size(),
+ params, params_len);
+ }
+
+ /*
+ * Perform Key Agreement Operation
+ * @param key_len the desired key output size
+ * @param in the other parties key
+ * @param in_len the length of in in bytes
+ * @param params extra derivation params
*/
SymmetricKey derive_key(u32bit key_len,
const byte in[], u32bit in_len,
@@ -294,6 +312,21 @@ class BOTAN_DLL PK_Key_Agreement
params.length());
}
+ /*
+ * Perform Key Agreement Operation
+ * @param key_len the desired key output size
+ * @param in the other parties key
+ * @param params extra derivation params
+ */
+ SymmetricKey derive_key(u32bit key_len,
+ const MemoryRegion<byte>& in,
+ const std::string& params = "") const
+ {
+ return derive_key(key_len, &in[0], in.size(),
+ reinterpret_cast<const byte*>(params.data()),
+ params.length());
+ }
+
/**
* Construct a PK Key Agreement.
* @param key the key to use
@@ -301,12 +334,12 @@ class BOTAN_DLL PK_Key_Agreement
*/
PK_Key_Agreement(const PK_Key_Agreement_Key& key, KDF* kdf = 0);
- ~PK_Key_Agreement() { delete kdf; }
+ ~PK_Key_Agreement() { delete op; 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;
+ PK_Ops::KA_Operation* op;
KDF* kdf;
};