Fabcoin Core  0.16.2
P2P Digital Currency
rabin.h
Go to the documentation of this file.
1 // rabin.h - written and placed in the public domain by Wei Dai
2 
5 
6 #ifndef CRYPTOPP_RABIN_H
7 #define CRYPTOPP_RABIN_H
8 
9 #include "cryptlib.h"
10 #include "oaep.h"
11 #include "pssr.h"
12 #include "integer.h"
13 
15 
16 class RabinFunction : public TrapdoorFunction, public PublicKey
20 {
22 
23 public:
24 
29  void Initialize(const Integer &n, const Integer &r, const Integer &s)
30  {m_n = n; m_r = r; m_s = s;}
31 
32  void BERDecode(BufferedTransformation &bt);
33  void DEREncode(BufferedTransformation &bt) const;
34 
35  Integer ApplyFunction(const Integer &x) const;
36  Integer PreimageBound() const {return m_n;}
37  Integer ImageBound() const {return m_n;}
38 
39  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
40  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
41  void AssignFrom(const NameValuePairs &source);
42 
43  const Integer& GetModulus() const {return m_n;}
44  const Integer& GetQuadraticResidueModPrime1() const {return m_r;}
45  const Integer& GetQuadraticResidueModPrime2() const {return m_s;}
46 
47  void SetModulus(const Integer &n) {m_n = n;}
48  void SetQuadraticResidueModPrime1(const Integer &r) {m_r = r;}
49  void SetQuadraticResidueModPrime2(const Integer &s) {m_s = s;}
50 
51 protected:
52  Integer m_n, m_r, m_s;
53 };
54 
59 {
61 
62 public:
63 
72  void Initialize(const Integer &n, const Integer &r, const Integer &s, const Integer &p, const Integer &q, const Integer &u)
73  {m_n = n; m_r = r; m_s = s; m_p = p; m_q = q; m_u = u;}
74 
81  void Initialize(RandomNumberGenerator &rng, unsigned int keybits)
82  {GenerateRandomWithKeySize(rng, keybits);}
83 
85  void DEREncode(BufferedTransformation &bt) const;
86 
88 
89  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
90  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
91  void AssignFrom(const NameValuePairs &source);
94 
95  const Integer& GetPrime1() const {return m_p;}
96  const Integer& GetPrime2() const {return m_q;}
98 
99  void SetPrime1(const Integer &p) {m_p = p;}
100  void SetPrime2(const Integer &q) {m_q = q;}
102 
103 protected:
105 };
106 
108 struct Rabin
109 {
110  static std::string StaticAlgorithmName() {return "Rabin-Crypto++Variant";}
113 };
114 
117 template <class STANDARD>
118 struct RabinES : public TF_ES<Rabin, STANDARD>
119 {
120 };
121 
125 template <class STANDARD, class H>
126 struct RabinSS : public TF_SS<Rabin, STANDARD, H>
127 {
128 };
129 
130 // More typedefs for backwards compatibility
131 class SHA1;
132 typedef RabinES<OAEP<SHA1> >::Decryptor RabinDecryptor;
133 typedef RabinES<OAEP<SHA1> >::Encryptor RabinEncryptor;
134 
136 
137 #endif
InvertibleRabinFunction ThisClass
Definition: rabin.h:60
Trapdoor Function (TF) encryption scheme.
Definition: pubkey.h:2078
RabinFunction ThisClass
Definition: rabin.h:21
const Integer & GetPrime1() const
Definition: rabin.h:95
static std::string StaticAlgorithmName()
Definition: rabin.h:110
Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const
Calculates the inverse of an element.
Definition: rabin.cpp:141
void DEREncode(BufferedTransformation &bt) const
Definition: rabin.cpp:129
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
Integer PreimageBound() const
Returns the maximum size of a message before the trapdoor function is applied.
Definition: rabin.h:36
Abstract base classes that provide a uniform interface to this library.
Interface for random number generators.
Definition: cryptlib.h:1188
Interface for buffered transformations.
Definition: cryptlib.h:1352
Interface for private keys.
Definition: cryptlib.h:2186
Rabin signature scheme.
Definition: rabin.h:126
Rabin trapdoor function using the public key.
Definition: rabin.h:19
Rabin encryption scheme.
Definition: rabin.h:118
RabinFunction PublicKey
Definition: rabin.h:111
Applies the inverse of the trapdoor function.
Definition: pubkey.h:183
#define x(i)
const char * source
Definition: rpcconsole.cpp:60
RabinES< OAEP< SHA1 > >::Encryptor RabinEncryptor
Definition: rabin.h:133
void SetPrime1(const Integer &p)
Definition: rabin.h:99
void SetModulus(const Integer &n)
Definition: rabin.h:47
RabinES< OAEP< SHA1 > >::Decryptor RabinDecryptor
Definition: rabin.h:131
Rabin keys.
Definition: rabin.h:108
const Integer & GetPrime2() const
Definition: rabin.h:96
const char * name
Definition: rest.cpp:36
bool Validate(int, bool, const char *)
Definition: test.cpp:884
Multiple precision integer with arithmetic operations.
Definition: integer.h:43
void SetQuadraticResidueModPrime1(const Integer &r)
Definition: rabin.h:48
SHA-1 message digest.
Definition: sha.h:25
const Integer & GetModulus() const
Definition: rabin.h:43
void BERDecode(BufferedTransformation &bt)
Definition: rabin.cpp:117
Applies the trapdoor function.
Definition: pubkey.h:128
const Integer & GetQuadraticResidueModPrime1() const
Definition: rabin.h:44
const Integer & GetMultiplicativeInverseOfPrime2ModPrime1() const
Definition: rabin.h:97
Integer ImageBound() const
Returns the maximum size of a message after the trapdoor function is applied.
Definition: rabin.h:37
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
Definition: rabin.cpp:76
void Initialize(const Integer &n, const Integer &r, const Integer &s, const Integer &p, const Integer &q, const Integer &u)
Initialize a Rabin private key.
Definition: rabin.h:72
void SetQuadraticResidueModPrime2(const Integer &s)
Definition: rabin.h:49
Integer m_s
Definition: rabin.h:52
void SetPrime2(const Integer &q)
Definition: rabin.h:100
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
Definition: rabin.cpp:213
void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u)
Definition: rabin.h:101
InvertibleRabinFunction PrivateKey
Definition: rabin.h:112
void GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize)
Generate a random key or crypto parameters.
Definition: cryptlib.cpp:780
Integer m_n
Definition: rabin.h:52
Multiple precision integer with arithmetic operations.
#define NAMESPACE_END
Definition: config.h:201
Interface for public keys.
Definition: cryptlib.h:2181
Integer m_r
Definition: rabin.h:52
Rabin trapdoor function using the private key.
Definition: rabin.h:58
Classes for probablistic signature schemes.
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
Definition: rabin.cpp:184
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
Definition: rabin.cpp:204
const Integer & GetQuadraticResidueModPrime2() const
Definition: rabin.h:45
void Initialize(const Integer &n, const Integer &r, const Integer &s)
Initialize a Rabin public key.
Definition: rabin.h:29
void Initialize(RandomNumberGenerator &rng, unsigned int keybits)
Create a Rabin private key.
Definition: rabin.h:81
Interface for retrieving values given their names.
Definition: cryptlib.h:279
Trapdoor Function (TF) Signature Scheme.
Definition: pubkey.h:2105