Botan  1.10.9
rw.h
Go to the documentation of this file.
1 /*
2 * Rabin-Williams
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7 
8 #ifndef BOTAN_RW_H__
9 #define BOTAN_RW_H__
10 
11 #include <botan/if_algo.h>
12 #include <botan/pk_ops.h>
13 #include <botan/reducer.h>
14 #include <botan/blinding.h>
15 
16 namespace Botan {
17 
18 /**
19 * Rabin-Williams Public Key
20 */
21 class BOTAN_DLL RW_PublicKey : public virtual IF_Scheme_PublicKey
22  {
23  public:
24  std::string algo_name() const { return "RW"; }
25 
27  const MemoryRegion<byte>& key_bits) :
28  IF_Scheme_PublicKey(alg_id, key_bits)
29  {}
30 
31  RW_PublicKey(const BigInt& mod, const BigInt& exponent) :
32  IF_Scheme_PublicKey(mod, exponent)
33  {}
34 
35  protected:
37  };
38 
39 /**
40 * Rabin-Williams Private Key
41 */
42 class BOTAN_DLL RW_PrivateKey : public RW_PublicKey,
44  {
45  public:
47  const MemoryRegion<byte>& key_bits,
49  IF_Scheme_PrivateKey(rng, alg_id, key_bits) {}
50 
52  const BigInt& p, const BigInt& q,
53  const BigInt& e, const BigInt& d = 0,
54  const BigInt& n = 0) :
55  IF_Scheme_PrivateKey(rng, p, q, e, d, n) {}
56 
57  RW_PrivateKey(RandomNumberGenerator& rng, size_t bits, size_t = 2);
58 
59  bool check_key(RandomNumberGenerator& rng, bool) const;
60  };
61 
62 /**
63 * Rabin-Williams Signature Operation
64 */
65 class BOTAN_DLL RW_Signature_Operation : public PK_Ops::Signature
66  {
67  public:
69 
70  size_t max_input_bits() const { return (n.bits() - 1); }
71 
72  SecureVector<byte> sign(const byte msg[], size_t msg_len,
74  private:
75  const BigInt& n;
76  const BigInt& e;
77  const BigInt& q;
78  const BigInt& c;
79 
80  Fixed_Exponent_Power_Mod powermod_d1_p, powermod_d2_q;
81  Modular_Reducer mod_p;
82  Blinder blinder;
83  };
84 
85 /**
86 * Rabin-Williams Verification Operation
87 */
89  {
90  public:
92  n(rw.get_n()), powermod_e_n(rw.get_e(), rw.get_n())
93  {}
94 
95  size_t max_input_bits() const { return (n.bits() - 1); }
96  bool with_recovery() const { return true; }
97 
98  SecureVector<byte> verify_mr(const byte msg[], size_t msg_len);
99 
100  private:
101  const BigInt& n;
102  Fixed_Exponent_Power_Mod powermod_e_n;
103  };
104 
105 }
106 
107 #endif
BigInt n
Definition: numthry.cpp:26
RW_PrivateKey(RandomNumberGenerator &rng, const BigInt &p, const BigInt &q, const BigInt &e, const BigInt &d=0, const BigInt &n=0)
Definition: rw.h:51
RW_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, RandomNumberGenerator &rng)
Definition: rw.h:46
unsigned char byte
Definition: types.h:22
RW_Verification_Operation(const RW_PublicKey &rw)
Definition: rw.h:91
size_t max_input_bits() const
Definition: rw.h:95
RandomNumberGenerator * rng
Definition: global_rng.cpp:165
GMP_MPZ mod
Definition: gmp_powm.cpp:29
std::string algo_name() const
Definition: rw.h:24
RW_PublicKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition: rw.h:26
size_t max_input_bits() const
Definition: rw.h:70
bool with_recovery() const
Definition: rw.h:96
RW_PublicKey(const BigInt &mod, const BigInt &exponent)
Definition: rw.h:31