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