diff options
author | lloyd <[email protected]> | 2010-03-05 17:35:10 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-05 17:35:10 +0000 |
commit | cdd1a1509ffc74c74bd902d55a7a85ab9e2afe78 (patch) | |
tree | 05f78baed62d78da63d5da4331d80d1909440702 /src/pubkey/rsa/rsa.h | |
parent | df8c46ffb5554d8804287b340e06f79fbafe8d1d (diff) |
Add RSA encrypt/decrypt ops
Diffstat (limited to 'src/pubkey/rsa/rsa.h')
-rw-r--r-- | src/pubkey/rsa/rsa.h | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/src/pubkey/rsa/rsa.h b/src/pubkey/rsa/rsa.h index ed7fe9eca..794352dce 100644 --- a/src/pubkey/rsa/rsa.h +++ b/src/pubkey/rsa/rsa.h @@ -96,16 +96,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 +class BOTAN_DLL RSA_Private_Operation : public PK_Ops::Signature, + public PK_Ops::Decryption { public: - RSA_Signature_Operation(const RSA_PrivateKey& rsa); + RSA_Private_Operation(const RSA_PrivateKey& rsa); - u32bit max_input_bits() const { return (n_bits - 1); } + u32bit max_input_bits() const { return (n.bits() - 1); } SecureVector<byte> sign(const byte msg[], u32bit msg_len, RandomNumberGenerator& rng) const; + + SecureVector<byte> decrypt(const byte msg[], u32bit msg_len) const; + private: + BigInt private_op(const BigInt& m) const; + + const BigInt& n; const BigInt& q; const BigInt& c; Fixed_Exponent_Power_Mod powermod_d1_p, powermod_d2_q; @@ -113,25 +120,40 @@ class BOTAN_DLL RSA_Signature_Operation : public PK_Ops::Signature u32bit n_bits; }; -class BOTAN_DLL RSA_Verification_Operation : public PK_Ops::Verification +class BOTAN_DLL RSA_Public_Operation : public PK_Ops::Verification, + public PK_Ops::Encryption { public: - RSA_Verification_Operation(const RSA_PublicKey& rsa) : - powermod_e_n(rsa.get_e(), rsa.get_n()), - n_bits(rsa.get_n().bits()) + RSA_Public_Operation(const RSA_PublicKey& rsa) : + n(rsa.get_n()), powermod_e_n(rsa.get_e(), rsa.get_n()) {} - u32bit max_input_bits() const { return (n_bits - 1); } + u32bit max_input_bits() const { return (n.bits() - 1); } bool with_recovery() const { return true; } + SecureVector<byte> encrypt(const byte msg[], u32bit msg_len, + RandomNumberGenerator&) const + { + BigInt m(msg, msg_len); + return BigInt::encode_1363(public_op(m), n.bytes()); + } + SecureVector<byte> verify_mr(const byte msg[], u32bit msg_len) const { - return BigInt::encode(powermod_e_n(BigInt(msg, msg_len))); + BigInt m(msg, msg_len); + return BigInt::encode(public_op(m)); } private: + BigInt public_op(const BigInt& m) const + { + if(m >= n) + throw Invalid_Argument("RSA public op - input is too large"); + return powermod_e_n(m); + } + + const BigInt& n; Fixed_Exponent_Power_Mod powermod_e_n; - u32bit n_bits; }; } |