diff options
author | Jack Lloyd <[email protected]> | 2019-10-06 12:21:42 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2019-10-06 12:21:42 -0400 |
commit | c5492a3632f50271c2bb44e36a82380359441375 (patch) | |
tree | 377a752791e230d8f4314fc4792d316559c1206b /src | |
parent | 1a8f7b84288e79a070e2635aca20e2357bc71f7b (diff) |
Throw if you attempt to use GOST 34.10-2012 with invalid params
It can only be used with 256 or 512 bit params, so enforce that.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/pubkey/gost_3410/gost_3410.cpp | 25 | ||||
-rw-r--r-- | src/lib/pubkey/gost_3410/gost_3410.h | 7 |
2 files changed, 26 insertions, 6 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) diff --git a/src/lib/pubkey/gost_3410/gost_3410.h b/src/lib/pubkey/gost_3410/gost_3410.h index 28e8274de..9eedaf122 100644 --- a/src/lib/pubkey/gost_3410/gost_3410.h +++ b/src/lib/pubkey/gost_3410/gost_3410.h @@ -67,8 +67,8 @@ class BOTAN_PUBLIC_API(2,0) GOST_3410_PublicKey : public virtual EC_PublicKey /** * GOST-34.10 Private Key */ -class BOTAN_PUBLIC_API(2,0) GOST_3410_PrivateKey final : public GOST_3410_PublicKey, - public EC_PrivateKey +class BOTAN_PUBLIC_API(2,0) GOST_3410_PrivateKey final : + public GOST_3410_PublicKey, public EC_PrivateKey { public: /** @@ -88,8 +88,7 @@ class BOTAN_PUBLIC_API(2,0) GOST_3410_PrivateKey final : public GOST_3410_Public */ GOST_3410_PrivateKey(RandomNumberGenerator& rng, const EC_Group& domain, - const BigInt& x = 0) : - EC_PrivateKey(rng, domain, x) {} + const BigInt& x = 0); AlgorithmIdentifier pkcs8_algorithm_identifier() const override { return EC_PublicKey::algorithm_identifier(); } |