diff options
Diffstat (limited to 'src/lib/pubkey/gost_3410/gost_3410.cpp')
-rw-r--r-- | src/lib/pubkey/gost_3410/gost_3410.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/lib/pubkey/gost_3410/gost_3410.cpp b/src/lib/pubkey/gost_3410/gost_3410.cpp index 7e4dbe221..61f674370 100644 --- a/src/lib/pubkey/gost_3410/gost_3410.cpp +++ b/src/lib/pubkey/gost_3410/gost_3410.cpp @@ -1,5 +1,5 @@ /* -* GOST 34.10-2001 implemenation +* GOST 34.10-2012 * (C) 2007 Falko Strenzke, FlexSecure GmbH * Manuel Hartl, FlexSecure GmbH * (C) 2008-2010,2015,2018 Jack Lloyd @@ -42,7 +42,12 @@ std::vector<uint8_t> GOST_3410_PublicKey::public_key_bits() const std::string GOST_3410_PublicKey::algo_name() const { - return "GOST-34.10-2012-" + std::to_string(domain().get_p_bits()); + const size_t p_bits = domain().get_p_bits(); + + if(p_bits == 256 || p_bits == 512) + return "GOST-34.10-2012-" + std::to_string(p_bits); + else + throw Encoding_Error("GOST-34.10-2012 is not defined for parameters of this size"); } AlgorithmIdentifier GOST_3410_PublicKey::algorithm_identifier() const @@ -67,6 +72,11 @@ GOST_3410_PublicKey::GOST_3410_PublicKey(const AlgorithmIdentifier& alg_id, m_domain_params = EC_Group(ecc_param_id); + const size_t p_bits = m_domain_params.get_p_bits(); + if(p_bits != 256 && p_bits != 512) + throw Decoding_Error("GOST-34.10-2012 is not defined for parameters of size " + + std::to_string(p_bits)); + secure_vector<uint8_t> bits; BER_Decoder(key_bits).decode(bits, OCTET_STRING); @@ -88,6 +98,17 @@ GOST_3410_PublicKey::GOST_3410_PublicKey(const AlgorithmIdentifier& alg_id, "Loaded GOST 34.10 public key is on the curve"); } +GOST_3410_PrivateKey::GOST_3410_PrivateKey(RandomNumberGenerator& rng, + const EC_Group& domain, + const BigInt& x) : + EC_PrivateKey(rng, domain, x) + { + const size_t p_bits = m_domain_params.get_p_bits(); + if(p_bits != 256 && p_bits != 512) + throw Decoding_Error("GOST-34.10-2012 is not defined for parameters of size " + + std::to_string(p_bits)); + } + namespace { BigInt decode_le(const uint8_t msg[], size_t msg_len) |