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  void Save(BufferedTransformation &bt) const
26  {DEREncode(bt);}
28  {BERDecode(bt);}
29 
30  Integer ApplyFunction(const Integer &x) const;
31  Integer PreimageBound() const {return ++(m_n>>1);}
32  Integer ImageBound() const {return m_n;}
33 
34  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
35  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
36  void AssignFrom(const NameValuePairs &source);
37 
38  const Integer& GetModulus() const {return m_n;}
39  void SetModulus(const Integer &n) {m_n = n;}
40 
41 protected:
42  Integer m_n;
43 };
44 
45 //! _
46 class CRYPTOPP_DLL InvertibleRWFunction : public RWFunction, public TrapdoorFunctionInverse, public PrivateKey
47 {
49 
50 public:
51  void Initialize(const Integer &n, const Integer &p, const Integer &q, const Integer &u)
52  {m_n = n; m_p = p; m_q = q; m_u = u;}
53  // generate a random private key
54  void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
55  {GenerateRandomWithKeySize(rng, modulusBits);}
56 
57  void BERDecode(BufferedTransformation &bt);
58  void DEREncode(BufferedTransformation &bt) const;
59 
60  void Save(BufferedTransformation &bt) const
61  {DEREncode(bt);}
63  {BERDecode(bt);}
64 
65  Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const;
66 
67  // GeneratibleCryptoMaterial
68  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
69  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
70  void AssignFrom(const NameValuePairs &source);
71  /*! parameters: (ModulusSize) */
73 
74  const Integer& GetPrime1() const {return m_p;}
75  const Integer& GetPrime2() const {return m_q;}
76  const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;}
77 
78  void SetPrime1(const Integer &p) {m_p = p;}
79  void SetPrime2(const Integer &q) {m_q = q;}
80  void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;}
81 
82 protected:
83  Integer m_p, m_q, m_u;
84 };
85 
86 //! RW
87 struct RW
88 {
89  static std::string StaticAlgorithmName() {return "RW";}
90  typedef RWFunction PublicKey;
92 };
93 
94 //! RWSS
95 template <class STANDARD, class H>
96 struct RWSS : public TF_SS<STANDARD, H, RW>
97 {
98 };
99 
100 NAMESPACE_END
101 
102 #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.
void Load(BufferedTransformation &bt)
load key from a BufferedTransformation
Definition: rw.h:27
interface for random number generators
Definition: cryptlib.h:669
interface for buffered transformations
Definition: cryptlib.h:771
interface for private keys
Definition: cryptlib.h:1122
_
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 ...
void Load(BufferedTransformation &bt)
load key from a BufferedTransformation
Definition: rw.h:62
void Save(BufferedTransformation &bt) const
save key into a BufferedTransformation
Definition: rw.h:60
RWSS.
Definition: rw.h:96
virtual void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &params=g_nullNameValuePairs)
generate a random key or crypto parameters
Definition: cryptlib.h:1107
void GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize)
calls the above function with a NameValuePairs object that just specifies "KeySize" ...
Definition: cryptlib.cpp:658
interface for public keys
Definition: cryptlib.h:1116
void Save(BufferedTransformation &bt) const
save key into a BufferedTransformation
Definition: rw.h:25
RW.
Definition: rw.h:87
interface for retrieving values given their names
Definition: cryptlib.h:225
Trapdoor Function Based Signature Scheme.
Definition: pubkey.h:1625