aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey/rsa
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-05 01:09:28 +0000
committerlloyd <[email protected]>2010-03-05 01:09:28 +0000
commit1c7dbb21d19702872379421e6ae44a15caf67da2 (patch)
treebd4ee9e01f8cfd9631655d0e0b0991d49c0a7e8e /src/pubkey/rsa
parent78b5b103291ee668185dc71d138a50e8e7e54808 (diff)
Add signature generation operation classes. Remove sign() from
PK_Signing_Key, though for the moment the class remains because there are a few pieces of code that use it to detect if signatures are supported, or for passing to functions in look_pk
Diffstat (limited to 'src/pubkey/rsa')
-rw-r--r--src/pubkey/rsa/rsa.cpp25
-rw-r--r--src/pubkey/rsa/rsa.h17
2 files changed, 42 insertions, 0 deletions
diff --git a/src/pubkey/rsa/rsa.cpp b/src/pubkey/rsa/rsa.cpp
index b181cb9cc..72a99b4f7 100644
--- a/src/pubkey/rsa/rsa.cpp
+++ b/src/pubkey/rsa/rsa.cpp
@@ -138,4 +138,29 @@ bool RSA_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const
return true;
}
+RSA_Signature_Operation::RSA_Signature_Operation(const RSA_PrivateKey& rsa) :
+ q(rsa.get_q()),
+ c(rsa.get_c()),
+ powermod_d1_p(rsa.get_d1(), rsa.get_p()),
+ powermod_d2_q(rsa.get_d2(), rsa.get_q()),
+ mod_p(rsa.get_p()),
+ n_bits(rsa.get_n().bits())
+ {
+ }
+
+SecureVector<byte> RSA_Signature_Operation::sign(const byte msg[],
+ u32bit msg_len,
+ RandomNumberGenerator& rng)
+ {
+ const u32bit n_bytes = (n_bits + 7) / 8;
+
+ BigInt i(msg, msg_len);
+ BigInt j1 = powermod_d1_p(i);
+ BigInt j2 = powermod_d2_q(i);
+
+ j1 = mod_p.reduce(sub_mul(j1, j2, c));
+
+ return BigInt::encode_1363(mul_add(j1, q, j2), n_bytes);
+ }
+
}
diff --git a/src/pubkey/rsa/rsa.h b/src/pubkey/rsa/rsa.h
index 0d5a4ad2e..aa2f8124f 100644
--- a/src/pubkey/rsa/rsa.h
+++ b/src/pubkey/rsa/rsa.h
@@ -101,6 +101,23 @@ class BOTAN_DLL RSA_PrivateKey : public RSA_PublicKey,
BigInt private_op(const byte[], u32bit) const;
};
+class BOTAN_DLL RSA_Signature_Operation : public PK_Ops::Signature_Operation
+ {
+ public:
+ RSA_Signature_Operation(const RSA_PrivateKey& rsa);
+
+ u32bit max_input_bits() const { return (n_bits - 1); }
+
+ SecureVector<byte> sign(const byte msg[], u32bit msg_len,
+ RandomNumberGenerator& rng);
+ private:
+ const BigInt& q;
+ const BigInt& c;
+ Fixed_Exponent_Power_Mod powermod_d1_p, powermod_d2_q;
+ Modular_Reducer mod_p;
+ u32bit n_bits;
+ };
+
}
#endif