From 7a9d0d6630c02c5b8e1123300fc7e74a12c24a03 Mon Sep 17 00:00:00 2001 From: René Korthaus Date: Wed, 13 Apr 2016 17:15:36 +0200 Subject: Add support probabilistic DSA & ECDSA Adds support for probabilistic, aka the standard, DSA and ECDSA. Can be enabled by disabling the rfc6979 module. Includes test vectors from NIST CAVP. Adds rfc6979 to the list of prohibited modules in BSI policy. --- src/lib/pubkey/ecdsa/ecdsa.cpp | 15 +++++++++++---- src/lib/pubkey/ecdsa/info.txt | 1 - 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src/lib/pubkey/ecdsa') diff --git a/src/lib/pubkey/ecdsa/ecdsa.cpp b/src/lib/pubkey/ecdsa/ecdsa.cpp index 4a4b0c037..53b5982e0 100644 --- a/src/lib/pubkey/ecdsa/ecdsa.cpp +++ b/src/lib/pubkey/ecdsa/ecdsa.cpp @@ -3,6 +3,7 @@ * (C) 2007 Manuel Hartl, FlexSecure GmbH * 2007 Falko Strenzke, FlexSecure GmbH * 2008-2010,2015 Jack Lloyd +* 2016 René Korthaus * * Botan is released under the Simplified BSD License (see license.txt) */ @@ -10,7 +11,9 @@ #include #include #include -#include +#if defined(BOTAN_HAS_RFC6979_GENERATOR) + #include +#endif namespace Botan { @@ -43,7 +46,7 @@ class ECDSA_Signature_Operation : public PK_Ops::Signature_with_EMSA m_base_point(ecdsa.domain().get_base_point(), m_order), m_x(ecdsa.private_value()), m_mod_order(m_order), - m_hash(hash_for_deterministic_signature(emsa)) + m_emsa(emsa) { } @@ -59,7 +62,7 @@ class ECDSA_Signature_Operation : public PK_Ops::Signature_with_EMSA Blinded_Point_Multiply m_base_point; const BigInt& m_x; Modular_Reducer m_mod_order; - std::string m_hash; + std::string m_emsa; }; secure_vector @@ -68,7 +71,11 @@ ECDSA_Signature_Operation::raw_sign(const byte msg[], size_t msg_len, { const BigInt m(msg, msg_len); - const BigInt k = generate_rfc6979_nonce(m_x, m_order, m, m_hash); +#if defined(BOTAN_HAS_RFC6979_GENERATOR) + const BigInt k = generate_rfc6979_nonce(m_x, m_order, m, hash_for_deterministic_signature(m_emsa)); +#else + const BigInt k = BigInt::random_integer(rng, 1, m_order); +#endif const PointGFp k_times_P = m_base_point.blinded_multiply(k, rng); const BigInt r = m_mod_order.reduce(k_times_P.get_affine_x()); diff --git a/src/lib/pubkey/ecdsa/info.txt b/src/lib/pubkey/ecdsa/info.txt index e7941d53d..e98913897 100644 --- a/src/lib/pubkey/ecdsa/info.txt +++ b/src/lib/pubkey/ecdsa/info.txt @@ -7,5 +7,4 @@ ecc_key keypair numbertheory rng -rfc6979 -- cgit v1.2.3