Botan  1.11.10
Public Member Functions | List of all members
Botan::RW_Signature_Operation Class Reference

#include <rw.h>

Inheritance diagram for Botan::RW_Signature_Operation:
Botan::PK_Ops::Signature

Public Member Functions

size_t max_input_bits () const
 
virtual size_t message_part_size () const
 
virtual size_t message_parts () const
 
 RW_Signature_Operation (const RW_PrivateKey &rw)
 
secure_vector< bytesign (const byte msg[], size_t msg_len, RandomNumberGenerator &rng)
 

Detailed Description

Rabin-Williams Signature Operation

Definition at line 65 of file rw.h.

Constructor & Destructor Documentation

Botan::RW_Signature_Operation::RW_Signature_Operation ( const RW_PrivateKey rw)

Definition at line 63 of file rw.cpp.

63  :
64  n(rw.get_n()),
65  e(rw.get_e()),
66  q(rw.get_q()),
67  c(rw.get_c()),
68  powermod_d1_p(rw.get_d1(), rw.get_p()),
69  powermod_d2_q(rw.get_d2(), rw.get_q()),
70  mod_p(rw.get_p())
71  {
72  }

Member Function Documentation

size_t Botan::RW_Signature_Operation::max_input_bits ( ) const
inlinevirtual

Get the maximum message size in bits supported by this public key.

Returns
maximum message in bits

Implements Botan::PK_Ops::Signature.

Definition at line 70 of file rw.h.

70 { 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::RW_Signature_Operation::sign ( const byte  msg[],
size_t  msg_len,
RandomNumberGenerator rng 
)
virtual

Implements Botan::PK_Ops::Signature.

Definition at line 75 of file rw.cpp.

References Botan::RandomNumberGenerator::add_entropy(), Botan::BigInt::bits(), Botan::Blinder::blind(), Botan::BigInt::bytes(), Botan::BigInt::encode_1363(), Botan::Blinder::initialized(), Botan::inverse_mod(), Botan::jacobi(), Botan::mul_add(), Botan::power_mod(), Botan::Modular_Reducer::reduce(), Botan::sub_mul(), and Botan::Blinder::unblind().

77  {
78  rng.add_entropy(msg, msg_len);
79 
80  if(!blinder.initialized())
81  {
82  BigInt k(rng, std::min<size_t>(160, n.bits() - 1));
83  blinder = Blinder(power_mod(k, e, n), inverse_mod(k, n), n);
84  }
85 
86  BigInt i(msg, msg_len);
87 
88  if(i >= n || i % 16 != 12)
89  throw Invalid_Argument("Rabin-Williams: invalid input");
90 
91  if(jacobi(i, n) != 1)
92  i >>= 1;
93 
94  i = blinder.blind(i);
95 
96  auto future_j1 = std::async(std::launch::async, powermod_d1_p, i);
97  const BigInt j2 = powermod_d2_q(i);
98  BigInt j1 = future_j1.get();
99 
100  j1 = mod_p.reduce(sub_mul(j1, j2, c));
101 
102  const BigInt r = blinder.unblind(mul_add(j1, q, j2));
103 
104  return BigInt::encode_1363(std::min(r, n - r), n.bytes());
105  }
static secure_vector< byte > encode_1363(const BigInt &n, size_t bytes)
Definition: big_code.cpp:82
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
bool initialized() const
Definition: blinding.h:25
size_t bits() const
Definition: bigint.cpp:233
BigInt unblind(const BigInt &x) const
Definition: blinding.cpp:42
s32bit jacobi(const BigInt &a, const BigInt &n)
Definition: jacobi.cpp:15
BigInt reduce(const BigInt &x) const
Definition: reducer.cpp:32
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition: numthry.cpp:128
BigInt blind(const BigInt &x) const
Definition: blinding.cpp:29
BigInt sub_mul(const BigInt &a, const BigInt &b, const BigInt &c)
Definition: mp_numth.cpp:63
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
Definition: numthry.cpp:219
BigInt mul_add(const BigInt &a, const BigInt &b, const BigInt &c)
Definition: mp_numth.cpp:34
size_t bytes() const
Definition: bigint.cpp:225

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