diff options
author | Jack Lloyd <[email protected]> | 2021-05-22 11:49:49 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2021-05-22 11:50:34 -0400 |
commit | 9745a8fed0f94d0fd26f6056572eb072d7108840 (patch) | |
tree | 6efcf45d34070e1badbb0ebca9f8b61af8a65c78 /src/lib/pubkey/pk_ops.cpp | |
parent | cb803e0c1b016428f9851eb9705498bc253bdb0f (diff) |
Prevent using non-sensical padding schemes
Most padding schemes require message recovery, which, now that NR and
RW have both been removed, limits their usage to RSA.
Diffstat (limited to 'src/lib/pubkey/pk_ops.cpp')
-rw-r--r-- | src/lib/pubkey/pk_ops.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/lib/pubkey/pk_ops.cpp b/src/lib/pubkey/pk_ops.cpp index d9a0a71a9..c9f25b748 100644 --- a/src/lib/pubkey/pk_ops.cpp +++ b/src/lib/pubkey/pk_ops.cpp @@ -59,12 +59,17 @@ secure_vector<uint8_t> PK_Ops::Key_Agreement_with_KDF::agree(size_t key_len, return z; } -PK_Ops::Signature_with_EMSA::Signature_with_EMSA(const std::string& emsa) : +PK_Ops::Signature_with_EMSA::Signature_with_EMSA(const std::string& emsa, bool with_message_recovery) : Signature(), m_emsa(EMSA::create_or_throw(emsa)), m_hash(hash_for_emsa(emsa)), m_prefix_used(false) { + if(!with_message_recovery && m_emsa->requires_message_recovery()) + { + throw Invalid_Argument("Signature padding method " + emsa + + " requires message recovery, which is not supported by this scheme"); + } } void PK_Ops::Signature_with_EMSA::update(const uint8_t msg[], size_t msg_len) @@ -86,12 +91,17 @@ secure_vector<uint8_t> PK_Ops::Signature_with_EMSA::sign(RandomNumberGenerator& return raw_sign(padded.data(), padded.size(), rng); } -PK_Ops::Verification_with_EMSA::Verification_with_EMSA(const std::string& emsa) : +PK_Ops::Verification_with_EMSA::Verification_with_EMSA(const std::string& emsa, bool with_message_recovery) : Verification(), m_emsa(EMSA::create_or_throw(emsa)), m_hash(hash_for_emsa(emsa)), m_prefix_used(false) { + if(!with_message_recovery && m_emsa->requires_message_recovery()) + { + throw Invalid_Argument("Signature padding method " + emsa + + " requires message recovery, which is not supported by this scheme"); + } } void PK_Ops::Verification_with_EMSA::update(const uint8_t msg[], size_t msg_len) |