Crypto++
rabin.h
Go to the documentation of this file.
1 #ifndef CRYPTOPP_RABIN_H
2 #define CRYPTOPP_RABIN_H
3 
4 /** \file
5 */
6 
7 #include "oaep.h"
8 #include "pssr.h"
9 #include "integer.h"
10 
11 NAMESPACE_BEGIN(CryptoPP)
12 
13 //! _
15 {
16  typedef RabinFunction ThisClass;
17 
18 public:
19  void Initialize(const Integer &n, const Integer &r, const Integer &s)
20  {m_n = n; m_r = r; m_s = s;}
21 
22  void BERDecode(BufferedTransformation &bt);
23  void DEREncode(BufferedTransformation &bt) const;
24 
25  Integer ApplyFunction(const Integer &x) const;
26  Integer PreimageBound() const {return m_n;}
27  Integer ImageBound() const {return m_n;}
28 
29  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
30  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
31  void AssignFrom(const NameValuePairs &source);
32 
33  const Integer& GetModulus() const {return m_n;}
34  const Integer& GetQuadraticResidueModPrime1() const {return m_r;}
35  const Integer& GetQuadraticResidueModPrime2() const {return m_s;}
36 
37  void SetModulus(const Integer &n) {m_n = n;}
38  void SetQuadraticResidueModPrime1(const Integer &r) {m_r = r;}
39  void SetQuadraticResidueModPrime2(const Integer &s) {m_s = s;}
40 
41 protected:
42  Integer m_n, m_r, m_s;
43 };
44 
45 //! _
47 {
49 
50 public:
51  void Initialize(const Integer &n, const Integer &r, const Integer &s,
52  const Integer &p, const Integer &q, const Integer &u)
53  {m_n = n; m_r = r; m_s = s; m_p = p; m_q = q; m_u = u;}
54  void Initialize(RandomNumberGenerator &rng, unsigned int keybits)
55  {GenerateRandomWithKeySize(rng, keybits);}
56 
57  void BERDecode(BufferedTransformation &bt);
58  void DEREncode(BufferedTransformation &bt) const;
59 
60  Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const;
61 
62  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
63  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
64  void AssignFrom(const NameValuePairs &source);
65  /*! parameters: (ModulusSize) */
67 
68  const Integer& GetPrime1() const {return m_p;}
69  const Integer& GetPrime2() const {return m_q;}
70  const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;}
71 
72  void SetPrime1(const Integer &p) {m_p = p;}
73  void SetPrime2(const Integer &q) {m_q = q;}
74  void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;}
75 
76 protected:
77  Integer m_p, m_q, m_u;
78 };
79 
80 //! Rabin
81 struct Rabin
82 {
83  static std::string StaticAlgorithmName() {return "Rabin-Crypto++Variant";}
84  typedef RabinFunction PublicKey;
86 };
87 
88 //! Rabin encryption
89 template <class STANDARD>
90 struct RabinES : public TF_ES<STANDARD, Rabin>
91 {
92 };
93 
94 //! Rabin signature
95 template <class STANDARD, class H>
96 struct RabinSS : public TF_SS<STANDARD, H, Rabin>
97 {
98 };
99 
100 // More typedefs for backwards compatibility
101 class SHA1;
102 typedef RabinES<OAEP<SHA1> >::Decryptor RabinDecryptor;
103 typedef RabinES<OAEP<SHA1> >::Encryptor RabinEncryptor;
104 
105 NAMESPACE_END
106 
107 #endif
interface for random number generators
Definition: cryptlib.h:668
interface for buffered transformations
Definition: cryptlib.h:770
interface for private keys
Definition: cryptlib.h:1121
Rabin signature.
Definition: rabin.h:96
Rabin encryption.
Definition: rabin.h:90
Rabin.
Definition: rabin.h:81
multiple precision integer and basic arithmetics
Definition: integer.h:26
SHA-1
Definition: sha.h:9
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
void AssignFrom(const NameValuePairs &source)
assign values from source to this object
Trapdoor Function Based Signature Scheme.
Definition: pubkey.h:1625
void GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize)
calls the above function with a NameValuePairs object that just specifies "KeySize" ...
interface for public keys
Definition: cryptlib.h:1115
Trapdoor Function Based Encryption Scheme.
Definition: pubkey.h:1603
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
check this object for errors
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
to be implemented by derived classes, users should use one of the above functions instead ...
interface for retrieving values given their names
Definition: cryptlib.h:224
A template implementing constructors for public key algorithm classes.
Definition: pubkey.h:1488