Fabcoin Core  0.16.2
P2P Digital Currency
rw.h
Go to the documentation of this file.
1 // rw.h - written and placed in the public domain by Wei Dai
2 
10 
11 #ifndef CRYPTOPP_RW_H
12 #define CRYPTOPP_RW_H
13 
14 #include "cryptlib.h"
15 #include "pubkey.h"
16 #include "integer.h"
17 
19 
24 {
26 
27 public:
28 
31  void Initialize(const Integer &n)
32  {m_n = n;}
33 
34  void BERDecode(BufferedTransformation &bt);
35  void DEREncode(BufferedTransformation &bt) const;
36 
37  void Save(BufferedTransformation &bt) const
38  {DEREncode(bt);}
40  {BERDecode(bt);}
41 
42  Integer ApplyFunction(const Integer &x) const;
43  Integer PreimageBound() const {return ++(m_n>>1);}
44  Integer ImageBound() const {return m_n;}
45 
46  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
47  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
48  void AssignFrom(const NameValuePairs &source);
49 
50  const Integer& GetModulus() const {return m_n;}
51  void SetModulus(const Integer &n) {m_n = n;}
52 
53 protected:
55 };
56 
61 {
63 
64 public:
66  InvertibleRWFunction() : m_precompute(false) {}
67 
74  void Initialize(const Integer &n, const Integer &p, const Integer &q, const Integer &u);
75 
82  void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
83  {GenerateRandomWithKeySize(rng, modulusBits);}
84 
86  void DEREncode(BufferedTransformation &bt) const;
87 
88  void Save(BufferedTransformation &bt) const
89  {DEREncode(bt);}
91  {BERDecode(bt);}
92 
94 
95  // GeneratibleCryptoMaterial
96  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
97  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
98  void AssignFrom(const NameValuePairs &source);
100  void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
101 
102  const Integer& GetPrime1() const {return m_p;}
103  const Integer& GetPrime2() const {return m_q;}
105 
106  void SetPrime1(const Integer &p) {m_p = p;}
107  void SetPrime2(const Integer &q) {m_q = q;}
109 
110  virtual bool SupportsPrecomputation() const {return true;}
111  virtual void Precompute(unsigned int unused = 0) {CRYPTOPP_UNUSED(unused); PrecomputeTweakedRoots();}
112  virtual void Precompute(unsigned int unused = 0) const {CRYPTOPP_UNUSED(unused); PrecomputeTweakedRoots();}
113 
114  virtual void LoadPrecomputation(BufferedTransformation &storedPrecomputation);
115  virtual void SavePrecomputation(BufferedTransformation &storedPrecomputation) const;
116 
117 protected:
118  void PrecomputeTweakedRoots() const;
119 
120 protected:
121  Integer m_p, m_q, m_u;
122 
123  mutable Integer m_pre_2_9p, m_pre_2_3q, m_pre_q_p;
124  mutable bool m_precompute;
125 };
126 
128 struct RW
129 {
130  CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "RW";}
133 };
134 
138 template <class STANDARD, class H>
139 struct RWSS : public TF_SS<RW, STANDARD, H>
140 {
141 };
142 
144 
145 #endif
virtual void AssignFrom(const NameValuePairs &source)=0
Assign values to this object.
Rabin-Williams trapdoor function using the private key.
Definition: rw.h:60
virtual void SavePrecomputation(BufferedTransformation &storedPrecomputation) const
Save precomputation for later use.
Definition: cryptlib.h:2140
#define CRYPTOPP_STATIC_CONSTEXPR
Definition: config.h:892
void Load(BufferedTransformation &bt)
Loads a key from a BufferedTransformation.
Definition: rw.h:39
void SetModulus(const Integer &n)
Definition: rw.h:51
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
Abstract base classes that provide a uniform interface to this library.
virtual void Precompute(unsigned int unused=0) const
Definition: rw.h:112
Integer m_n
Definition: rw.h:54
const Integer & GetMultiplicativeInverseOfPrime2ModPrime1() const
Definition: rw.h:104
Interface for random number generators.
Definition: cryptlib.h:1188
Integer ImageBound() const
Returns the maximum size of a message after the trapdoor function is applied.
Definition: rw.h:44
Interface for buffered transformations.
Definition: cryptlib.h:1352
Interface for private keys.
Definition: cryptlib.h:2186
RWFunction PublicKey
Definition: rw.h:131
virtual CRYPTOPP_DLL bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const =0
Get a named value.
Applies the inverse of the trapdoor function.
Definition: pubkey.h:183
virtual void LoadPrecomputation(BufferedTransformation &storedPrecomputation)
Retrieve previously saved precomputation.
Definition: cryptlib.h:2134
bool m_precompute
Definition: rw.h:124
#define x(i)
const char * source
Definition: rpcconsole.cpp:60
Rabin-Williams trapdoor function using the public key.
Definition: rw.h:23
virtual bool Validate(RandomNumberGenerator &rng, unsigned int level) const =0
Check this object for errors.
const char * name
Definition: rest.cpp:36
virtual bool SupportsPrecomputation() const
Determines whether the object supports precomputation.
Definition: rw.h:110
const Integer & GetPrime2() const
Definition: rw.h:103
void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
Create a Rabin-Williams private key.
Definition: rw.h:82
bool Validate(int, bool, const char *)
Definition: test.cpp:884
Multiple precision integer with arithmetic operations.
Definition: integer.h:43
CRYPTOPP_STATIC_CONSTEXPR const char * StaticAlgorithmName()
Definition: rw.h:130
Applies the trapdoor function.
Definition: pubkey.h:128
void Load(BufferedTransformation &bt)
Loads a key from a BufferedTransformation.
Definition: rw.h:90
virtual Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const =0
Calculates the inverse of an element.
void Save(BufferedTransformation &bt) const
Saves a key to a BufferedTransformation.
Definition: rw.h:88
void BERDecode(BufferedTransformation &bt)
Definition: rw.cpp:22
void Initialize(const Integer &n)
Initialize a Rabin-Williams public key.
Definition: rw.h:31
Rabin-Williams signature scheme.
Definition: rw.h:139
#define CRYPTOPP_UNUSED(x)
Definition: config.h:741
virtual void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &params=g_nullNameValuePairs)
Generate a random key or crypto parameters.
Definition: cryptlib.h:2166
void GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize)
Generate a random key or crypto parameters.
Definition: cryptlib.cpp:780
Integer m_pre_q_p
Definition: rw.h:123
Multiple precision integer with arithmetic operations.
const Integer & GetPrime1() const
Definition: rw.h:102
const Integer & GetModulus() const
Definition: rw.h:50
#define NAMESPACE_END
Definition: config.h:201
void DEREncode(BufferedTransformation &bt) const
Definition: rw.cpp:29
Interface for public keys.
Definition: cryptlib.h:2181
virtual void Precompute(unsigned int unused=0)
Perform precomputation.
Definition: rw.h:111
RWFunction ThisClass
Definition: rw.h:25
void SetPrime1(const Integer &p)
Definition: rw.h:106
#define CRYPTOPP_DLL
Definition: config.h:704
Integer PreimageBound() const
Returns the maximum size of a message before the trapdoor function is applied.
Definition: rw.h:43
void Save(BufferedTransformation &bt) const
Saves a key to a BufferedTransformation.
Definition: rw.h:37
Rabin-Williams keys.
Definition: rw.h:128
InvertibleRWFunction PrivateKey
Definition: rw.h:132
InvertibleRWFunction ThisClass
Definition: rw.h:62
InvertibleRWFunction()
Construct an InvertibleRWFunction.
Definition: rw.h:66
void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u)
Definition: rw.h:108
Interface for retrieving values given their names.
Definition: cryptlib.h:279
Integer m_u
Definition: rw.h:121
void SetPrime2(const Integer &q)
Definition: rw.h:107
Trapdoor Function (TF) Signature Scheme.
Definition: pubkey.h:2105