aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-05 06:47:02 +0000
committerlloyd <[email protected]>2010-03-05 06:47:02 +0000
commit1b68d7e53c4bc5e6b2938194b0f7eda78a72ce43 (patch)
treeda1b0482d875a48fe95e133346aee4baabcbf7cb /src/pubkey
parentd4ef447dc8b3b4f40f2ab250b1c364e2f74ccfa4 (diff)
Remove the sign() operation from the public key objects, totally replaced
by using the ops. Add real ECDSA test vectors (two found in ANSI X9.62)
Diffstat (limited to 'src/pubkey')
-rw-r--r--src/pubkey/dsa/dsa.cpp18
-rw-r--r--src/pubkey/dsa/dsa.h3
-rw-r--r--src/pubkey/ecc_key/ecc_key.cpp11
-rw-r--r--src/pubkey/ecc_key/ecc_key.h1
-rw-r--r--src/pubkey/ecdsa/ecdsa.cpp41
-rw-r--r--src/pubkey/ecdsa/ecdsa.h10
-rw-r--r--src/pubkey/gost_3410/gost_3410.cpp40
-rw-r--r--src/pubkey/gost_3410/gost_3410.h9
-rw-r--r--src/pubkey/nr/nr.cpp18
-rw-r--r--src/pubkey/nr/nr.h5
-rw-r--r--src/pubkey/pk_ops.h25
-rw-r--r--src/pubkey/rsa/rsa.cpp11
-rw-r--r--src/pubkey/rsa/rsa.h3
13 files changed, 40 insertions, 155 deletions
diff --git a/src/pubkey/dsa/dsa.cpp b/src/pubkey/dsa/dsa.cpp
index 403243a97..628841fba 100644
--- a/src/pubkey/dsa/dsa.cpp
+++ b/src/pubkey/dsa/dsa.cpp
@@ -66,24 +66,6 @@ DSA_PrivateKey::DSA_PrivateKey(const AlgorithmIdentifier& alg_id,
}
/*
-* DSA Signature Operation
-*/
-SecureVector<byte> DSA_PrivateKey::sign(const byte in[], u32bit length,
- RandomNumberGenerator& rng) const
- {
- const BigInt& q = group_q();
-
- rng.add_entropy(in, length);
-
- BigInt k;
- do
- k.randomize(rng, q.bits());
- while(k >= q);
-
- return core.sign(in, length, k);
- }
-
-/*
* Check Private DSA Parameters
*/
bool DSA_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const
diff --git a/src/pubkey/dsa/dsa.h b/src/pubkey/dsa/dsa.h
index 444b3a825..e0aab1b52 100644
--- a/src/pubkey/dsa/dsa.h
+++ b/src/pubkey/dsa/dsa.h
@@ -63,9 +63,6 @@ class BOTAN_DLL DSA_PrivateKey : public DSA_PublicKey,
const BigInt& private_key = 0);
bool check_key(RandomNumberGenerator& rng, bool strong) const;
-
- SecureVector<byte> sign(const byte hash[], u32bit hash_len,
- RandomNumberGenerator& rng) const;
};
class BOTAN_DLL DSA_Signature_Operation : public PK_Ops::Signature_Operation
diff --git a/src/pubkey/ecc_key/ecc_key.cpp b/src/pubkey/ecc_key/ecc_key.cpp
index f1ece3ebd..5ad0fbddd 100644
--- a/src/pubkey/ecc_key/ecc_key.cpp
+++ b/src/pubkey/ecc_key/ecc_key.cpp
@@ -87,17 +87,18 @@ const BigInt& EC_PrivateKey::private_value() const
/**
* EC_PrivateKey generator
-**/
+*/
EC_PrivateKey::EC_PrivateKey(const EC_Domain_Params& dom_par,
- const BigInt& priv_key) :
- EC_PublicKey(dom_par, dom_par.get_base_point() * private_key),
- private_key(priv_key)
+ const BigInt& priv_key)
{
+ domain_params = dom_par;
+ public_key = domain().get_base_point() * priv_key;
+ private_key = priv_key;
}
/**
* EC_PrivateKey generator
-**/
+*/
EC_PrivateKey::EC_PrivateKey(RandomNumberGenerator& rng,
const EC_Domain_Params& dom_par)
{
diff --git a/src/pubkey/ecc_key/ecc_key.h b/src/pubkey/ecc_key/ecc_key.h
index fcbc4b679..92f02613c 100644
--- a/src/pubkey/ecc_key/ecc_key.h
+++ b/src/pubkey/ecc_key/ecc_key.h
@@ -31,7 +31,6 @@ namespace Botan {
class BOTAN_DLL EC_PublicKey : public virtual Public_Key
{
public:
-
EC_PublicKey(const EC_Domain_Params& dom_par,
const PointGFp& pub_point);
diff --git a/src/pubkey/ecdsa/ecdsa.cpp b/src/pubkey/ecdsa/ecdsa.cpp
index 6ca3fb9b1..ba8c20571 100644
--- a/src/pubkey/ecdsa/ecdsa.cpp
+++ b/src/pubkey/ecdsa/ecdsa.cpp
@@ -9,6 +9,8 @@
#include <botan/ecdsa.h>
+#include <iostream>
+
namespace Botan {
bool ECDSA_PublicKey::verify(const byte msg[], u32bit msg_len,
@@ -39,38 +41,6 @@ bool ECDSA_PublicKey::verify(const byte msg[], u32bit msg_len,
return (R.get_affine_x() % n == r);
}
-SecureVector<byte> ECDSA_PrivateKey::sign(const byte msg[],
- u32bit msg_len,
- RandomNumberGenerator& rng) const
- {
- const BigInt& n = domain().get_order();
-
- if(n == 0 || private_value() == 0)
- throw Invalid_State("ECDSA_PrivateKey::sign: Not initialized");
-
- BigInt k;
- do
- k.randomize(rng, n.bits()-1);
- while(k >= n);
-
- BigInt e(msg, msg_len);
-
- PointGFp k_times_P = domain().get_base_point() * k;
- BigInt r = k_times_P.get_affine_x() % n;
-
- if(r == 0)
- throw Internal_Error("Default_ECDSA_Op::sign: r was zero");
-
- BigInt k_inv = inverse_mod(k, n);
-
- BigInt s = (((r * private_value()) + e) * k_inv) % n;
-
- SecureVector<byte> output(2*n.bytes());
- r.binary_encode(output + (output.size() / 2 - r.bytes()));
- s.binary_encode(output + (output.size() - s.bytes()));
- return output;
- }
-
ECDSA_Signature_Operation::ECDSA_Signature_Operation(const ECDSA_PrivateKey& ecdsa) :
base_point(ecdsa.domain().get_base_point()),
order(ecdsa.domain().get_order()),
@@ -85,9 +55,10 @@ SecureVector<byte> ECDSA_Signature_Operation::sign(const byte msg[],
rng.add_entropy(msg, msg_len);
BigInt k;
- do
- k.randomize(rng, order.bits()-1);
- while(k >= order);
+ k.randomize(rng, order.bits());
+
+ while(k >= order)
+ k.randomize(rng, order.bits() - 1);
BigInt e(msg, msg_len);
diff --git a/src/pubkey/ecdsa/ecdsa.h b/src/pubkey/ecdsa/ecdsa.h
index a54b28b46..75a7b152a 100644
--- a/src/pubkey/ecdsa/ecdsa.h
+++ b/src/pubkey/ecdsa/ecdsa.h
@@ -96,16 +96,6 @@ class BOTAN_DLL ECDSA_PrivateKey : public ECDSA_PublicKey,
*/
ECDSA_PrivateKey(const EC_Domain_Params& domain, const BigInt& x) :
EC_PrivateKey(domain, x) {}
-
- /**
- * Sign a message with this key.
- * @param message the byte array representing the message to be signed
- * @param mess_len the length of the message byte array
- * @result the signature
- */
-
- SecureVector<byte> sign(const byte message[], u32bit mess_len,
- RandomNumberGenerator& rng) const;
};
class BOTAN_DLL ECDSA_Signature_Operation : public PK_Ops::Signature_Operation
diff --git a/src/pubkey/gost_3410/gost_3410.cpp b/src/pubkey/gost_3410/gost_3410.cpp
index ef0bac726..c3735c720 100644
--- a/src/pubkey/gost_3410/gost_3410.cpp
+++ b/src/pubkey/gost_3410/gost_3410.cpp
@@ -101,46 +101,6 @@ bool GOST_3410_PublicKey::verify(const byte msg[], u32bit msg_len,
return (R.get_affine_x() == r);
}
-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);
-
- BigInt e(msg, msg_len);
-
- e %= n;
- if(e == 0)
- e = 1;
-
- PointGFp k_times_P = domain().get_base_point() * k;
- k_times_P.check_invariants();
-
- BigInt r = k_times_P.get_affine_x() % n;
-
- if(r == 0)
- throw Invalid_State("GOST_3410::sign: r was zero");
-
- BigInt s = (r*private_value() + k*e) % n;
-
- SecureVector<byte> output(2*n.bytes());
- r.binary_encode(output + (output.size() / 2 - r.bytes()));
- s.binary_encode(output + (output.size() - s.bytes()));
- return output;
- }
-
GOST_3410_Signature_Operation::GOST_3410_Signature_Operation(
const GOST_3410_PrivateKey& gost_3410) :
diff --git a/src/pubkey/gost_3410/gost_3410.h b/src/pubkey/gost_3410/gost_3410.h
index 1bf55aa21..12abd6354 100644
--- a/src/pubkey/gost_3410/gost_3410.h
+++ b/src/pubkey/gost_3410/gost_3410.h
@@ -106,15 +106,6 @@ class BOTAN_DLL GOST_3410_PrivateKey : public GOST_3410_PublicKey,
AlgorithmIdentifier pkcs8_algorithm_identifier() const
{ return EC_PublicKey::algorithm_identifier(); }
-
- /**
- * Sign a message with this key.
- * @param message the byte array representing the message to be signed
- * @param mess_len the length of the message byte array
- * @result the signature
- */
- SecureVector<byte> sign(const byte message[], u32bit mess_len,
- RandomNumberGenerator& rng) const;
};
class BOTAN_DLL GOST_3410_Signature_Operation : public PK_Ops::Signature_Operation
diff --git a/src/pubkey/nr/nr.cpp b/src/pubkey/nr/nr.cpp
index 08ed6b376..df483499b 100644
--- a/src/pubkey/nr/nr.cpp
+++ b/src/pubkey/nr/nr.cpp
@@ -74,22 +74,6 @@ NR_PrivateKey::NR_PrivateKey(const AlgorithmIdentifier& alg_id,
}
/*
-* Nyberg-Rueppel Signature Operation
-*/
-SecureVector<byte> NR_PrivateKey::sign(const byte in[], u32bit length,
- RandomNumberGenerator& rng) const
- {
- const BigInt& q = group_q();
-
- BigInt k;
- do
- k.randomize(rng, q.bits());
- while(k >= q);
-
- return core.sign(in, length, k);
- }
-
-/*
* Check Private Nyberg-Rueppel Parameters
*/
bool NR_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const
@@ -141,7 +125,7 @@ SecureVector<byte> NR_Signature_Operation::sign(const byte msg[],
BigInt c = mod_q.reduce(powermod_g_p(k) + f);
if(c.is_zero())
- throw Internal_Error("Default_NR_Op::sign: c was zero");
+ throw Internal_Error("NR_Signature_Operation: c was zero");
BigInt d = mod_q.reduce(k - x * c);
SecureVector<byte> output(2*q.bytes());
diff --git a/src/pubkey/nr/nr.h b/src/pubkey/nr/nr.h
index 013f3d42b..5fc7b2914 100644
--- a/src/pubkey/nr/nr.h
+++ b/src/pubkey/nr/nr.h
@@ -1,6 +1,6 @@
/*
* Nyberg-Rueppel
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2010 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -48,9 +48,6 @@ class BOTAN_DLL NR_PrivateKey : public NR_PublicKey,
public virtual DL_Scheme_PrivateKey
{
public:
- SecureVector<byte> sign(const byte msg[], u32bit msg_len,
- RandomNumberGenerator& rng) const;
-
bool check_key(RandomNumberGenerator& rng, bool strong) const;
NR_PrivateKey(const AlgorithmIdentifier& alg_id,
diff --git a/src/pubkey/pk_ops.h b/src/pubkey/pk_ops.h
index 5aa50efdb..2386b968a 100644
--- a/src/pubkey/pk_ops.h
+++ b/src/pubkey/pk_ops.h
@@ -49,6 +49,31 @@ class Signature_Operation
virtual ~Signature_Operation() {}
};
+class Verification_Operation
+ {
+ public:
+ /**
+ * Get the maximum message size in bits supported by this public key.
+ * @return the maximum message in bits
+ */
+ virtual u32bit max_input_bits() const = 0;
+
+ /**
+ * @return boolean specifying if this key type supports recovery
+ */
+ virtual bool with_recovery() const = 0;
+
+ /*
+ * Perform a signature operation
+ * @param msg the message
+ * @param msg_len the length of msg in bytes
+ * @returns recovered message if with_recovery() otherwise {0} or {1}
+ */
+ virtual SecureVector<byte> verify(const byte msg[], u32bit msg_len);
+
+ virtual ~Verification_Operation() {}
+ };
+
/*
* A generic Key Agreement Operation (eg DH or ECDH)
*/
diff --git a/src/pubkey/rsa/rsa.cpp b/src/pubkey/rsa/rsa.cpp
index 72a99b4f7..f21459f7b 100644
--- a/src/pubkey/rsa/rsa.cpp
+++ b/src/pubkey/rsa/rsa.cpp
@@ -96,15 +96,6 @@ SecureVector<byte> RSA_PrivateKey::decrypt(const byte in[], u32bit len) const
}
/*
-* RSA Signature Operation
-*/
-SecureVector<byte> RSA_PrivateKey::sign(const byte in[], u32bit len,
- RandomNumberGenerator&) const
- {
- return BigInt::encode_1363(private_op(in, len), n.bytes());
- }
-
-/*
* Check Private RSA Parameters
*/
bool RSA_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const
@@ -150,7 +141,7 @@ RSA_Signature_Operation::RSA_Signature_Operation(const RSA_PrivateKey& rsa) :
SecureVector<byte> RSA_Signature_Operation::sign(const byte msg[],
u32bit msg_len,
- RandomNumberGenerator& rng)
+ RandomNumberGenerator&)
{
const u32bit n_bytes = (n_bits + 7) / 8;
diff --git a/src/pubkey/rsa/rsa.h b/src/pubkey/rsa/rsa.h
index aa2f8124f..989cfd038 100644
--- a/src/pubkey/rsa/rsa.h
+++ b/src/pubkey/rsa/rsa.h
@@ -59,9 +59,6 @@ class BOTAN_DLL RSA_PrivateKey : public RSA_PublicKey,
public IF_Scheme_PrivateKey
{
public:
- SecureVector<byte> sign(const byte[], u32bit,
- RandomNumberGenerator&) const;
-
SecureVector<byte> decrypt(const byte[], u32bit) const;
bool check_key(RandomNumberGenerator& rng, bool) const;