Botan  1.11.11
Public Member Functions | List of all members
Botan::RSA_Private_Operation Class Reference

#include <rsa.h>

Inheritance diagram for Botan::RSA_Private_Operation:
Botan::PK_Ops::Signature Botan::PK_Ops::Decryption

Public Member Functions

secure_vector< bytedecrypt (const byte msg[], size_t msg_len)
 
size_t max_input_bits () const
 
virtual size_t message_part_size () const
 
virtual size_t message_parts () const
 
 RSA_Private_Operation (const RSA_PrivateKey &rsa, RandomNumberGenerator &rng)
 
secure_vector< bytesign (const byte msg[], size_t msg_len, RandomNumberGenerator &rng)
 

Detailed Description

RSA private (decrypt/sign) operation

Definition at line 89 of file rsa.h.

Constructor & Destructor Documentation

Botan::RSA_Private_Operation::RSA_Private_Operation ( const RSA_PrivateKey rsa,
RandomNumberGenerator rng 
)

Definition at line 62 of file rsa.cpp.

References Botan::BigInt::bits(), and Botan::inverse_mod().

63  :
64  n(rsa.get_n()),
65  q(rsa.get_q()),
66  c(rsa.get_c()),
67  powermod_e_n(rsa.get_e(), rsa.get_n()),
68  powermod_d1_p(rsa.get_d1(), rsa.get_p()),
69  powermod_d2_q(rsa.get_d2(), rsa.get_q()),
70  mod_p(rsa.get_p())
71  {
72  BigInt k(rng, n.bits() - 1);
73  blinder = Blinder(powermod_e_n(k), inverse_mod(k, n), n);
74  }
size_t bits() const
Definition: bigint.cpp:233
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition: numthry.cpp:128

Member Function Documentation

secure_vector< byte > Botan::RSA_Private_Operation::decrypt ( const byte  msg[],
size_t  msg_len 
)
virtual

Implements Botan::PK_Ops::Decryption.

Definition at line 110 of file rsa.cpp.

References Botan::Blinder::blind(), BOTAN_ASSERT, Botan::BigInt::encode_locked(), and Botan::Blinder::unblind().

111  {
112  const BigInt m(msg, msg_len);
113  const BigInt x = blinder.unblind(private_op(blinder.blind(m)));
114 
115  BOTAN_ASSERT(m == powermod_e_n(x),
116  "RSA decrypt passed consistency check");
117 
118  return BigInt::encode_locked(x);
119  }
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:27
BigInt unblind(const BigInt &x) const
Definition: blinding.cpp:42
BigInt blind(const BigInt &x) const
Definition: blinding.cpp:29
static secure_vector< byte > encode_locked(const BigInt &n, Base base=Binary)
Definition: big_code.cpp:68
size_t Botan::RSA_Private_Operation::max_input_bits ( ) const
inlinevirtual

Implements Botan::PK_Ops::Decryption.

Definition at line 96 of file rsa.h.

96 { return (n.bits() - 1); }
size_t bits() const
Definition: bigint.cpp:233
virtual size_t Botan::PK_Ops::Signature::message_part_size ( ) const
inlinevirtualinherited

Find out the message part size supported by this scheme/key.

Returns
size of the message parts

Reimplemented in Botan::ECDSA_Signature_Operation, Botan::GOST_3410_Signature_Operation, Botan::DSA_Signature_Operation, and Botan::NR_Signature_Operation.

Definition at line 62 of file pk_ops.h.

62 { return 0; }
virtual size_t Botan::PK_Ops::Signature::message_parts ( ) const
inlinevirtualinherited

Find out the number of message parts supported by this scheme.

Returns
number of message parts

Reimplemented in Botan::ECDSA_Signature_Operation, Botan::GOST_3410_Signature_Operation, Botan::DSA_Signature_Operation, and Botan::NR_Signature_Operation.

Definition at line 56 of file pk_ops.h.

56 { return 1; }
secure_vector< byte > Botan::RSA_Private_Operation::sign ( const byte  msg[],
size_t  msg_len,
RandomNumberGenerator rng 
)
virtual

Implements Botan::PK_Ops::Signature.

Definition at line 91 of file rsa.cpp.

References Botan::RandomNumberGenerator::add_entropy(), Botan::Blinder::blind(), Botan::BigInt::bytes(), Botan::BigInt::encode_1363(), and Botan::Blinder::unblind().

93  {
94  rng.add_entropy(msg, msg_len);
95 
96  /* We don't check signatures against powermod_e_n here because
97  PK_Signer checks verification consistency for all signature
98  algorithms.
99  */
100 
101  const BigInt m(msg, msg_len);
102  const BigInt x = blinder.unblind(private_op(blinder.blind(m)));
103  return BigInt::encode_1363(x, n.bytes());
104  }
static secure_vector< byte > encode_1363(const BigInt &n, size_t bytes)
Definition: big_code.cpp:82
BigInt unblind(const BigInt &x) const
Definition: blinding.cpp:42
BigInt blind(const BigInt &x) const
Definition: blinding.cpp:29
size_t bytes() const
Definition: bigint.cpp:225

The documentation for this class was generated from the following files: