aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-02 13:37:11 +0000
committerlloyd <[email protected]>2010-03-02 13:37:11 +0000
commitd723232f03eb5073bdf245e0502434ebadbee1cd (patch)
treedee5bbea429c8a809594bc954a6efd2967f7ca5a /src/pubkey
parent44fa6060faac4ae69ad43620f48e5890f3e99384 (diff)
Small cleanups
Diffstat (limited to 'src/pubkey')
-rw-r--r--src/pubkey/ecc_key/ecc_key.cpp2
-rw-r--r--src/pubkey/ecc_key/ecc_key.h7
-rw-r--r--src/pubkey/gost_3410/gost_3410.cpp32
-rw-r--r--src/pubkey/gost_3410/gost_3410.h3
4 files changed, 21 insertions, 23 deletions
diff --git a/src/pubkey/ecc_key/ecc_key.cpp b/src/pubkey/ecc_key/ecc_key.cpp
index 10968fa7e..e1559fc92 100644
--- a/src/pubkey/ecc_key/ecc_key.cpp
+++ b/src/pubkey/ecc_key/ecc_key.cpp
@@ -55,7 +55,7 @@ X509_Encoder* EC_PublicKey::x509_encoder() const
AlgorithmIdentifier alg_id() const
{
return AlgorithmIdentifier(key->get_oid(),
- key->domain().DER_encode(key->domain_format()));
+ key->DER_domain());
}
MemoryVector<byte> key_bits() const
diff --git a/src/pubkey/ecc_key/ecc_key.h b/src/pubkey/ecc_key/ecc_key.h
index 653f97cab..1c41e5a1b 100644
--- a/src/pubkey/ecc_key/ecc_key.h
+++ b/src/pubkey/ecc_key/ecc_key.h
@@ -55,6 +55,13 @@ class BOTAN_DLL EC_PublicKey : public virtual Public_Key
void set_parameter_encoding(EC_Domain_Params_Encoding enc);
/**
+ * Return the DER encoding of this keys domain in whatever format
+ * is preset for this particular key
+ */
+ MemoryVector<byte> DER_domain() const
+ { return domain().DER_encode(domain_format()); }
+
+ /**
* Get the domain parameter encoding to be used when encoding this key.
* @result the encoding to use
*/
diff --git a/src/pubkey/gost_3410/gost_3410.cpp b/src/pubkey/gost_3410/gost_3410.cpp
index 8dd72dfc1..d23229d9b 100644
--- a/src/pubkey/gost_3410/gost_3410.cpp
+++ b/src/pubkey/gost_3410/gost_3410.cpp
@@ -24,7 +24,7 @@ X509_Encoder* GOST_3410_PublicKey::x509_encoder() const
AlgorithmIdentifier alg_id() const
{
return AlgorithmIdentifier(key->get_oid(),
- key->domain().DER_encode(key->domain_format()));
+ key->DER_domain());
}
MemoryVector<byte> key_bits() const
@@ -67,7 +67,6 @@ X509_Decoder* GOST_3410_PublicKey::x509_decoder()
void key_bits(const MemoryRegion<byte>& bits)
{
-
SecureVector<byte> key_bits;
BER_Decoder ber(bits);
ber.decode(key_bits, OCTET_STRING);
@@ -97,13 +96,12 @@ bool GOST_3410_PublicKey::verify(const byte msg[], u32bit msg_len,
{
const BigInt& n = domain().get_order();
+ if(n == 0)
+ throw Invalid_State("domain parameters not set");
+
if(sig_len != n.bytes()*2)
return false;
- // NOTE: it is not checked whether the public point is set
- if(domain().get_curve().get_p() == 0)
- throw Internal_Error("domain parameters not set");
-
BigInt e(msg, msg_len);
BigInt r(sig, sig_len / 2);
@@ -126,32 +124,24 @@ bool GOST_3410_PublicKey::verify(const byte msg[], u32bit msg_len,
return (R.get_affine_x() == r);
}
-GOST_3410_PublicKey::GOST_3410_PublicKey(const EC_Domain_Params& dom_par,
- const PointGFp& pub_point)
- {
- domain_params = dom_par;
- public_key = pub_point;
- domain_encoding = EC_DOMPAR_ENC_EXPLICIT;
- }
-
SecureVector<byte>
GOST_3410_PrivateKey::sign(const byte msg[],
u32bit msg_len,
RandomNumberGenerator& rng) const
{
+ if(private_value() == 0)
+ throw Invalid_State("GOST_3410::sign(): no private key");
+
const BigInt& n = domain().get_order();
+ if(n == 0)
+ throw Invalid_State("GOST_3410::sign(): domain parameters not set");
+
BigInt k;
do
k.randomize(rng, n.bits()-1);
while(k >= n);
- if(private_value() == 0)
- throw Internal_Error("GOST_3410::sign(): no private key");
-
- if(n == 0)
- throw Internal_Error("GOST_3410::sign(): domain parameters not set");
-
BigInt e(msg, msg_len);
e %= n;
@@ -164,7 +154,7 @@ GOST_3410_PrivateKey::sign(const byte msg[],
BigInt r = k_times_P.get_affine_x() % n;
if(r == 0)
- throw Internal_Error("GOST_3410::sign: r was zero");
+ throw Invalid_State("GOST_3410::sign: r was zero");
BigInt s = (r*private_value() + k*e) % n;
diff --git a/src/pubkey/gost_3410/gost_3410.h b/src/pubkey/gost_3410/gost_3410.h
index 8104cbb75..6daa0eaf8 100644
--- a/src/pubkey/gost_3410/gost_3410.h
+++ b/src/pubkey/gost_3410/gost_3410.h
@@ -63,7 +63,8 @@ class BOTAN_DLL GOST_3410_PublicKey : public virtual EC_PublicKey,
* @param public_point the public point defining this key
*/
GOST_3410_PublicKey(const EC_Domain_Params& dom_par,
- const PointGFp& public_point);
+ const PointGFp& public_point) :
+ EC_PublicKey(dom_par, public_point) {}
/**
* Get an x509_encoder that can be used to encode this key.