aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pk_pad
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/pk_pad')
-rw-r--r--src/lib/pk_pad/emsa.cpp13
-rw-r--r--src/lib/pk_pad/emsa.h13
-rw-r--r--src/lib/pk_pad/emsa1/emsa1.cpp5
-rw-r--r--src/lib/pk_pad/emsa1/emsa1.h6
-rw-r--r--src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h4
-rw-r--r--src/lib/pk_pad/emsa_pssr/pssr.h2
-rw-r--r--src/lib/pk_pad/emsa_raw/emsa_raw.h3
-rw-r--r--src/lib/pk_pad/emsa_x931/emsa_x931.h2
8 files changed, 46 insertions, 2 deletions
diff --git a/src/lib/pk_pad/emsa.cpp b/src/lib/pk_pad/emsa.cpp
index 0501bc5f4..4d4b96ad1 100644
--- a/src/lib/pk_pad/emsa.cpp
+++ b/src/lib/pk_pad/emsa.cpp
@@ -41,6 +41,19 @@ EMSA* get_emsa(const std::string& algo_spec)
throw Algorithm_Not_Found(algo_spec);
}
+std::string hash_for_emsa(const std::string& algo_spec)
+ {
+ SCAN_Name emsa_name(algo_spec);
+
+ if(emsa_name.arg_count() > 0)
+ {
+ const std::string pos_hash = emsa_name.arg(0);
+ return pos_hash;
+ }
+
+ return "SHA-512"; // safe default if nothing we understand
+ }
+
#define BOTAN_REGISTER_EMSA_NAMED_NOARGS(type, name) \
BOTAN_REGISTER_NAMED_T(EMSA, name, type, make_new_T<type>)
diff --git a/src/lib/pk_pad/emsa.h b/src/lib/pk_pad/emsa.h
index d4fd146da..f4697d100 100644
--- a/src/lib/pk_pad/emsa.h
+++ b/src/lib/pk_pad/emsa.h
@@ -59,16 +59,27 @@ class BOTAN_DLL EMSA
size_t key_bits) = 0;
virtual ~EMSA();
+
+ virtual EMSA* clone() = 0;
};
/**
* Factory method for EMSA (message-encoding methods for signatures
* with appendix) objects
-* @param algo_spec the name of the EME to create
+* @param algo_spec the name of the EMSA to create
* @return pointer to newly allocated object of that type
*/
BOTAN_DLL EMSA* get_emsa(const std::string& algo_spec);
+/**
+* Returns the hash function used in the given EMSA scheme
+* If the hash function is not specified or not understood,
+* returns "SHA-512"
+* @param algo_spec the name of the EMSA
+* @return hash function used in the given EMSA scheme
+*/
+BOTAN_DLL std::string hash_for_emsa(const std::string& algo_spec);
+
}
#endif
diff --git a/src/lib/pk_pad/emsa1/emsa1.cpp b/src/lib/pk_pad/emsa1/emsa1.cpp
index 0031bf263..67f8ab21f 100644
--- a/src/lib/pk_pad/emsa1/emsa1.cpp
+++ b/src/lib/pk_pad/emsa1/emsa1.cpp
@@ -40,6 +40,11 @@ secure_vector<byte> emsa1_encoding(const secure_vector<byte>& msg,
}
+EMSA* EMSA1::clone()
+ {
+ return new EMSA1(m_hash->clone());
+ }
+
void EMSA1::update(const byte input[], size_t length)
{
m_hash->update(input, length);
diff --git a/src/lib/pk_pad/emsa1/emsa1.h b/src/lib/pk_pad/emsa1/emsa1.h
index e346167da..5a4b4b372 100644
--- a/src/lib/pk_pad/emsa1/emsa1.h
+++ b/src/lib/pk_pad/emsa1/emsa1.h
@@ -25,8 +25,13 @@ class BOTAN_DLL EMSA1 : public EMSA
*/
explicit EMSA1(HashFunction* hash) : m_hash(hash) {}
+ EMSA* clone() override;
+
protected:
size_t hash_output_length() const { return m_hash->output_length(); }
+
+ std::unique_ptr<HashFunction> m_hash;
+
private:
void update(const byte[], size_t) override;
secure_vector<byte> raw_data() override;
@@ -39,7 +44,6 @@ class BOTAN_DLL EMSA1 : public EMSA
const secure_vector<byte>& raw,
size_t key_bits) override;
- std::unique_ptr<HashFunction> m_hash;
};
}
diff --git a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h
index 9d5bc7829..0773ed2c4 100644
--- a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h
+++ b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h
@@ -28,6 +28,8 @@ class BOTAN_DLL EMSA_PKCS1v15 final : public EMSA
*/
explicit EMSA_PKCS1v15(HashFunction* hash);
+ EMSA* clone() override { return new EMSA_PKCS1v15(m_hash->clone()); }
+
void update(const byte[], size_t) override;
secure_vector<byte> raw_data() override;
@@ -50,6 +52,8 @@ class BOTAN_DLL EMSA_PKCS1v15 final : public EMSA
class BOTAN_DLL EMSA_PKCS1v15_Raw final : public EMSA
{
public:
+ EMSA* clone() override { return new EMSA_PKCS1v15_Raw(); }
+
void update(const byte[], size_t) override;
secure_vector<byte> raw_data() override;
diff --git a/src/lib/pk_pad/emsa_pssr/pssr.h b/src/lib/pk_pad/emsa_pssr/pssr.h
index ee234b0b6..9b39417a5 100644
--- a/src/lib/pk_pad/emsa_pssr/pssr.h
+++ b/src/lib/pk_pad/emsa_pssr/pssr.h
@@ -31,6 +31,8 @@ class BOTAN_DLL PSSR final : public EMSA
*/
PSSR(HashFunction* hash, size_t salt_size);
+ EMSA* clone() override { return new PSSR(m_hash->clone(), m_SALT_SIZE); }
+
static PSSR* make(const Spec& spec);
private:
void update(const byte input[], size_t length) override;
diff --git a/src/lib/pk_pad/emsa_raw/emsa_raw.h b/src/lib/pk_pad/emsa_raw/emsa_raw.h
index 272d34b0e..cc2d5d63a 100644
--- a/src/lib/pk_pad/emsa_raw/emsa_raw.h
+++ b/src/lib/pk_pad/emsa_raw/emsa_raw.h
@@ -18,6 +18,9 @@ namespace Botan {
*/
class BOTAN_DLL EMSA_Raw final : public EMSA
{
+ public:
+ EMSA* clone() override { return new EMSA_Raw(); }
+
private:
void update(const byte[], size_t) override;
secure_vector<byte> raw_data() override;
diff --git a/src/lib/pk_pad/emsa_x931/emsa_x931.h b/src/lib/pk_pad/emsa_x931/emsa_x931.h
index 400042a86..56754d3b1 100644
--- a/src/lib/pk_pad/emsa_x931/emsa_x931.h
+++ b/src/lib/pk_pad/emsa_x931/emsa_x931.h
@@ -25,6 +25,8 @@ class BOTAN_DLL EMSA_X931 final : public EMSA
* @param hash the hash object to use
*/
explicit EMSA_X931(HashFunction* hash);
+
+ EMSA* clone() override { return new EMSA_X931(m_hash->clone()); }
private:
void update(const byte[], size_t) override;
secure_vector<byte> raw_data() override;