diff options
author | lloyd <[email protected]> | 2011-04-08 18:13:41 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2011-04-08 18:13:41 +0000 |
commit | 8b543e804375a788ae71d461c0f8cf5d4193fc25 (patch) | |
tree | 6177931cd84a9be204cdab6e62729954e69e0421 /src/pubkey/ecc_key | |
parent | 3b66bfd4da97189ec275e5f85b9f85009d3f8370 (diff) |
ECC private keys had two different constructors, one taking a group
and a random number generator, and the other taking a group and a
preset private key value. The DL private keys instead have on
constructor for this; if the x value is zero, then a new random key is
created. For consistency, do this with ECC as well.
ECDH actually didn't have one of these constructors, forcing you to
either load from PKCS #8 or else use a random key.
Rename EC_Domain_Params to EC_Group, with a typedef for compatability.
More doc updates.
Update mtn ignores for Sphinx output
Diffstat (limited to 'src/pubkey/ecc_key')
-rw-r--r-- | src/pubkey/ecc_key/ecc_key.cpp | 36 | ||||
-rw-r--r-- | src/pubkey/ecc_key/ecc_key.h | 26 | ||||
-rw-r--r-- | src/pubkey/ecc_key/info.txt | 2 |
3 files changed, 27 insertions, 37 deletions
diff --git a/src/pubkey/ecc_key/ecc_key.cpp b/src/pubkey/ecc_key/ecc_key.cpp index bd04e3197..991446f07 100644 --- a/src/pubkey/ecc_key/ecc_key.cpp +++ b/src/pubkey/ecc_key/ecc_key.cpp @@ -18,7 +18,7 @@ namespace Botan { -EC_PublicKey::EC_PublicKey(const EC_Domain_Params& dom_par, +EC_PublicKey::EC_PublicKey(const EC_Group& dom_par, const PointGFp& pub_point) : domain_params(dom_par), public_key(pub_point), domain_encoding(EC_DOMPAR_ENC_EXPLICIT) @@ -30,7 +30,7 @@ EC_PublicKey::EC_PublicKey(const EC_Domain_Params& dom_par, EC_PublicKey::EC_PublicKey(const AlgorithmIdentifier& alg_id, const MemoryRegion<byte>& key_bits) { - domain_params = EC_Domain_Params(alg_id.parameters); + domain_params = EC_Group(alg_id.parameters); domain_encoding = EC_DOMPAR_ENC_EXPLICIT; public_key = OS2ECP(key_bits, domain().get_curve()); @@ -52,7 +52,7 @@ MemoryVector<byte> EC_PublicKey::x509_subject_public_key() const return EC2OSP(public_point(), PointGFp::COMPRESSED); } -void EC_PublicKey::set_parameter_encoding(EC_Domain_Params_Encoding form) +void EC_PublicKey::set_parameter_encoding(EC_Group_Encoding form) { if(form != EC_DOMPAR_ENC_EXPLICIT && form != EC_DOMPAR_ENC_IMPLICITCA && @@ -76,32 +76,24 @@ const BigInt& EC_PrivateKey::private_value() const } /** -* EC_PrivateKey generator -*/ -EC_PrivateKey::EC_PrivateKey(const EC_Domain_Params& dom_par, - const BigInt& priv_key) - { - domain_params = dom_par; - domain_encoding = EC_DOMPAR_ENC_EXPLICIT; - - public_key = domain().get_base_point() * priv_key; - private_key = priv_key; - } - -/** -* EC_PrivateKey generator +* EC_PrivateKey constructor */ EC_PrivateKey::EC_PrivateKey(RandomNumberGenerator& rng, - const EC_Domain_Params& dom_par) + const EC_Group& ec_group, + const BigInt& x) { - domain_params = dom_par; + domain_params = ec_group; domain_encoding = EC_DOMPAR_ENC_EXPLICIT; - private_key = BigInt::random_integer(rng, 1, domain().get_order()); + if(x == 0) + private_key = BigInt::random_integer(rng, 1, domain().get_order()); + else + private_key = x; + public_key = domain().get_base_point() * private_key; BOTAN_ASSERT(public_key.on_the_curve(), - "generated ECC private key was not on the curve"); + "ECC private key was not on the curve"); } MemoryVector<byte> EC_PrivateKey::pkcs8_private_key() const @@ -118,7 +110,7 @@ MemoryVector<byte> EC_PrivateKey::pkcs8_private_key() const EC_PrivateKey::EC_PrivateKey(const AlgorithmIdentifier& alg_id, const MemoryRegion<byte>& key_bits) { - domain_params = EC_Domain_Params(alg_id.parameters); + domain_params = EC_Group(alg_id.parameters); domain_encoding = EC_DOMPAR_ENC_EXPLICIT; BER_Decoder(key_bits) diff --git a/src/pubkey/ecc_key/ecc_key.h b/src/pubkey/ecc_key/ecc_key.h index a20516ec6..cccc8d53c 100644 --- a/src/pubkey/ecc_key/ecc_key.h +++ b/src/pubkey/ecc_key/ecc_key.h @@ -10,7 +10,7 @@ #ifndef BOTAN_ECC_PUBLIC_KEY_BASE_H__ #define BOTAN_ECC_PUBLIC_KEY_BASE_H__ -#include <botan/ec_dompar.h> +#include <botan/ec_group.h> #include <botan/pk_keys.h> #include <botan/x509_key.h> #include <botan/pkcs8.h> @@ -18,7 +18,7 @@ namespace Botan { /** -* This class represents abstract EC Public Keys. When encoding a key +* This class represents abstract ECC public keys. When encoding a key * via an encoder that can be accessed via the corresponding member * functions, the key will decide upon its internally stored encoding * information whether to encode itself with or without domain @@ -30,7 +30,7 @@ namespace Botan { class BOTAN_DLL EC_PublicKey : public virtual Public_Key { public: - EC_PublicKey(const EC_Domain_Params& dom_par, + EC_PublicKey(const EC_Group& dom_par, const PointGFp& pub_point); EC_PublicKey(const AlgorithmIdentifier& alg_id, @@ -57,13 +57,13 @@ class BOTAN_DLL EC_PublicKey : public virtual Public_Key * domain parameters of this point are not set * @result the domain parameters of this key */ - const EC_Domain_Params& domain() const { return domain_params; } + const EC_Group& domain() const { return domain_params; } /** * Set the domain parameter encoding to be used when encoding this key. * @param enc the encoding to use */ - void set_parameter_encoding(EC_Domain_Params_Encoding enc); + void set_parameter_encoding(EC_Group_Encoding enc); /** * Return the DER encoding of this keys domain in whatever format @@ -76,28 +76,26 @@ class BOTAN_DLL EC_PublicKey : public virtual Public_Key * Get the domain parameter encoding to be used when encoding this key. * @result the encoding to use */ - EC_Domain_Params_Encoding domain_format() const + EC_Group_Encoding domain_format() const { return domain_encoding; } protected: EC_PublicKey() : domain_encoding(EC_DOMPAR_ENC_EXPLICIT) {} - EC_Domain_Params domain_params; + EC_Group domain_params; PointGFp public_key; - EC_Domain_Params_Encoding domain_encoding; + EC_Group_Encoding domain_encoding; }; /** -* This abstract class represents general EC Private Keys +* This abstract class represents ECC private keys */ class BOTAN_DLL EC_PrivateKey : public virtual EC_PublicKey, public virtual Private_Key { public: - EC_PrivateKey(const EC_Domain_Params& domain, - const BigInt& private_key); - - EC_PrivateKey(RandomNumberGenerator& rng, - const EC_Domain_Params& domain); + EC_PrivateKey(RandomNumberGenerator& rng, + const EC_Group& domain, + const BigInt& private_key); EC_PrivateKey(const AlgorithmIdentifier& alg_id, const MemoryRegion<byte>& key_bits); diff --git a/src/pubkey/ecc_key/info.txt b/src/pubkey/ecc_key/info.txt index e08a4231d..be281d697 100644 --- a/src/pubkey/ecc_key/info.txt +++ b/src/pubkey/ecc_key/info.txt @@ -4,6 +4,6 @@ define ECC_PUBLIC_KEY_CRYPTO alloc asn1 bigint -ec_dompar +ec_group numbertheory </requires> |