aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/pk_pad/emsa.cpp13
-rw-r--r--src/lib/pk_pad/emsa_raw/emsa_raw.cpp22
-rw-r--r--src/lib/pk_pad/emsa_raw/emsa_raw.h10
-rw-r--r--src/tests/data/pubkey/ecdsa_prob.vec22
-rw-r--r--src/tests/data/pubkey/ecdsa_rfc6979.vec18
-rw-r--r--src/tests/test_ecdsa.cpp2
6 files changed, 79 insertions, 8 deletions
diff --git a/src/lib/pk_pad/emsa.cpp b/src/lib/pk_pad/emsa.cpp
index 074af273a..0fd35ef43 100644
--- a/src/lib/pk_pad/emsa.cpp
+++ b/src/lib/pk_pad/emsa.cpp
@@ -134,9 +134,18 @@ EMSA* get_emsa(const std::string& algo_spec)
#endif
#if defined(BOTAN_HAS_EMSA_RAW)
- if(req.algo_name() == "Raw" && req.arg_count() == 0)
+ if(req.algo_name() == "Raw")
{
- return new EMSA_Raw;
+ if(req.arg_count() == 0)
+ {
+ return new EMSA_Raw;
+ }
+ else
+ {
+ auto hash = HashFunction::create(req.arg(0));
+ if(hash)
+ return new EMSA_Raw(hash->output_length());
+ }
}
#endif
diff --git a/src/lib/pk_pad/emsa_raw/emsa_raw.cpp b/src/lib/pk_pad/emsa_raw/emsa_raw.cpp
index d15012a0d..bae7b2d04 100644
--- a/src/lib/pk_pad/emsa_raw/emsa_raw.cpp
+++ b/src/lib/pk_pad/emsa_raw/emsa_raw.cpp
@@ -22,6 +22,12 @@ void EMSA_Raw::update(const uint8_t input[], size_t length)
*/
secure_vector<uint8_t> EMSA_Raw::raw_data()
{
+ if(m_expected_size && m_message.size() != m_expected_size)
+ throw Invalid_Argument("EMSA_Raw was configured to use a " +
+ std::to_string(m_expected_size) +
+ " byte hash but instead was used for a " +
+ std::to_string(m_message.size()) + " hash");
+
secure_vector<uint8_t> output;
std::swap(m_message, output);
return output;
@@ -30,10 +36,17 @@ secure_vector<uint8_t> EMSA_Raw::raw_data()
/*
* EMSA-Raw Encode Operation
*/
-secure_vector<uint8_t> EMSA_Raw::encoding_of(const secure_vector<uint8_t>& msg,
- size_t,
- RandomNumberGenerator&)
+secure_vector<uint8_t>
+EMSA_Raw::encoding_of(const secure_vector<uint8_t>& msg,
+ size_t,
+ RandomNumberGenerator&)
{
+ if(m_expected_size && msg.size() != m_expected_size)
+ throw Invalid_Argument("EMSA_Raw was configured to use a " +
+ std::to_string(m_expected_size) +
+ " byte hash but instead was used for a " +
+ std::to_string(msg.size()) + " hash");
+
return msg;
}
@@ -44,6 +57,9 @@ bool EMSA_Raw::verify(const secure_vector<uint8_t>& coded,
const secure_vector<uint8_t>& raw,
size_t)
{
+ if(m_expected_size && raw.size() != m_expected_size)
+ return false;
+
if(coded.size() == raw.size())
return (coded == raw);
diff --git a/src/lib/pk_pad/emsa_raw/emsa_raw.h b/src/lib/pk_pad/emsa_raw/emsa_raw.h
index 288969257..598b9b97c 100644
--- a/src/lib/pk_pad/emsa_raw/emsa_raw.h
+++ b/src/lib/pk_pad/emsa_raw/emsa_raw.h
@@ -21,15 +21,21 @@ class BOTAN_DLL EMSA_Raw final : public EMSA
public:
EMSA* clone() override { return new EMSA_Raw(); }
+ explicit EMSA_Raw(size_t expected_hash_size = 0) :
+ m_expected_size(expected_hash_size) {}
+
private:
void update(const uint8_t[], size_t) override;
secure_vector<uint8_t> raw_data() override;
secure_vector<uint8_t> encoding_of(const secure_vector<uint8_t>&, size_t,
- RandomNumberGenerator&) override;
- bool verify(const secure_vector<uint8_t>&, const secure_vector<uint8_t>&,
+ RandomNumberGenerator&) override;
+
+ bool verify(const secure_vector<uint8_t>&,
+ const secure_vector<uint8_t>&,
size_t) override;
+ const size_t m_expected_size;
secure_vector<uint8_t> m_message;
};
diff --git a/src/tests/data/pubkey/ecdsa_prob.vec b/src/tests/data/pubkey/ecdsa_prob.vec
index dcfc5664e..e5a5ad8e5 100644
--- a/src/tests/data/pubkey/ecdsa_prob.vec
+++ b/src/tests/data/pubkey/ecdsa_prob.vec
@@ -1004,9 +1004,31 @@ Nonce = A808BBBBCDB8C60C097DD2839FA2B4DEA13777D27D11C8BD3ABE7F16FFDA4BF6
Msg = 0000000000000000000000000000000000000000000000000000000000000000
Signature = AE15A0963B6E0144E7F801616DBBBF1BB4C4943CA85B0AF9D00F3FA5CACB95FB02032D911851E27F8E5C565A43F54DE6E03EFF81A9BF73B9ACC47B363979F101
+Hash = Raw(SHA-256)
+Group = secp256r1
+X = 5
+Nonce = 35F6E341405E516C2FD796CA12F039C6971AB7A0F69B254E38CA7191F298DFB2
+Msg = 0000000000000000000000000000000000000000000000000000000000000000
+Signature = 921D2C2012856C4F8BD1AB9229C302848AB99CFCF92A512BD24B9A08F3C0DF99CE18D76B930B81493E77737E24285D07F2919C98AFE32F2450A28BA50FBE32E8
+
Hash = Raw
Group = secp384r1
X = 5
Nonce = 77294F6D855441C4DBEC66E1494DA0F2C6BFA3FB8518A9ED8D271D72BB3BE45302DCDEE6FF66555489756BECB8BF6CB9
Msg = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Signature = 53C99B5021F9DD7B8D2EC1C1BB17C03FCFF324DED361B4845D9C98E1A3F490C63946BA68DF0FA26AE62BB6E04531581C9D29FF7775BE15F14C1AA86B292F987241E42241E08DBA4229597260A4D9F433AC78F36D772F83499C5E2E3AF68F83E4
+
+X = 5
+Group = secp384r1
+Hash = Raw(SHA-384)
+Msg = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+Nonce = 6BE36DD30F03CB45B2F20A1F38025BBF7701561C163FBB426CB0B210E601EF85B3E5F60058B706C56575712A05BB780D
+Signature = 7A5C707564BF8DA1261387DFD5D5ED2A8C10B3AA4D00C9A927D5729E8BB555954F94799B972CD6F976B99703A561A1AD62929113627D363F5765D5FFCEBCF529B6B74D78B91D7A400D7E09C7613571C25E55AC98989635BE251EE123AA9A63CC
+
+X = 5
+Group = secp521r1
+Hash = Raw(SHA-512)
+Msg = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+Nonce = 0169EBB978C1B61CCE759A67B828F8213960B2E1D041DF948ABC435C99E1080D650612D1C7284E1B1F1B9D16D477B722B59545407137D0FBC17C05344A7BB2033E60
+Signature = 0157BC701722FB4853DD9F3E9BBAE977137CF04659B3CF4BD9A3FF47D8E1DF3D7B9A1E291234CD8AE9C9B9711F22C9B3B127F6217A582A9830D75184CB6A6AC174570164A920D8059F8BC21F4FBFDEE3140CF1033F3AB10260A71CBD32197822C3B575BC44DA681EBBB4612357A1E81670B2A76A35DDA2AAE708F7FD7D66D1EAE453249C
+
diff --git a/src/tests/data/pubkey/ecdsa_rfc6979.vec b/src/tests/data/pubkey/ecdsa_rfc6979.vec
index a56970fa5..7132038db 100644
--- a/src/tests/data/pubkey/ecdsa_rfc6979.vec
+++ b/src/tests/data/pubkey/ecdsa_rfc6979.vec
@@ -385,9 +385,27 @@ Hash = Raw
Msg = 0000000000000000000000000000000000000000000000000000000000000000
Signature = AE15A0963B6E0144E7F801616DBBBF1BB4C4943CA85B0AF9D00F3FA5CACB95FB02032D911851E27F8E5C565A43F54DE6E03EFF81A9BF73B9ACC47B363979F101
+X = 5
+Group = secp256r1
+Hash = Raw(SHA-256)
+Msg = 0000000000000000000000000000000000000000000000000000000000000000
+Signature = 921D2C2012856C4F8BD1AB9229C302848AB99CFCF92A512BD24B9A08F3C0DF99CE18D76B930B81493E77737E24285D07F2919C98AFE32F2450A28BA50FBE32E8
+
X = 5
Group = secp384r1
Hash = Raw
Msg = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Signature = 53C99B5021F9DD7B8D2EC1C1BB17C03FCFF324DED361B4845D9C98E1A3F490C63946BA68DF0FA26AE62BB6E04531581C9D29FF7775BE15F14C1AA86B292F987241E42241E08DBA4229597260A4D9F433AC78F36D772F83499C5E2E3AF68F83E4
+
+X = 5
+Group = secp384r1
+Hash = Raw(SHA-384)
+Msg = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+Signature = 7A5C707564BF8DA1261387DFD5D5ED2A8C10B3AA4D00C9A927D5729E8BB555954F94799B972CD6F976B99703A561A1AD62929113627D363F5765D5FFCEBCF529B6B74D78B91D7A400D7E09C7613571C25E55AC98989635BE251EE123AA9A63CC
+
+X = 5
+Group = secp521r1
+Hash = Raw(SHA-512)
+Msg = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+Signature = 0157BC701722FB4853DD9F3E9BBAE977137CF04659B3CF4BD9A3FF47D8E1DF3D7B9A1E291234CD8AE9C9B9711F22C9B3B127F6217A582A9830D75184CB6A6AC174570164A920D8059F8BC21F4FBFDEE3140CF1033F3AB10260A71CBD32197822C3B575BC44DA681EBBB4612357A1E81670B2A76A35DDA2AAE708F7FD7D66D1EAE453249C
diff --git a/src/tests/test_ecdsa.cpp b/src/tests/test_ecdsa.cpp
index 9b8c2200e..5d9c327a8 100644
--- a/src/tests/test_ecdsa.cpp
+++ b/src/tests/test_ecdsa.cpp
@@ -52,7 +52,7 @@ class ECDSA_Signature_KAT_Tests : public PK_Signature_Generation_Test
std::string default_padding(const VarMap& vars) const override
{
const std::string hash = get_req_str(vars, "Hash");
- if(hash == "Raw")
+ if(hash.substr(0,3) == "Raw")
return hash;
return "EMSA1(" + hash + ")";
}