Crypto++
rw.h
Go to the documentation of this file.
1 #ifndef CRYPTOPP_RW_H
2 #define CRYPTOPP_RW_H
3 
4 /** \file
5  This file contains classes that implement the
6  Rabin-Williams signature schemes as defined in IEEE P1363.
7 */
8 
9 #include "pubkey.h"
10 
11 NAMESPACE_BEGIN(CryptoPP)
12 
13 //! _
14 class CRYPTOPP_DLL RWFunction : public TrapdoorFunction, public PublicKey
15 {
16  typedef RWFunction ThisClass;
17 
18 public:
19  void Initialize(const Integer &n)
20  {m_n = n;}
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>>1);}
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  void SetModulus(const Integer &n) {m_n = n;}
35 
36 protected:
37  Integer m_n;
38 };
39 
40 //! _
41 class CRYPTOPP_DLL InvertibleRWFunction : public RWFunction, public TrapdoorFunctionInverse, public PrivateKey
42 {
44 
45 public:
46  void Initialize(const Integer &n, const Integer &p, const Integer &q, const Integer &u)
47  {m_n = n; m_p = p; m_q = q; m_u = u;}
48  // generate a random private key
49  void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
50  {GenerateRandomWithKeySize(rng, modulusBits);}
51 
52  void BERDecode(BufferedTransformation &bt);
53  void DEREncode(BufferedTransformation &bt) const;
54 
55  Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const;
56 
57  // GeneratibleCryptoMaterial
58  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
59  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
60  void AssignFrom(const NameValuePairs &source);
61  /*! parameters: (ModulusSize) */
63 
64  const Integer& GetPrime1() const {return m_p;}
65  const Integer& GetPrime2() const {return m_q;}
66  const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;}
67 
68  void SetPrime1(const Integer &p) {m_p = p;}
69  void SetPrime2(const Integer &q) {m_q = q;}
70  void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;}
71 
72 protected:
73  Integer m_p, m_q, m_u;
74 };
75 
76 //! RW
77 struct RW
78 {
79  static std::string StaticAlgorithmName() {return "RW";}
80  typedef RWFunction PublicKey;
82 };
83 
84 //! RWSS
85 template <class STANDARD, class H>
86 struct RWSS : public TF_SS<STANDARD, H, RW>
87 {
88 };
89 
90 NAMESPACE_END
91 
92 #endif
virtual void AssignFrom(const NameValuePairs &source)=0
assign values from source to this object
This file contains helper classes/functions for implementing public key algorithms.
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
_
Definition: rw.h:14
virtual bool Validate(RandomNumberGenerator &rng, unsigned int level) const =0
check this object for errors
multiple precision integer and basic arithmetics
Definition: integer.h:26
virtual bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const =0
to be implemented by derived classes, users should use one of the above functions instead ...
RWSS.
Definition: rw.h:86
Trapdoor Function Based Signature Scheme.
Definition: pubkey.h:1625
virtual void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &params=g_nullNameValuePairs)
generate a random key or crypto parameters
Definition: cryptlib.h:1106
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
RW.
Definition: rw.h:77
interface for retrieving values given their names
Definition: cryptlib.h:224