aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey/ecc_key
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-19 18:21:34 +0000
committerlloyd <[email protected]>2010-03-19 18:21:34 +0000
commit602fb0e763cfaa2caa62b3b239d021efc767d567 (patch)
tree062a11e60698bdad68ef28b21e34f964cbd41cc7 /src/pubkey/ecc_key
parentdab16b79c89e54e9551d30dcf54ca89432932dce (diff)
Replace PointGFp::check_invaraints, which would either return silently
or throw an exception, with PointGFp::on_the_curve, which returns a bool. Update callers. This showed several cases where check_invaraints was being called multiple times, for instance when decoding a point with OS2ECP, check_invaraints was called; many callers of OS2ECP would then call check_invaraints again on the same object.
Diffstat (limited to 'src/pubkey/ecc_key')
-rw-r--r--src/pubkey/ecc_key/ecc_key.cpp37
1 files changed, 5 insertions, 32 deletions
diff --git a/src/pubkey/ecc_key/ecc_key.cpp b/src/pubkey/ecc_key/ecc_key.cpp
index fdb29b29f..2c66dc97f 100644
--- a/src/pubkey/ecc_key/ecc_key.cpp
+++ b/src/pubkey/ecc_key/ecc_key.cpp
@@ -25,14 +25,8 @@ EC_PublicKey::EC_PublicKey(const EC_Domain_Params& dom_par,
if(domain().get_curve() != public_point().get_curve())
throw Invalid_Argument("EC_PublicKey: curve mismatch in constructor");
- try
- {
- public_key.check_invariants();
- }
- catch(Illegal_Point)
- {
- throw Invalid_State("Public key failed invariant check");
- }
+ if(!public_point().on_the_curve())
+ throw Invalid_State("Public key was not on the curve");
}
EC_PublicKey::EC_PublicKey(const AlgorithmIdentifier& alg_id,
@@ -41,16 +35,7 @@ EC_PublicKey::EC_PublicKey(const AlgorithmIdentifier& alg_id,
domain_params = EC_Domain_Params(alg_id.parameters);
domain_encoding = EC_DOMPAR_ENC_EXPLICIT;
- public_key = PointGFp(OS2ECP(key_bits, domain().get_curve()));
-
- try
- {
- public_point().check_invariants();
- }
- catch(Illegal_Point)
- {
- throw Decoding_Error("Invalid public point; not on curve");
- }
+ public_key = OS2ECP(key_bits, domain().get_curve());
}
AlgorithmIdentifier EC_PublicKey::algorithm_identifier() const
@@ -111,14 +96,8 @@ EC_PrivateKey::EC_PrivateKey(RandomNumberGenerator& rng,
private_key = BigInt::random_integer(rng, 1, domain().get_order());
public_key = domain().get_base_point() * private_key;
- try
- {
- public_key.check_invariants();
- }
- catch(Illegal_Point)
- {
+ if(!public_key.on_the_curve())
throw Internal_Error("ECC private key generation failed");
- }
}
MemoryVector<byte> EC_PrivateKey::pkcs8_private_key() const
@@ -147,14 +126,8 @@ EC_PrivateKey::EC_PrivateKey(const AlgorithmIdentifier& alg_id,
public_key = domain().get_base_point() * private_key;
- try
- {
- public_key.check_invariants();
- }
- catch(Illegal_Point)
- {
+ if(!public_key.on_the_curve())
throw Internal_Error("Loaded ECC private key failed self test");
- }
}
}