Crypto++  5.6.3
Free C++ class library of cryptographic schemes
rw.h
Go to the documentation of this file.
1 // rw.h - written and placed in the public domain by Wei Dai
2 
3 //! \file rw.h
4 //! \brief Classes for Rabin-Williams signature schemes
5 //! \details Rabin-Williams signature schemes as defined in IEEE P1363.
6 
7 #ifndef CRYPTOPP_RW_H
8 #define CRYPTOPP_RW_H
9 
10 
11 #include "cryptlib.h"
12 #include "pubkey.h"
13 #include "integer.h"
14 
15 NAMESPACE_BEGIN(CryptoPP)
16 
17 //! _
18 class CRYPTOPP_DLL RWFunction : public TrapdoorFunction, public PublicKey
19 {
20  typedef RWFunction ThisClass;
21 
22 public:
23  void Initialize(const Integer &n)
24  {m_n = n;}
25 
26  void BERDecode(BufferedTransformation &bt);
27  void DEREncode(BufferedTransformation &bt) const;
28 
29  void Save(BufferedTransformation &bt) const
30  {DEREncode(bt);}
32  {BERDecode(bt);}
33 
34  Integer ApplyFunction(const Integer &x) const;
35  Integer PreimageBound() const {return ++(m_n>>1);}
36  Integer ImageBound() const {return m_n;}
37 
38  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
39  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
40  void AssignFrom(const NameValuePairs &source);
41 
42  const Integer& GetModulus() const {return m_n;}
43  void SetModulus(const Integer &n) {m_n = n;}
44 
45 protected:
46  Integer m_n;
47 };
48 
49 //! _
50 class CRYPTOPP_DLL InvertibleRWFunction : public RWFunction, public TrapdoorFunctionInverse, public PrivateKey
51 {
53 
54 public:
55  void Initialize(const Integer &n, const Integer &p, const Integer &q, const Integer &u)
56  {m_n = n; m_p = p; m_q = q; m_u = u;}
57  // generate a random private key
58  void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
59  {GenerateRandomWithKeySize(rng, modulusBits);}
60 
61  void BERDecode(BufferedTransformation &bt);
62  void DEREncode(BufferedTransformation &bt) const;
63 
64  void Save(BufferedTransformation &bt) const
65  {DEREncode(bt);}
67  {BERDecode(bt);}
68 
70 
71  // GeneratibleCryptoMaterial
72  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
73  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
74  void AssignFrom(const NameValuePairs &source);
75  /*! parameters: (ModulusSize) */
77 
78  const Integer& GetPrime1() const {return m_p;}
79  const Integer& GetPrime2() const {return m_q;}
80  const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;}
81 
82  void SetPrime1(const Integer &p) {m_p = p;}
83  void SetPrime2(const Integer &q) {m_q = q;}
84  void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;}
85 
86 protected:
87  Integer m_p, m_q, m_u;
88 };
89 
90 //! RW
91 struct RW
92 {
93  static std::string StaticAlgorithmName() {return "RW";}
94  typedef RWFunction PublicKey;
96 };
97 
98 //! RWSS
99 template <class STANDARD, class H>
100 struct RWSS : public TF_SS<STANDARD, H, RW>
101 {
102 };
103 
104 NAMESPACE_END
105 
106 #endif
virtual void AssignFrom(const NameValuePairs &source)=0
Assign values to this object.
This file contains helper classes/functions for implementing public key algorithms.
void Load(BufferedTransformation &bt)
Loads a key from a BufferedTransformation.
Definition: rw.h:31
Abstract base classes that provide a uniform interface to this library.
virtual bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const =0
Get a named value.
Interface for random number generators.
Definition: cryptlib.h:1186
Integer ImageBound() const
Returns the maximum size of a message after the trapdoor function is applied.
Definition: rw.h:36
Interface for buffered transformations.
Definition: cryptlib.h:1352
virtual Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const =0
Calculates the inverse of an element.
Interface for private keys.
Definition: cryptlib.h:2184
Applies the inverse of the trapdoor function.
Definition: pubkey.h:184
_
Definition: rw.h:18
Multiple precision integer with arithmetic operations.
Definition: integer.h:31
Applies the trapdoor function.
Definition: pubkey.h:127
void Load(BufferedTransformation &bt)
Loads a key from a BufferedTransformation.
Definition: rw.h:66
void Save(BufferedTransformation &bt) const
Saves a key to a BufferedTransformation.
Definition: rw.h:64
virtual bool Validate(RandomNumberGenerator &rng, unsigned int level) const =0
Check this object for errors.
RWSS.
Definition: rw.h:100
virtual void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &params=g_nullNameValuePairs)
Generate a random key or crypto parameters.
Definition: cryptlib.h:2164
void GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize)
Generate a random key or crypto parameters.
Definition: cryptlib.cpp:771
Interface for public keys.
Definition: cryptlib.h:2179
Crypto++ library namespace.
Integer PreimageBound() const
Returns the maximum size of a message before the trapdoor function is applied.
Definition: rw.h:35
void Save(BufferedTransformation &bt) const
Saves a key to a BufferedTransformation.
Definition: rw.h:29
RW.
Definition: rw.h:91
Interface for retrieving values given their names.
Definition: cryptlib.h:277
Trapdoor Function (TF) Signature Scheme.
Definition: pubkey.h:2180