Crypto++  5.6.4
Free C++ class library of cryptographic schemes
rabin.h
Go to the documentation of this file.
1 // rabin.h - written and placed in the public domain by Wei Dai
2 
3 //! \file
4 //! \headerfile rabin.h
5 //! \brief Classes for Rabin encryption and signature schemes
6 
7 #ifndef CRYPTOPP_RABIN_H
8 #define CRYPTOPP_RABIN_H
9 
10 #include "cryptlib.h"
11 #include "oaep.h"
12 #include "pssr.h"
13 #include "integer.h"
14 
15 NAMESPACE_BEGIN(CryptoPP)
16 
17 //! _
19 {
20  typedef RabinFunction ThisClass;
21 
22 public:
23  void Initialize(const Integer &n, const Integer &r, const Integer &s)
24  {m_n = n; m_r = r; m_s = s;}
25 
26  void BERDecode(BufferedTransformation &bt);
27  void DEREncode(BufferedTransformation &bt) const;
28 
29  Integer ApplyFunction(const Integer &x) const;
30  Integer PreimageBound() const {return m_n;}
31  Integer ImageBound() const {return m_n;}
32 
33  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
34  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
35  void AssignFrom(const NameValuePairs &source);
36 
37  const Integer& GetModulus() const {return m_n;}
38  const Integer& GetQuadraticResidueModPrime1() const {return m_r;}
39  const Integer& GetQuadraticResidueModPrime2() const {return m_s;}
40 
41  void SetModulus(const Integer &n) {m_n = n;}
42  void SetQuadraticResidueModPrime1(const Integer &r) {m_r = r;}
43  void SetQuadraticResidueModPrime2(const Integer &s) {m_s = s;}
44 
45 protected:
46  Integer m_n, m_r, m_s;
47 };
48 
49 //! _
51 {
53 
54 public:
55  void Initialize(const Integer &n, const Integer &r, const Integer &s,
56  const Integer &p, const Integer &q, const Integer &u)
57  {m_n = n; m_r = r; m_s = s; m_p = p; m_q = q; m_u = u;}
58  void Initialize(RandomNumberGenerator &rng, unsigned int keybits)
59  {GenerateRandomWithKeySize(rng, keybits);}
60 
61  void BERDecode(BufferedTransformation &bt);
62  void DEREncode(BufferedTransformation &bt) const;
63 
65 
66  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
67  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
68  void AssignFrom(const NameValuePairs &source);
69  /*! parameters: (ModulusSize) */
71 
72  const Integer& GetPrime1() const {return m_p;}
73  const Integer& GetPrime2() const {return m_q;}
74  const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;}
75 
76  void SetPrime1(const Integer &p) {m_p = p;}
77  void SetPrime2(const Integer &q) {m_q = q;}
78  void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;}
79 
80 protected:
81  Integer m_p, m_q, m_u;
82 };
83 
84 //! Rabin
85 struct Rabin
86 {
87  static std::string StaticAlgorithmName() {return "Rabin-Crypto++Variant";}
88  typedef RabinFunction PublicKey;
90 };
91 
92 //! Rabin encryption
93 template <class STANDARD>
94 struct RabinES : public TF_ES<STANDARD, Rabin>
95 {
96 };
97 
98 //! Rabin signature
99 template <class STANDARD, class H>
100 struct RabinSS : public TF_SS<STANDARD, H, Rabin>
101 {
102 };
103 
104 // More typedefs for backwards compatibility
105 class SHA1;
106 typedef RabinES<OAEP<SHA1> >::Decryptor RabinDecryptor;
107 typedef RabinES<OAEP<SHA1> >::Encryptor RabinEncryptor;
108 
109 NAMESPACE_END
110 
111 #endif
Trapdoor Function (TF) encryption scheme.
Definition: pubkey.h:2160
Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const
Calculates the inverse of an element.
Definition: rabin.cpp:141
Integer PreimageBound() const
Returns the maximum size of a message before the trapdoor function is applied.
Definition: rabin.h:30
Abstract base classes that provide a uniform interface to this library.
Interface for random number generators.
Definition: cryptlib.h:1193
Interface for buffered transformations.
Definition: cryptlib.h:1359
Interface for private keys.
Definition: cryptlib.h:2198
Rabin signature.
Definition: rabin.h:100
Rabin encryption.
Definition: rabin.h:94
Applies the inverse of the trapdoor function.
Definition: pubkey.h:190
Rabin.
Definition: rabin.h:85
Multiple precision integer with arithmetic operations.
Definition: integer.h:45
SHA-1
Definition: sha.h:22
Applies the trapdoor function.
Definition: pubkey.h:133
Integer ImageBound() const
Returns the maximum size of a message after the trapdoor function is applied.
Definition: rabin.h:31
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
Definition: rabin.cpp:76
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
Definition: rabin.cpp:213
void GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize)
Generate a random key or crypto parameters.
Definition: cryptlib.cpp:768
Multiple precision integer with arithmetic operations.
Interface for public keys.
Definition: cryptlib.h:2193
Crypto++ library namespace.
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
Interface for retrieving values given their names.
Definition: cryptlib.h:282
Template implementing constructors for public key algorithm classes.
Definition: pubkey.h:2037
Trapdoor Function (TF) Signature Scheme.
Definition: pubkey.h:2187