Botan 1.10.17

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
26 RW_PublicKey(const AlgorithmIdentifier& alg_id,
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:
36 RW_PublicKey() {}
37 };
38
39 /**
40 * Rabin-Williams Private Key
41 */
42 class BOTAN_DLL RW_PrivateKey : public RW_PublicKey,
43 public IF_Scheme_PrivateKey
44 {
45 public:
46 RW_PrivateKey(const AlgorithmIdentifier& alg_id,
47 const MemoryRegion<byte>& key_bits,
48 RandomNumberGenerator& rng) :
49 IF_Scheme_PrivateKey(rng, alg_id, key_bits) {}
50
51 RW_PrivateKey(RandomNumberGenerator& rng,
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:
68 RW_Signature_Operation(const RW_PrivateKey& rw);
69
70 size_t max_input_bits() const { return (n.bits() - 1); }
71
72 SecureVector<byte> sign(const byte msg[], size_t msg_len,
73 RandomNumberGenerator& rng);
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 */
88 class BOTAN_DLL RW_Verification_Operation : public PK_Ops::Verification
89 {
90 public:
91 RW_Verification_Operation(const RW_PublicKey& rw) :
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
Botan::RW_PrivateKey::RW_PrivateKey
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
Botan::BigInt
Definition: bigint.h:22
Botan::IF_Scheme_PrivateKey
Definition: if_algo.h:58
Botan::RandomNumberGenerator
Definition: rng.h:20
Botan::IF_Scheme_PublicKey
Definition: if_algo.h:21
Botan::PK_Ops::Signature
Definition: pk_ops.h:49
Botan::RW_PrivateKey::RW_PrivateKey
RW_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, RandomNumberGenerator &rng)
Definition: rw.h:46
Botan::RW_PublicKey::RW_PublicKey
RW_PublicKey()
Definition: rw.h:36
Botan::RW_PublicKey::algo_name
std::string algo_name() const
Definition: rw.h:24
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::RW_Verification_Operation::RW_Verification_Operation
RW_Verification_Operation(const RW_PublicKey &rw)
Definition: rw.h:91
Botan::RW_PublicKey
Definition: rw.h:21
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::RW_Signature_Operation::max_input_bits
size_t max_input_bits() const
Definition: rw.h:70
Botan::Blinder
Definition: blinding.h:19
Botan::RW_PublicKey::RW_PublicKey
RW_PublicKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition: rw.h:26
Botan::RW_Verification_Operation::max_input_bits
size_t max_input_bits() const
Definition: rw.h:95
Botan::RW_PrivateKey
Definition: rw.h:42
Botan::RW_Verification_Operation
Definition: rw.h:88
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::Fixed_Exponent_Power_Mod
Definition: pow_mod.h:73
Botan::SecureVector< byte >
Botan::RW_PublicKey::RW_PublicKey
RW_PublicKey(const BigInt &mod, const BigInt &exponent)
Definition: rw.h:31
Botan::RW_Signature_Operation
Definition: rw.h:65
Botan::RW_Verification_Operation::with_recovery
bool with_recovery() const
Definition: rw.h:96
Botan::Modular_Reducer
Definition: reducer.h:18
Botan::PK_Ops::Verification
Definition: pk_ops.h:85