diff options
author | lloyd <[email protected]> | 2008-10-08 03:05:15 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-10-08 03:05:15 +0000 |
commit | 601001c6325dcdb229ea715abb3addfbe70201af (patch) | |
tree | 14ffa37c850c1c3e9cb135c072df752776062346 /src | |
parent | ebfb6a6e9150820aa7e783f97bd5e0ac302adfbe (diff) |
Fix problems with disabling ECDSA
Diffstat (limited to 'src')
-rw-r--r-- | src/core/libstate/engine.cpp | 2 | ||||
-rw-r--r-- | src/core/libstate/engine.h | 2 | ||||
-rw-r--r-- | src/pubkey/ecc_key/ecc_key.cpp | 56 | ||||
-rw-r--r-- | src/pubkey/ecdsa/ecdsa.cpp | 56 |
4 files changed, 60 insertions, 56 deletions
diff --git a/src/core/libstate/engine.cpp b/src/core/libstate/engine.cpp index 44c3ae5e5..ce32fa3b4 100644 --- a/src/core/libstate/engine.cpp +++ b/src/core/libstate/engine.cpp @@ -129,7 +129,9 @@ ECDSA_Operation* ecdsa_op(const EC_Domain_Params& dom_pars, throw Lookup_Error("Engine_Core::ecdsa_op: Unable to find a working engine"); } +#endif +#if defined(BOTAN_HAS_ECKAEG) /************************************************* * Acquire a ECKAEG op * *************************************************/ diff --git a/src/core/libstate/engine.h b/src/core/libstate/engine.h index d9b70011c..af0fb67e1 100644 --- a/src/core/libstate/engine.h +++ b/src/core/libstate/engine.h @@ -194,7 +194,9 @@ DH_Operation* dh_op(const DL_Group&, const BigInt&); ECDSA_Operation* ecdsa_op(const EC_Domain_Params& dom_pars, const BigInt& priv_key, const PointGFp& pub_key); +#endif +#if defined(BOTAN_HAS_ECKAEG) ECKAEG_Operation* eckaeg_op(const EC_Domain_Params& dom_pars, const BigInt& priv_key, const PointGFp& pub_key); diff --git a/src/pubkey/ecc_key/ecc_key.cpp b/src/pubkey/ecc_key/ecc_key.cpp index 78284b6ae..2307f0e03 100644 --- a/src/pubkey/ecc_key/ecc_key.cpp +++ b/src/pubkey/ecc_key/ecc_key.cpp @@ -139,6 +139,62 @@ void EC_PrivateKey::affirm_init() const // virtual } /** +* EC_PrivateKey generator +**/ +void EC_PrivateKey::generate_private_key(RandomNumberGenerator& rng) + { + if (mp_dom_pars.get() == 0) + { + throw Invalid_State("cannot generate private key when domain parameters are not set"); + } + BigInt tmp_private_value(0); + tmp_private_value = BigInt::random_integer(rng, 1, mp_dom_pars->get_order() ); + mp_public_point = std::auto_ptr<PointGFp>( new PointGFp (mp_dom_pars->get_base_point())); + mp_public_point->mult_this_secure(tmp_private_value, mp_dom_pars->get_order(), mp_dom_pars->get_order()-1); + + //assert(mp_public_point.get() != 0); + tmp_private_value.swap(m_private_value); + } + +/** +* Return the PKCS #8 public key encoder +**/ +PKCS8_Encoder* EC_PrivateKey::pkcs8_encoder() const + { + class EC_Key_Encoder : public PKCS8_Encoder + { + public: + AlgorithmIdentifier alg_id() const + { + key->affirm_init(); + SecureVector<byte> params = encode_der_ec_dompar ( * ( key->mp_dom_pars ), ENC_EXPLICIT ); + return AlgorithmIdentifier ( key->get_oid(), + params ); + } + + MemoryVector<byte> key_bits() const + { + key->affirm_init(); + SecureVector<byte> octstr_secret = BigInt::encode_1363 ( key->m_private_value, key->m_private_value.bytes() ); + + return DER_Encoder() + .start_cons ( SEQUENCE ) + .encode ( BigInt ( 1 ) ) + .encode ( octstr_secret, OCTET_STRING ) + .end_cons() + .get_contents(); + } + + EC_Key_Encoder ( const EC_PrivateKey* k ) : key ( k ) + {} + private: + const EC_PrivateKey* key; + }; + + return new EC_Key_Encoder(this); + } + +/** * Return the PKCS #8 public key decoder */ PKCS8_Decoder* EC_PrivateKey::pkcs8_decoder(RandomNumberGenerator&) diff --git a/src/pubkey/ecdsa/ecdsa.cpp b/src/pubkey/ecdsa/ecdsa.cpp index 5cc226203..b3a63c304 100644 --- a/src/pubkey/ecdsa/ecdsa.cpp +++ b/src/pubkey/ecdsa/ecdsa.cpp @@ -34,62 +34,6 @@ ECDSA_PrivateKey::ECDSA_PrivateKey(RandomNumberGenerator& rng, m_ecdsa_core = ECDSA_Core(*mp_dom_pars, m_private_value, *mp_public_point); } -/** -* EC_PrivateKey generator -**/ -void EC_PrivateKey::generate_private_key(RandomNumberGenerator& rng) - { - if (mp_dom_pars.get() == 0) - { - throw Invalid_State("cannot generate private key when domain parameters are not set"); - } - BigInt tmp_private_value(0); - tmp_private_value = BigInt::random_integer(rng, 1, mp_dom_pars->get_order() ); - mp_public_point = std::auto_ptr<PointGFp>( new PointGFp (mp_dom_pars->get_base_point())); - mp_public_point->mult_this_secure(tmp_private_value, mp_dom_pars->get_order(), mp_dom_pars->get_order()-1); - - //assert(mp_public_point.get() != 0); - tmp_private_value.swap(m_private_value); - } - -/** -* Return the PKCS #8 public key encoder -**/ -PKCS8_Encoder* EC_PrivateKey::pkcs8_encoder() const - { - class EC_Key_Encoder : public PKCS8_Encoder - { - public: - AlgorithmIdentifier alg_id() const - { - key->affirm_init(); - SecureVector<byte> params = encode_der_ec_dompar ( * ( key->mp_dom_pars ), ENC_EXPLICIT ); - return AlgorithmIdentifier ( key->get_oid(), - params ); - } - - MemoryVector<byte> key_bits() const - { - key->affirm_init(); - SecureVector<byte> octstr_secret = BigInt::encode_1363 ( key->m_private_value, key->m_private_value.bytes() ); - - return DER_Encoder() - .start_cons ( SEQUENCE ) - .encode ( BigInt ( 1 ) ) - .encode ( octstr_secret, OCTET_STRING ) - .end_cons() - .get_contents(); - } - - EC_Key_Encoder ( const EC_PrivateKey* k ) : key ( k ) - {} - private: - const EC_PrivateKey* key; - }; - - return new EC_Key_Encoder(this); - } - /************************************************* * ECDSA_PublicKey * *************************************************/ |