aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-05 16:40:49 +0000
committerlloyd <[email protected]>2010-03-05 16:40:49 +0000
commit8df87a70435cae25e30f7045f7799537857e13d4 (patch)
treeea66d8941cf7c675dcac7e0944139f9b94eb8103 /src/pubkey
parentce88e2c6918bb012321e1d7599c2a13b9ba9301e (diff)
Constify sign and verify ops
Diffstat (limited to 'src/pubkey')
-rw-r--r--src/pubkey/dsa/dsa.cpp8
-rw-r--r--src/pubkey/dsa/dsa.h4
-rw-r--r--src/pubkey/ecdsa/ecdsa.cpp8
-rw-r--r--src/pubkey/ecdsa/ecdsa.h4
-rw-r--r--src/pubkey/gost_3410/gost_3410.cpp7
-rw-r--r--src/pubkey/gost_3410/gost_3410.h4
-rw-r--r--src/pubkey/nr/nr.cpp8
-rw-r--r--src/pubkey/nr/nr.h4
-rw-r--r--src/pubkey/pk_ops.h22
-rw-r--r--src/pubkey/rsa/rsa.cpp6
-rw-r--r--src/pubkey/rsa/rsa.h4
-rw-r--r--src/pubkey/rw/rw.cpp8
-rw-r--r--src/pubkey/rw/rw.h4
13 files changed, 50 insertions, 41 deletions
diff --git a/src/pubkey/dsa/dsa.cpp b/src/pubkey/dsa/dsa.cpp
index 60414195d..1fbc2abc1 100644
--- a/src/pubkey/dsa/dsa.cpp
+++ b/src/pubkey/dsa/dsa.cpp
@@ -86,9 +86,9 @@ DSA_Signature_Operation::DSA_Signature_Operation(const DSA_PrivateKey& dsa) :
{
}
-SecureVector<byte> DSA_Signature_Operation::sign(const byte msg[],
- u32bit msg_len,
- RandomNumberGenerator& rng)
+SecureVector<byte>
+DSA_Signature_Operation::sign(const byte msg[], u32bit msg_len,
+ RandomNumberGenerator& rng) const
{
rng.add_entropy(msg, msg_len);
@@ -121,7 +121,7 @@ DSA_Verification_Operation::DSA_Verification_Operation(const DSA_PublicKey& dsa)
}
bool DSA_Verification_Operation::verify(const byte msg[], u32bit msg_len,
- const byte sig[], u32bit sig_len)
+ const byte sig[], u32bit sig_len) const
{
const BigInt& q = mod_q.get_modulus();
diff --git a/src/pubkey/dsa/dsa.h b/src/pubkey/dsa/dsa.h
index 7745e08ff..290cb5740 100644
--- a/src/pubkey/dsa/dsa.h
+++ b/src/pubkey/dsa/dsa.h
@@ -69,7 +69,7 @@ class BOTAN_DLL DSA_Signature_Operation : public PK_Ops::Signature
u32bit max_input_bits() const { return q.bits(); }
SecureVector<byte> sign(const byte msg[], u32bit msg_len,
- RandomNumberGenerator& rng);
+ RandomNumberGenerator& rng) const;
private:
const BigInt& q;
const BigInt& x;
@@ -89,7 +89,7 @@ class BOTAN_DLL DSA_Verification_Operation : public PK_Ops::Verification
bool with_recovery() const { return false; }
bool verify(const byte msg[], u32bit msg_len,
- const byte sig[], u32bit sig_len);
+ const byte sig[], u32bit sig_len) const;
private:
const BigInt& q;
const BigInt& y;
diff --git a/src/pubkey/ecdsa/ecdsa.cpp b/src/pubkey/ecdsa/ecdsa.cpp
index fc2a75454..95dc99e67 100644
--- a/src/pubkey/ecdsa/ecdsa.cpp
+++ b/src/pubkey/ecdsa/ecdsa.cpp
@@ -18,9 +18,9 @@ ECDSA_Signature_Operation::ECDSA_Signature_Operation(const ECDSA_PrivateKey& ecd
{
}
-SecureVector<byte> ECDSA_Signature_Operation::sign(const byte msg[],
- u32bit msg_len,
- RandomNumberGenerator& rng)
+SecureVector<byte>
+ECDSA_Signature_Operation::sign(const byte msg[], u32bit msg_len,
+ RandomNumberGenerator& rng) const
{
rng.add_entropy(msg, msg_len);
@@ -56,7 +56,7 @@ ECDSA_Verification_Operation::ECDSA_Verification_Operation(const ECDSA_PublicKey
}
bool ECDSA_Verification_Operation::verify(const byte msg[], u32bit msg_len,
- const byte sig[], u32bit sig_len)
+ const byte sig[], u32bit sig_len) const
{
if(sig_len != order.bytes()*2)
return false;
diff --git a/src/pubkey/ecdsa/ecdsa.h b/src/pubkey/ecdsa/ecdsa.h
index 240c981e8..9e457a0a7 100644
--- a/src/pubkey/ecdsa/ecdsa.h
+++ b/src/pubkey/ecdsa/ecdsa.h
@@ -94,7 +94,7 @@ class BOTAN_DLL ECDSA_Signature_Operation : public PK_Ops::Signature
ECDSA_Signature_Operation(const ECDSA_PrivateKey& ecdsa);
SecureVector<byte> sign(const byte msg[], u32bit msg_len,
- RandomNumberGenerator& rng);
+ RandomNumberGenerator& rng) const;
u32bit message_parts() const { return 2; }
u32bit message_part_size() const { return order.bytes(); }
@@ -118,7 +118,7 @@ class BOTAN_DLL ECDSA_Verification_Operation : public PK_Ops::Verification
bool with_recovery() const { return false; }
bool verify(const byte msg[], u32bit msg_len,
- const byte sig[], u32bit sig_len);
+ const byte sig[], u32bit sig_len) const;
private:
const PointGFp& base_point;
const PointGFp& public_point;
diff --git a/src/pubkey/gost_3410/gost_3410.cpp b/src/pubkey/gost_3410/gost_3410.cpp
index 9a7681cb2..c5cc1ddbd 100644
--- a/src/pubkey/gost_3410/gost_3410.cpp
+++ b/src/pubkey/gost_3410/gost_3410.cpp
@@ -78,9 +78,8 @@ GOST_3410_Signature_Operation::GOST_3410_Signature_Operation(
}
SecureVector<byte>
-GOST_3410_Signature_Operation::sign(const byte msg[],
- u32bit msg_len,
- RandomNumberGenerator& rng)
+GOST_3410_Signature_Operation::sign(const byte msg[], u32bit msg_len,
+ RandomNumberGenerator& rng) const
{
BigInt k;
do
@@ -118,7 +117,7 @@ GOST_3410_Verification_Operation::GOST_3410_Verification_Operation(const GOST_34
}
bool GOST_3410_Verification_Operation::verify(const byte msg[], u32bit msg_len,
- const byte sig[], u32bit sig_len)
+ const byte sig[], u32bit sig_len) const
{
if(sig_len != order.bytes()*2)
return false;
diff --git a/src/pubkey/gost_3410/gost_3410.h b/src/pubkey/gost_3410/gost_3410.h
index b10421a02..d3309b8f1 100644
--- a/src/pubkey/gost_3410/gost_3410.h
+++ b/src/pubkey/gost_3410/gost_3410.h
@@ -108,7 +108,7 @@ class BOTAN_DLL GOST_3410_Signature_Operation : public PK_Ops::Signature
u32bit max_input_bits() const { return order.bits(); }
SecureVector<byte> sign(const byte msg[], u32bit msg_len,
- RandomNumberGenerator& rng);
+ RandomNumberGenerator& rng) const;
private:
const PointGFp& base_point;
@@ -128,7 +128,7 @@ class BOTAN_DLL GOST_3410_Verification_Operation : public PK_Ops::Verification
bool with_recovery() const { return false; }
bool verify(const byte msg[], u32bit msg_len,
- const byte sig[], u32bit sig_len);
+ const byte sig[], u32bit sig_len) const;
private:
const PointGFp& base_point;
const PointGFp& public_point;
diff --git a/src/pubkey/nr/nr.cpp b/src/pubkey/nr/nr.cpp
index 540cfa281..1fc8630d7 100644
--- a/src/pubkey/nr/nr.cpp
+++ b/src/pubkey/nr/nr.cpp
@@ -92,9 +92,9 @@ NR_Signature_Operation::NR_Signature_Operation(const NR_PrivateKey& nr) :
{
}
-SecureVector<byte> NR_Signature_Operation::sign(const byte msg[],
- u32bit msg_len,
- RandomNumberGenerator& rng)
+SecureVector<byte>
+NR_Signature_Operation::sign(const byte msg[], u32bit msg_len,
+ RandomNumberGenerator& rng) const
{
rng.add_entropy(msg, msg_len);
@@ -129,7 +129,7 @@ NR_Verification_Operation::NR_Verification_Operation(const NR_PublicKey& nr) :
}
SecureVector<byte>
-NR_Verification_Operation::verify_mr(const byte msg[], u32bit msg_len)
+NR_Verification_Operation::verify_mr(const byte msg[], u32bit msg_len) const
{
const BigInt& q = mod_q.get_modulus();
diff --git a/src/pubkey/nr/nr.h b/src/pubkey/nr/nr.h
index 3fe0efeb5..ba7cee8cc 100644
--- a/src/pubkey/nr/nr.h
+++ b/src/pubkey/nr/nr.h
@@ -67,7 +67,7 @@ class BOTAN_DLL NR_Signature_Operation : public PK_Ops::Signature
u32bit max_input_bits() const { return (q.bits() - 1); }
SecureVector<byte> sign(const byte msg[], u32bit msg_len,
- RandomNumberGenerator& rng);
+ RandomNumberGenerator& rng) const;
private:
const BigInt& q;
const BigInt& x;
@@ -86,7 +86,7 @@ class BOTAN_DLL NR_Verification_Operation : public PK_Ops::Verification
bool with_recovery() const { return true; }
- SecureVector<byte> verify_mr(const byte msg[], u32bit msg_len);
+ SecureVector<byte> verify_mr(const byte msg[], u32bit msg_len) const;
private:
const BigInt& q;
const BigInt& y;
diff --git a/src/pubkey/pk_ops.h b/src/pubkey/pk_ops.h
index cb488a1a0..c749bc8ea 100644
--- a/src/pubkey/pk_ops.h
+++ b/src/pubkey/pk_ops.h
@@ -15,7 +15,16 @@ namespace Botan {
namespace PK_Ops {
-class Signature
+class BOTAN_DLL Encryption
+ {
+ public:
+ virtual SecureVector<byte> encrypt(const byte msg[], u32bit msg_len,
+ RandomNumberGenerator& rng) const = 0;
+
+ virtual ~Encryption() {}
+ };
+
+class BOTAN_DLL Signature
{
public:
/**
@@ -42,9 +51,9 @@ class Signature
* @param msg_len the length of msg in bytes
* @param rng a random number generator
*/
- virtual SecureVector<byte> sign(const byte msg[],
- u32bit msg_len,
- RandomNumberGenerator& rng) = 0;
+ virtual SecureVector<byte>
+ sign(const byte msg[], u32bit msg_len,
+ RandomNumberGenerator& rng) const = 0;
virtual ~Signature() {}
};
@@ -85,7 +94,7 @@ class BOTAN_DLL Verification
* @returns if signature is a valid one for message
*/
virtual bool verify(const byte msg[], u32bit msg_len,
- const byte sig[], u32bit sig_len)
+ const byte sig[], u32bit sig_len) const
{
throw Invalid_State("Message recovery required");
}
@@ -97,7 +106,8 @@ class BOTAN_DLL Verification
* @param msg_len the length of msg in bytes
* @returns recovered message
*/
- virtual SecureVector<byte> verify_mr(const byte msg[], u32bit msg_len)
+ virtual SecureVector<byte> verify_mr(const byte msg[],
+ u32bit msg_len) const
{
throw Invalid_State("Message recovery not supported");
}
diff --git a/src/pubkey/rsa/rsa.cpp b/src/pubkey/rsa/rsa.cpp
index 76165090e..910fddb95 100644
--- a/src/pubkey/rsa/rsa.cpp
+++ b/src/pubkey/rsa/rsa.cpp
@@ -130,9 +130,9 @@ RSA_Signature_Operation::RSA_Signature_Operation(const RSA_PrivateKey& rsa) :
{
}
-SecureVector<byte> RSA_Signature_Operation::sign(const byte msg[],
- u32bit msg_len,
- RandomNumberGenerator&)
+SecureVector<byte>
+RSA_Signature_Operation::sign(const byte msg[], u32bit msg_len,
+ RandomNumberGenerator&) const
{
const u32bit n_bytes = (n_bits + 7) / 8;
diff --git a/src/pubkey/rsa/rsa.h b/src/pubkey/rsa/rsa.h
index c62616cdc..ed7fe9eca 100644
--- a/src/pubkey/rsa/rsa.h
+++ b/src/pubkey/rsa/rsa.h
@@ -104,7 +104,7 @@ class BOTAN_DLL RSA_Signature_Operation : public PK_Ops::Signature
u32bit max_input_bits() const { return (n_bits - 1); }
SecureVector<byte> sign(const byte msg[], u32bit msg_len,
- RandomNumberGenerator& rng);
+ RandomNumberGenerator& rng) const;
private:
const BigInt& q;
const BigInt& c;
@@ -124,7 +124,7 @@ class BOTAN_DLL RSA_Verification_Operation : public PK_Ops::Verification
u32bit max_input_bits() const { return (n_bits - 1); }
bool with_recovery() const { return true; }
- SecureVector<byte> verify_mr(const byte msg[], u32bit msg_len)
+ SecureVector<byte> verify_mr(const byte msg[], u32bit msg_len) const
{
return BigInt::encode(powermod_e_n(BigInt(msg, msg_len)));
}
diff --git a/src/pubkey/rw/rw.cpp b/src/pubkey/rw/rw.cpp
index a1df0649b..bf66898b2 100644
--- a/src/pubkey/rw/rw.cpp
+++ b/src/pubkey/rw/rw.cpp
@@ -84,9 +84,9 @@ RW_Signature_Operation::RW_Signature_Operation(const RW_PrivateKey& rw) :
{
}
-SecureVector<byte> RW_Signature_Operation::sign(const byte msg[],
- u32bit msg_len,
- RandomNumberGenerator&)
+SecureVector<byte>
+RW_Signature_Operation::sign(const byte msg[], u32bit msg_len,
+ RandomNumberGenerator&) const
{
BigInt i(msg, msg_len);
@@ -108,7 +108,7 @@ SecureVector<byte> RW_Signature_Operation::sign(const byte msg[],
}
SecureVector<byte>
-RW_Verification_Operation::verify_mr(const byte msg[], u32bit msg_len)
+RW_Verification_Operation::verify_mr(const byte msg[], u32bit msg_len) const
{
BigInt m(msg, msg_len);
diff --git a/src/pubkey/rw/rw.h b/src/pubkey/rw/rw.h
index 232051862..059ba7d48 100644
--- a/src/pubkey/rw/rw.h
+++ b/src/pubkey/rw/rw.h
@@ -70,7 +70,7 @@ class BOTAN_DLL RW_Signature_Operation : public PK_Ops::Signature
u32bit max_input_bits() const { return (n.bits() - 1); }
SecureVector<byte> sign(const byte msg[], u32bit msg_len,
- RandomNumberGenerator& rng);
+ RandomNumberGenerator& rng) const;
private:
const BigInt& q;
const BigInt& c;
@@ -90,7 +90,7 @@ class BOTAN_DLL RW_Verification_Operation : public PK_Ops::Verification
u32bit max_input_bits() const { return (n.bits() - 1); }
bool with_recovery() const { return true; }
- SecureVector<byte> verify_mr(const byte msg[], u32bit msg_len);
+ SecureVector<byte> verify_mr(const byte msg[], u32bit msg_len) const;
private:
const BigInt& n;