diff options
author | Never <[email protected]> | 2017-02-27 17:35:05 +0100 |
---|---|---|
committer | Never <[email protected]> | 2017-02-27 17:35:05 +0100 |
commit | f79cba75823ba72a8dc4d1931087acddd0c32af3 (patch) | |
tree | 9deb3e12f82c41d8bdca69b652724fb12d94c245 /src/lib | |
parent | 09d213dead4d3519bbd9aa8083e8c784a4eb9c4f (diff) |
EC_PublicKey::check_key for curves with cofactor > 1
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/pubkey/ecc_key/ecc_key.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/lib/pubkey/ecc_key/ecc_key.cpp b/src/lib/pubkey/ecc_key/ecc_key.cpp index cb0af42eb..fd1e9dd83 100644 --- a/src/lib/pubkey/ecc_key/ecc_key.cpp +++ b/src/lib/pubkey/ecc_key/ecc_key.cpp @@ -47,9 +47,32 @@ EC_PublicKey::EC_PublicKey(const AlgorithmIdentifier& alg_id, bool EC_PublicKey::check_key(RandomNumberGenerator&, bool) const { - return public_point().on_the_curve(); + //check that public point is not at infinity + if(public_point().is_zero()) + { + return false; + } + //check that public point is on the curve + if(!public_point().on_the_curve()) + { + return false; + } + if(m_domain_params.get_cofactor() > 1) + { + if((public_point() * m_domain_params.get_cofactor()).is_zero()) + { + return false; + } + //check that public point has order q + if(!(public_point() * m_domain_params.get_order()).is_zero()) + { + return false; + } + } + return true; } + AlgorithmIdentifier EC_PublicKey::algorithm_identifier() const { return AlgorithmIdentifier(get_oid(), DER_domain()); |