Crypto++  5.6.4
Free C++ class library of cryptographic schemes
luc.h
Go to the documentation of this file.
1 #ifndef CRYPTOPP_LUC_H
2 #define CRYPTOPP_LUC_H
3 
4 /** \file
5 */
6 
7 #include "cryptlib.h"
8 #include "gfpcrypt.h"
9 #include "integer.h"
10 #include "algebra.h"
11 #include "secblock.h"
12 
13 #if CRYPTOPP_MSC_VERSION
14 # pragma warning(push)
15 # pragma warning(disable: 4127 4189)
16 #endif
17 
18 #include "pkcspad.h"
19 #include "integer.h"
20 #include "oaep.h"
21 #include "dh.h"
22 
23 #include <limits.h>
24 
25 NAMESPACE_BEGIN(CryptoPP)
26 
27 //! The LUC function.
28 /*! This class is here for historical and pedagogical interest. It has no
29  practical advantages over other trapdoor functions and probably shouldn't
30  be used in production software. The discrete log based LUC schemes
31  defined later in this .h file may be of more practical interest.
32 */
33 class LUCFunction : public TrapdoorFunction, public PublicKey
34 {
35  typedef LUCFunction ThisClass;
36 
37 public:
38  void Initialize(const Integer &n, const Integer &e)
39  {m_n = n; m_e = e;}
40 
41  void BERDecode(BufferedTransformation &bt);
42  void DEREncode(BufferedTransformation &bt) const;
43 
44  Integer ApplyFunction(const Integer &x) const;
45  Integer PreimageBound() const {return m_n;}
46  Integer ImageBound() const {return m_n;}
47 
48  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
49  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
50  void AssignFrom(const NameValuePairs &source);
51 
52  // non-derived interface
53  const Integer & GetModulus() const {return m_n;}
54  const Integer & GetPublicExponent() const {return m_e;}
55 
56  void SetModulus(const Integer &n) {m_n = n;}
57  void SetPublicExponent(const Integer &e) {m_e = e;}
58 
59 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
60  virtual ~LUCFunction() {}
61 #endif
62 
63 protected:
64  Integer m_n, m_e;
65 };
66 
67 //! _
69 {
71 
72 public:
73  void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits, const Integer &eStart=17);
74  void Initialize(const Integer &n, const Integer &e, const Integer &p, const Integer &q, const Integer &u)
75  {m_n = n; m_e = e; m_p = p; m_q = q; m_u = u;}
76 
77  void BERDecode(BufferedTransformation &bt);
78  void DEREncode(BufferedTransformation &bt) const;
79 
81 
82  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
83  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
84  void AssignFrom(const NameValuePairs &source);
85  /*! parameters: (ModulusSize, PublicExponent (default 17)) */
87 
88  // non-derived interface
89  const Integer& GetPrime1() const {return m_p;}
90  const Integer& GetPrime2() const {return m_q;}
91  const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;}
92 
93  void SetPrime1(const Integer &p) {m_p = p;}
94  void SetPrime2(const Integer &q) {m_q = q;}
95  void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;}
96 
97 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
98  virtual ~InvertibleLUCFunction() {}
99 #endif
100 
101 protected:
102  Integer m_p, m_q, m_u;
103 };
104 
105 struct LUC
106 {
107  static std::string StaticAlgorithmName() {return "LUC";}
108  typedef LUCFunction PublicKey;
110 };
111 
112 //! LUC cryptosystem
113 template <class STANDARD>
114 struct LUCES : public TF_ES<STANDARD, LUC>
115 {
116 };
117 
118 //! LUC signature scheme with appendix
119 template <class STANDARD, class H>
120 struct LUCSS : public TF_SS<STANDARD, H, LUC>
121 {
122 };
123 
124 // analagous to the RSA schemes defined in PKCS #1 v2.0
125 typedef LUCES<OAEP<SHA> >::Decryptor LUCES_OAEP_SHA_Decryptor;
126 typedef LUCES<OAEP<SHA> >::Encryptor LUCES_OAEP_SHA_Encryptor;
127 
130 
131 // ********************************************************
132 
133 // no actual precomputation
135 {
136 public:
137  const AbstractGroup<Element> & GetGroup() const {CRYPTOPP_ASSERT(false); throw 0;}
138  Element BERDecodeElement(BufferedTransformation &bt) const {return Integer(bt);}
139  void DEREncodeElement(BufferedTransformation &bt, const Element &v) const {v.DEREncode(bt);}
140 
141  // non-inherited
142  void SetModulus(const Integer &v) {m_p = v;}
143  const Integer & GetModulus() const {return m_p;}
144 
145 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
146  virtual ~DL_GroupPrecomputation_LUC() {}
147 #endif
148 
149 private:
150  Integer m_p;
151 };
152 
153 //! _
155 {
156 public:
157  // DL_FixedBasePrecomputation
158  bool IsInitialized() const {return m_g.NotZero();}
159  void SetBase(const DL_GroupPrecomputation<Element> &group, const Integer &base)
160  {CRYPTOPP_UNUSED(group); m_g = base;}
161  const Integer & GetBase(const DL_GroupPrecomputation<Element> &group) const
162  {CRYPTOPP_UNUSED(group); return m_g;}
163  void Precompute(const DL_GroupPrecomputation<Element> &group, unsigned int maxExpBits, unsigned int storage)
164  {CRYPTOPP_UNUSED(group); CRYPTOPP_UNUSED(maxExpBits); CRYPTOPP_UNUSED(storage);}
165  void Load(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation)
166  {CRYPTOPP_UNUSED(group); CRYPTOPP_UNUSED(storedPrecomputation);}
167  void Save(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) const
168  {CRYPTOPP_UNUSED(group); CRYPTOPP_UNUSED(storedPrecomputation);}
169  Integer Exponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent) const;
170  Integer CascadeExponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent, const DL_FixedBasePrecomputation<Integer> &pc2, const Integer &exponent2) const
171  {
172  CRYPTOPP_UNUSED(group); CRYPTOPP_UNUSED(exponent); CRYPTOPP_UNUSED(pc2); CRYPTOPP_UNUSED(exponent2);
173  // shouldn't be called
174  throw NotImplemented("DL_BasePrecomputation_LUC: CascadeExponentiate not implemented");
175  }
176 
177 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
178  virtual ~DL_BasePrecomputation_LUC() {}
179 #endif
180 
181 private:
182  Integer m_g;
183 };
184 
185 //! _
186 class DL_GroupParameters_LUC : public DL_GroupParameters_IntegerBasedImpl<DL_GroupPrecomputation_LUC, DL_BasePrecomputation_LUC>
187 {
188 public:
189  // DL_GroupParameters
190  bool IsIdentity(const Integer &element) const {return element == Integer::Two();}
191  void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const;
192  Element MultiplyElements(const Element &a, const Element &b) const
193  {
194  CRYPTOPP_UNUSED(a); CRYPTOPP_UNUSED(b);
195  throw NotImplemented("LUC_GroupParameters: MultiplyElements can not be implemented");
196  }
197  Element CascadeExponentiate(const Element &element1, const Integer &exponent1, const Element &element2, const Integer &exponent2) const
198  {
199  CRYPTOPP_UNUSED(element1); CRYPTOPP_UNUSED(exponent1); CRYPTOPP_UNUSED(element2); CRYPTOPP_UNUSED(exponent2);
200  throw NotImplemented("LUC_GroupParameters: MultiplyElements can not be implemented");
201  }
202 
203  // NameValuePairs interface
204  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
205  {
206  return GetValueHelper<DL_GroupParameters_IntegerBased>(this, name, valueType, pValue).Assignable();
207  }
208 
209 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
210  virtual ~DL_GroupParameters_LUC() {}
211 #endif
212 
213 private:
214  int GetFieldType() const {return 2;}
215 };
216 
217 //! _
219 {
220 public:
222 
223 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
225 #endif
226 
227 protected:
228  unsigned int GetDefaultSubgroupOrderSize(unsigned int modulusSize) const {return modulusSize-1;}
229 };
230 
231 //! _
233 {
234 public:
235  CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "LUC-HMP";}
236 
237  void Sign(const DL_GroupParameters<Integer> &params, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const;
238  bool Verify(const DL_GroupParameters<Integer> &params, const DL_PublicKey<Integer> &publicKey, const Integer &e, const Integer &r, const Integer &s) const;
239 
240  size_t RLen(const DL_GroupParameters<Integer> &params) const
241  {return params.GetGroupOrder().ByteCount();}
242 
243 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
244  virtual ~DL_Algorithm_LUC_HMP() {}
245 #endif
246 };
247 
248 //! _
250 {
254 
255 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
256  virtual ~DL_SignatureKeys_LUC() {}
257 #endif
258 };
259 
260 //! LUC-HMP, based on "Digital signature schemes based on Lucas functions" by Patrick Horster, Markus Michels, Holger Petersen
261 template <class H>
262 struct LUC_HMP : public DL_SS<DL_SignatureKeys_LUC, DL_Algorithm_LUC_HMP, DL_SignatureMessageEncodingMethod_DSA, H>
263 {
264 };
265 
266 //! _
268 {
272 
273 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
274  virtual ~DL_CryptoKeys_LUC() {}
275 #endif
276 };
277 
278 //! LUC-IES
279 template <class COFACTOR_OPTION = NoCofactorMultiplication, bool DHAES_MODE = true>
280 struct LUC_IES
281  : public DL_ES<
282  DL_CryptoKeys_LUC,
283  DL_KeyAgreementAlgorithm_DH<Integer, COFACTOR_OPTION>,
284  DL_KeyDerivationAlgorithm_P1363<Integer, DHAES_MODE, P1363_KDF2<SHA1> >,
285  DL_EncryptionAlgorithm_Xor<HMAC<SHA1>, DHAES_MODE>,
286  LUC_IES<> >
287 {
288  static std::string StaticAlgorithmName() {return "LUC-IES";} // non-standard name
289 
290 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
291  virtual ~LUC_IES() {}
292 #endif
293 };
294 
295 // ********************************************************
296 
297 //! LUC-DH
299 
300 NAMESPACE_END
301 
302 #if CRYPTOPP_MSC_VERSION
303 # pragma warning(pop)
304 #endif
305 
306 #endif
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
Definition: luc.cpp:111
Trapdoor Function (TF) encryption scheme.
Definition: pubkey.h:2160
bool NotZero() const
Determines if the Integer is non-0.
Definition: integer.h:329
LUC-IES.
Definition: luc.h:280
Converts a typename to an enumerated value.
Definition: cryptlib.h:120
Abstract base classes that provide a uniform interface to this library.
Interface for random number generators.
Definition: cryptlib.h:1193
Definition: luc.h:105
Discrete Log (DL) encryption scheme.
Definition: pubkey.h:2237
Integer PreimageBound() const
Returns the maximum size of a message before the trapdoor function is applied.
Definition: luc.h:45
Classes for performing mathematics over different fields.
Interface for buffered transformations.
Definition: cryptlib.h:1359
Interface for private keys.
Definition: cryptlib.h:2198
bool IsIdentity(const Integer &element) const
Determines if an element is an identity.
Definition: luc.h:190
Interface for Discrete Log (DL) public keys.
Definition: pubkey.h:1020
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
Definition: luc.cpp:197
Discrete Log (DL) signature scheme.
Definition: pubkey.h:2214
Classes and functions for secure memory allocations.
Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const
Calculates the inverse of an element.
Definition: luc.cpp:169
Applies the inverse of the trapdoor function.
Definition: pubkey.h:190
LUC signature scheme with appendix.
Definition: luc.h:120
A method was called which was not implemented.
Definition: cryptlib.h:208
LUC cryptosystem.
Definition: luc.h:114
Interface for Elgamal-like signature algorithms.
Definition: pubkey.h:1304
Classes for Diffie-Hellman key exchange.
Multiple precision integer with arithmetic operations.
Definition: integer.h:45
static const Integer & Two()
Integer representing 2.
Definition: integer.cpp:3024
Applies the trapdoor function.
Definition: pubkey.h:133
Implementation of schemes based on DL over GF(p)
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Definition: trap.h:62
Diffie-Hellman domain.
Definition: dh.h:23
Abstract group.
Definition: algebra.h:26
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
Definition: luc.h:204
void DEREncode(BufferedTransformation &bt) const
Encode in DER format.
Definition: integer.cpp:3363
LUC-HMP, based on "Digital signature schemes based on Lucas functions" by Patrick Horster...
Definition: luc.h:262
DL private key (in GF(p) groups)
Definition: gfpcrypt.h:275
void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const
Exponentiates a base to multiple exponents.
Definition: luc.cpp:44
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
Definition: luc.cpp:206
Multiple precision integer with arithmetic operations.
The LUC function.
Definition: luc.h:33
Interface for public keys.
Definition: cryptlib.h:2193
Crypto++ library namespace.
Integer ImageBound() const
Returns the maximum size of a message after the trapdoor function is applied.
Definition: luc.h:46
DH_Domain< DL_GroupParameters_LUC_DefaultSafePrime > LUC_DH
LUC-DH.
Definition: luc.h:298
unsigned int ByteCount() const
Determines the number of bytes required to represent the Integer.
Definition: integer.cpp:3271
virtual Integer GetGroupOrder() const
Retrieves the order of the group.
Definition: pubkey.h:867
Interface for retrieving values given their names.
Definition: cryptlib.h:282
Template implementing constructors for public key algorithm classes.
Definition: pubkey.h:2037
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
Definition: luc.cpp:177
Trapdoor Function (TF) Signature Scheme.
Definition: pubkey.h:2187