aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libstate/look_pk.h14
-rw-r--r--src/pubkey/pubkey.cpp44
-rw-r--r--src/pubkey/pubkey.h32
3 files changed, 51 insertions, 39 deletions
diff --git a/src/libstate/look_pk.h b/src/libstate/look_pk.h
index 459f19564..59fe7d8c8 100644
--- a/src/libstate/look_pk.h
+++ b/src/libstate/look_pk.h
@@ -22,7 +22,7 @@ namespace Botan {
inline PK_Encryptor* get_pk_encryptor(const Public_Key& key,
const std::string& eme)
{
- return new PK_Encryptor_MR_with_EME(key, get_eme(eme));
+ return new PK_Encryptor_MR_with_EME(key, eme);
}
/**
@@ -34,7 +34,7 @@ inline PK_Encryptor* get_pk_encryptor(const Public_Key& key,
inline PK_Decryptor* get_pk_decryptor(const Private_Key& key,
const std::string& eme)
{
- return new PK_Decryptor_MR_with_EME(key, get_eme(eme));
+ return new PK_Decryptor_MR_with_EME(key, eme);
}
/**
@@ -48,9 +48,7 @@ inline PK_Signer* get_pk_signer(const Private_Key& key,
const std::string& emsa,
Signature_Format sig_format = IEEE_1363)
{
- PK_Signer* signer = new PK_Signer(key, get_emsa(emsa));
- signer->set_output_format(sig_format);
- return signer;
+ return new PK_Signer(key, emsa, sig_format);
}
/**
@@ -64,9 +62,7 @@ inline PK_Verifier* get_pk_verifier(const Public_Key& key,
const std::string& emsa,
Signature_Format sig_format = IEEE_1363)
{
- PK_Verifier* verifier = new PK_Verifier(key, get_emsa(emsa));
- verifier->set_input_format(sig_format);
- return verifier;
+ return new PK_Verifier(key, emsa, sig_format);
}
/**
@@ -78,7 +74,7 @@ inline PK_Verifier* get_pk_verifier(const Public_Key& key,
inline PK_Key_Agreement* get_pk_kas(const PK_Key_Agreement_Key& key,
const std::string& kdf)
{
- return new PK_Key_Agreement(key, get_kdf(kdf));
+ return new PK_Key_Agreement(key, kdf);
}
}
diff --git a/src/pubkey/pubkey.cpp b/src/pubkey/pubkey.cpp
index 7bff1a500..7426292ce 100644
--- a/src/pubkey/pubkey.cpp
+++ b/src/pubkey/pubkey.cpp
@@ -12,6 +12,7 @@
#include <botan/parsing.h>
#include <botan/libstate.h>
#include <botan/engine.h>
+#include <botan/lookup.h>
#include <botan/internal/bit_ops.h>
#include <memory>
@@ -21,8 +22,7 @@ namespace Botan {
* PK_Encryptor_MR_with_EME Constructor
*/
PK_Encryptor_MR_with_EME::PK_Encryptor_MR_with_EME(const Public_Key& key,
- EME* eme_obj) :
- encoder(eme_obj)
+ const std::string& eme_name)
{
Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory());
@@ -36,6 +36,8 @@ PK_Encryptor_MR_with_EME::PK_Encryptor_MR_with_EME(const Public_Key& key,
if(op == 0)
throw Lookup_Error("PK_Encryptor_MR_with_EME: No working engine for " +
key.algo_name());
+
+ eme = get_eme(eme_name);
}
/*
@@ -47,8 +49,8 @@ PK_Encryptor_MR_with_EME::enc(const byte msg[],
RandomNumberGenerator& rng) const
{
SecureVector<byte> message;
- if(encoder)
- message = encoder->encode(msg, length, op->max_input_bits(), rng);
+ if(eme)
+ message = eme->encode(msg, length, op->max_input_bits(), rng);
else
message.set(msg, length);
@@ -63,18 +65,17 @@ PK_Encryptor_MR_with_EME::enc(const byte msg[],
*/
u32bit PK_Encryptor_MR_with_EME::maximum_input_size() const
{
- if(!encoder)
+ if(!eme)
return (op->max_input_bits() / 8);
else
- return encoder->maximum_input_size(op->max_input_bits());
+ return eme->maximum_input_size(op->max_input_bits());
}
/*
* PK_Decryptor_MR_with_EME Constructor
*/
PK_Decryptor_MR_with_EME::PK_Decryptor_MR_with_EME(const Private_Key& key,
- EME* eme_obj) :
- encoder(eme_obj)
+ const std::string& eme_name)
{
Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory());
@@ -88,6 +89,8 @@ PK_Decryptor_MR_with_EME::PK_Decryptor_MR_with_EME(const Private_Key& key,
if(op == 0)
throw Lookup_Error("PK_Decryptor_MR_with_EME: No working engine for " +
key.algo_name());
+
+ eme = get_eme(eme_name);
}
/*
@@ -98,8 +101,8 @@ SecureVector<byte> PK_Decryptor_MR_with_EME::dec(const byte msg[],
{
try {
SecureVector<byte> decrypted = op->decrypt(msg, length);
- if(encoder)
- return encoder->decode(decrypted, op->max_input_bits());
+ if(eme)
+ return eme->decode(decrypted, op->max_input_bits());
else
return decrypted;
}
@@ -112,8 +115,9 @@ SecureVector<byte> PK_Decryptor_MR_with_EME::dec(const byte msg[],
/*
* PK_Signer Constructor
*/
-PK_Signer::PK_Signer(const Private_Key& key, EMSA* emsa_obj) :
- emsa(emsa_obj)
+PK_Signer::PK_Signer(const Private_Key& key,
+ const std::string& emsa_name,
+ Signature_Format format)
{
Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory());
@@ -128,7 +132,8 @@ PK_Signer::PK_Signer(const Private_Key& key, EMSA* emsa_obj) :
throw Lookup_Error("PK_Signer: No working engine for " +
key.algo_name());
- sig_format = IEEE_1363;
+ emsa = get_emsa(emsa_name);
+ sig_format = format;
}
/*
@@ -187,7 +192,9 @@ SecureVector<byte> PK_Signer::signature(RandomNumberGenerator& rng)
/*
* PK_Verifier Constructor
*/
-PK_Verifier::PK_Verifier(const Public_Key& key, EMSA* emsa_obj)
+PK_Verifier::PK_Verifier(const Public_Key& key,
+ const std::string& emsa_name,
+ Signature_Format format)
{
Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory());
@@ -202,8 +209,8 @@ PK_Verifier::PK_Verifier(const Public_Key& key, EMSA* emsa_obj)
throw Lookup_Error("PK_Verifier: No working engine for " +
key.algo_name());
- emsa = emsa_obj;
- sig_format = IEEE_1363;
+ emsa = get_emsa(emsa_name);
+ sig_format = format;
}
/*
@@ -297,8 +304,7 @@ bool PK_Verifier::validate_signature(const MemoryRegion<byte>& msg,
* PK_Key_Agreement Constructor
*/
PK_Key_Agreement::PK_Key_Agreement(const PK_Key_Agreement_Key& key,
- KDF* kdf_obj) :
- kdf(kdf_obj)
+ const std::string& kdf_name)
{
Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory());
@@ -312,6 +318,8 @@ PK_Key_Agreement::PK_Key_Agreement(const PK_Key_Agreement_Key& key,
if(op == 0)
throw Lookup_Error("PK_Key_Agreement: No working engine for " +
key.algo_name());
+
+ kdf = get_kdf(kdf_name);
}
SymmetricKey PK_Key_Agreement::derive_key(u32bit key_len, const byte in[],
diff --git a/src/pubkey/pubkey.h b/src/pubkey/pubkey.h
index 127500dd6..c65ecd468 100644
--- a/src/pubkey/pubkey.h
+++ b/src/pubkey/pubkey.h
@@ -165,8 +165,11 @@ class BOTAN_DLL PK_Signer
* @param key the key to use inside this signer
* @param emsa the EMSA to use
* An example would be "EMSA1(SHA-224)".
+ * @param format the signature format to use
*/
- PK_Signer(const Private_Key& key, EMSA* emsa);
+ PK_Signer(const Private_Key& key,
+ const std::string& emsa,
+ Signature_Format format = IEEE_1363);
~PK_Signer() { delete op; delete emsa; }
private:
@@ -260,10 +263,12 @@ class BOTAN_DLL PK_Verifier
/**
* Construct a PK Verifier.
* @param pub_key the public key to verify against
- * @param emsa the EMSA to use
- * An example would be new EMSA1(new SHA_224)
+ * @param emsa the EMSA to use (eg "EMSA3(SHA-1)")
+ * @param format the signature format to use
*/
- PK_Verifier(const Public_Key& pub_key, EMSA* emsa);
+ PK_Verifier(const Public_Key& pub_key,
+ const std::string& emsa,
+ Signature_Format format = IEEE_1363);
~PK_Verifier() { delete op; delete emsa; }
private:
@@ -350,9 +355,10 @@ class BOTAN_DLL PK_Key_Agreement
/**
* Construct a PK Key Agreement.
* @param key the key to use
- * @param kdf the KDF to use (or NULL for no KDF)
+ * @param kdf name of the KDF to use (or 'Raw' for no KDF)
*/
- PK_Key_Agreement(const PK_Key_Agreement_Key& key, KDF* kdf = 0);
+ PK_Key_Agreement(const PK_Key_Agreement_Key& key,
+ const std::string& kdf);
~PK_Key_Agreement() { delete op; delete kdf; }
private:
@@ -376,9 +382,10 @@ class BOTAN_DLL PK_Encryptor_MR_with_EME : public PK_Encryptor
* @param key the key to use inside the decryptor
* @param eme the EME to use
*/
- PK_Encryptor_MR_with_EME(const Public_Key& key, EME* eme = 0);
+ PK_Encryptor_MR_with_EME(const Public_Key& key,
+ const std::string& eme);
- ~PK_Encryptor_MR_with_EME() { delete op; delete encoder; }
+ ~PK_Encryptor_MR_with_EME() { delete op; delete eme; }
private:
PK_Encryptor_MR_with_EME(const PK_Encryptor_MR_with_EME&);
PK_Encryptor_MR_with_EME& operator=(const PK_Encryptor_MR_with_EME&);
@@ -387,7 +394,7 @@ class BOTAN_DLL PK_Encryptor_MR_with_EME : public PK_Encryptor
RandomNumberGenerator& rng) const;
const PK_Ops::Encryption* op;
- const EME* encoder;
+ const EME* eme;
};
/**
@@ -401,9 +408,10 @@ class BOTAN_DLL PK_Decryptor_MR_with_EME : public PK_Decryptor
* @param key the key to use inside the encryptor
* @param eme the EME to use
*/
- PK_Decryptor_MR_with_EME(const Private_Key& key, EME* eme = 0);
+ PK_Decryptor_MR_with_EME(const Private_Key& key,
+ const std::string& eme);
- ~PK_Decryptor_MR_with_EME() { delete op; delete encoder; }
+ ~PK_Decryptor_MR_with_EME() { delete op; delete eme; }
private:
PK_Decryptor_MR_with_EME(const PK_Decryptor_MR_with_EME&);
PK_Decryptor_MR_with_EME& operator=(const PK_Decryptor_MR_with_EME&);
@@ -411,7 +419,7 @@ class BOTAN_DLL PK_Decryptor_MR_with_EME : public PK_Decryptor
SecureVector<byte> dec(const byte[], u32bit) const;
const PK_Ops::Decryption* op;
- const EME* encoder;
+ const EME* eme;
};
}