Fabcoin Core  0.16.2
P2P Digital Currency
luc.h
Go to the documentation of this file.
1 // luc.h - written and placed in the public domain by Wei Dai
2 
8 
9 #ifndef CRYPTOPP_LUC_H
10 #define CRYPTOPP_LUC_H
11 
12 #include "cryptlib.h"
13 #include "gfpcrypt.h"
14 #include "integer.h"
15 #include "algebra.h"
16 #include "secblock.h"
17 
18 #if CRYPTOPP_MSC_VERSION
19 # pragma warning(push)
20 # pragma warning(disable: 4127 4189)
21 #endif
22 
23 #include "pkcspad.h"
24 #include "integer.h"
25 #include "oaep.h"
26 #include "dh.h"
27 
28 #include <limits.h>
29 
31 
32 class LUCFunction : public TrapdoorFunction, public PublicKey
37 {
39 
40 public:
41  virtual ~LUCFunction() {}
42 
46  void Initialize(const Integer &n, const Integer &e)
47  {m_n = n; m_e = e;}
48 
49  void BERDecode(BufferedTransformation &bt);
50  void DEREncode(BufferedTransformation &bt) const;
51 
52  Integer ApplyFunction(const Integer &x) const;
53  Integer PreimageBound() const {return m_n;}
54  Integer ImageBound() const {return m_n;}
55 
56  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
57  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
58  void AssignFrom(const NameValuePairs &source);
59 
60  // non-derived interface
61  const Integer & GetModulus() const {return m_n;}
62  const Integer & GetPublicExponent() const {return m_e;}
63 
64  void SetModulus(const Integer &n) {m_n = n;}
65  void SetPublicExponent(const Integer &e) {m_e = e;}
66 
67 protected:
68  Integer m_n, m_e;
69 };
70 
76 {
78 
79 public:
81 
90  void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits, const Integer &eStart=17);
91 
99  void Initialize(const Integer &n, const Integer &e, const Integer &p, const Integer &q, const Integer &u)
100  {m_n = n; m_e = e; m_p = p; m_q = q; m_u = u;}
101 
103  void DEREncode(BufferedTransformation &bt) const;
104 
106 
107  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
108  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
109  void AssignFrom(const NameValuePairs &source);
111  void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
112 
113  // non-derived interface
114  const Integer& GetPrime1() const {return m_p;}
115  const Integer& GetPrime2() const {return m_q;}
117 
118  void SetPrime1(const Integer &p) {m_p = p;}
119  void SetPrime2(const Integer &q) {m_q = q;}
121 
122 protected:
124 };
125 
126 struct LUC
127 {
128  static std::string StaticAlgorithmName() {return "LUC";}
131 };
132 
138 template <class STANDARD>
139 struct LUCES : public TF_ES<LUC, STANDARD>
140 {
141 };
142 
149 template <class STANDARD, class H>
150 struct LUCSS : public TF_SS<LUC, STANDARD, H>
151 {
152 };
153 
154 // analogous to the RSA schemes defined in PKCS #1 v2.0
157 
160 
161 // ********************************************************
162 
163 // no actual precomputation
165 {
166 public:
168 
169  const AbstractGroup<Element> & GetGroup() const {CRYPTOPP_ASSERT(false); throw 0;}
171  void DEREncodeElement(BufferedTransformation &bt, const Element &v) const {v.DEREncode(bt);}
172 
173  // non-inherited
174  void SetModulus(const Integer &v) {m_p = v;}
175  const Integer & GetModulus() const {return m_p;}
176 
177 private:
179 };
180 
183 {
184 public:
186 
187  // DL_FixedBasePrecomputation
188  bool IsInitialized() const {return m_g.NotZero();}
189  void SetBase(const DL_GroupPrecomputation<Element> &group, const Integer &base)
190  {CRYPTOPP_UNUSED(group); m_g = base;}
191  const Integer & GetBase(const DL_GroupPrecomputation<Element> &group) const
192  {CRYPTOPP_UNUSED(group); return m_g;}
193  void Precompute(const DL_GroupPrecomputation<Element> &group, unsigned int maxExpBits, unsigned int storage)
194  {CRYPTOPP_UNUSED(group); CRYPTOPP_UNUSED(maxExpBits); CRYPTOPP_UNUSED(storage);}
195  void Load(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation)
196  {CRYPTOPP_UNUSED(group); CRYPTOPP_UNUSED(storedPrecomputation);}
197  void Save(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) const
198  {CRYPTOPP_UNUSED(group); CRYPTOPP_UNUSED(storedPrecomputation);}
199  Integer Exponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent) const;
200  Integer CascadeExponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent, const DL_FixedBasePrecomputation<Integer> &pc2, const Integer &exponent2) const
201  {
202  CRYPTOPP_UNUSED(group); CRYPTOPP_UNUSED(exponent); CRYPTOPP_UNUSED(pc2); CRYPTOPP_UNUSED(exponent2);
203  // shouldn't be called
204  throw NotImplemented("DL_BasePrecomputation_LUC: CascadeExponentiate not implemented");
205  }
206 
207 private:
209 };
210 
213 class DL_GroupParameters_LUC : public DL_GroupParameters_IntegerBasedImpl<DL_GroupPrecomputation_LUC, DL_BasePrecomputation_LUC>
214 {
215 public:
217 
218  // DL_GroupParameters
219  bool IsIdentity(const Integer &element) const {return element == Integer::Two();}
220  void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const;
221  Element MultiplyElements(const Element &a, const Element &b) const
222  {
224  throw NotImplemented("LUC_GroupParameters: MultiplyElements can not be implemented");
225  }
226  Element CascadeExponentiate(const Element &element1, const Integer &exponent1, const Element &element2, const Integer &exponent2) const
227  {
228  CRYPTOPP_UNUSED(element1); CRYPTOPP_UNUSED(exponent1); CRYPTOPP_UNUSED(element2); CRYPTOPP_UNUSED(exponent2);
229  throw NotImplemented("LUC_GroupParameters: MultiplyElements can not be implemented");
230  }
231 
232  // NameValuePairs interface
233  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
234  {
235  return GetValueHelper<DL_GroupParameters_IntegerBased>(this, name, valueType, pValue).Assignable();
236  }
237 
238 private:
239  int GetFieldType() const {return 2;}
240 };
241 
245 {
246 public:
248 
249 protected:
250  unsigned int GetDefaultSubgroupOrderSize(unsigned int modulusSize) const {return modulusSize-1;}
251 };
252 
256 {
257 public:
258  CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "LUC-HMP";}
259 
261 
262  void Sign(const DL_GroupParameters<Integer> &params, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const;
263  bool Verify(const DL_GroupParameters<Integer> &params, const DL_PublicKey<Integer> &publicKey, const Integer &e, const Integer &r, const Integer &s) const;
264 
265  size_t RLen(const DL_GroupParameters<Integer> &params) const
266  {return params.GetGroupOrder().ByteCount();}
267 };
268 
271 {
275 };
276 
282 template <class H>
283 struct LUC_HMP : public DL_SS<DL_SignatureKeys_LUC, DL_Algorithm_LUC_HMP, DL_SignatureMessageEncodingMethod_DSA, H>
284 {
285 };
286 
289 {
293 };
294 
302 template <class HASH = SHA1, class COFACTOR_OPTION = NoCofactorMultiplication, bool DHAES_MODE = true, bool LABEL_OCTETS = false>
303 struct LUC_IES
304  : public DL_ES<
305  DL_CryptoKeys_LUC,
306  DL_KeyAgreementAlgorithm_DH<Integer, COFACTOR_OPTION>,
307  DL_KeyDerivationAlgorithm_P1363<Integer, DHAES_MODE, P1363_KDF2<HASH> >,
308  DL_EncryptionAlgorithm_Xor<HMAC<HASH>, DHAES_MODE, LABEL_OCTETS>,
309  LUC_IES<> >
310 {
311  CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "LUC-IES";} // non-standard name
312 };
313 
314 // ********************************************************
315 
318 
320 
321 #if CRYPTOPP_MSC_VERSION
322 # pragma warning(pop)
323 #endif
324 
325 #endif
virtual ~DL_GroupPrecomputation_LUC()
Definition: luc.h:167
NoCofactorMultiplication DefaultCofactorOption
Definition: luc.h:247
DL_PrivateKey_GFP< GroupParameters > PrivateKey
Definition: luc.h:274
void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits, const Integer &eStart=17)
Create a LUC private key.
Definition: luc.cpp:134
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
Definition: luc.cpp:111
const Integer & GetModulus() const
Definition: luc.h:61
Trapdoor Function (TF) encryption scheme.
Definition: pubkey.h:2078
#define CRYPTOPP_STATIC_CONSTEXPR
Definition: config.h:892
const Integer & GetModulus() const
Definition: luc.h:175
LUC signature keys.
Definition: luc.h:270
LUC HMP signature algorithm.
Definition: luc.h:255
DL_GroupParameters_LUC GroupParameters
Definition: luc.h:272
LUCFunction ThisClass
Definition: luc.h:38
InvertibleLUCFunction ThisClass
Definition: luc.h:77
void Precompute(const DL_GroupPrecomputation< Element > &group, unsigned int maxExpBits, unsigned int storage)
Definition: luc.h:193
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
Definition: luc.h:303
Converts an enumeration to a type suitable for use as a template parameter.
Definition: cryptlib.h:116
LUCSS< PKCS1v15, SHA >::Signer LUCSSA_PKCS1v15_SHA_Signer
Definition: luc.h:158
DL_PublicKey_GFP< GroupParameters > PublicKey
Definition: luc.h:291
Abstract base classes that provide a uniform interface to this library.
const Integer & GetBase(const DL_GroupPrecomputation< Element > &group) const
Definition: luc.h:191
LUC GroupParameters specialization.
Definition: luc.h:213
bool IsInitialized() const
Definition: luc.h:188
LUCES< OAEP< SHA > >::Encryptor LUCES_OAEP_SHA_Encryptor
Definition: luc.h:156
LUCES< OAEP< SHA > >::Decryptor LUCES_OAEP_SHA_Decryptor
Definition: luc.h:155
virtual ~DL_BasePrecomputation_LUC()
Definition: luc.h:185
const Integer & GetMultiplicativeInverseOfPrime2ModPrime1() const
Definition: luc.h:116
void DEREncodeElement(BufferedTransformation &bt, const Element &v) const
Definition: luc.h:171
Integer m_e
Definition: luc.h:68
Interface for random number generators.
Definition: cryptlib.h:1188
LUC Integrated Encryption Scheme.
Definition: luc.h:126
Discrete Log (DL) encryption scheme.
Definition: pubkey.h:2155
Integer PreimageBound() const
Returns the maximum size of a message before the trapdoor function is applied.
Definition: luc.h:53
Classes for performing mathematics over different fields.
Interface for buffered transformations.
Definition: cryptlib.h:1352
Interface for private keys.
Definition: cryptlib.h:2186
bool IsIdentity(const Integer &element) const
Determines if an element is an identity.
Definition: luc.h:219
Interface for Discrete Log (DL) public keys.
Definition: pubkey.h:992
LUC encryption keys.
Definition: luc.h:288
const Integer & GetPublicExponent() const
Definition: luc.h:62
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
Definition: luc.cpp:197
GF(p) group parameters that default to safe primes.
Definition: luc.h:244
Discrete Log (DL) signature scheme.
Definition: pubkey.h:2132
size_t RLen(const DL_GroupParameters< Integer > &params) const
Definition: luc.h:265
Classes and functions for secure memory allocations.
Integer m_n
Definition: luc.h:68
void SetModulus(const Integer &v)
Definition: luc.h:174
void SetBase(const DL_GroupPrecomputation< Element > &group, const Integer &base)
Definition: luc.h:189
const Integer & GetPrime1() const
Definition: luc.h:114
Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const
Calculates the inverse of an element.
Definition: luc.cpp:169
#define a(i)
Applies the inverse of the trapdoor function.
Definition: pubkey.h:183
LUC signature scheme with appendix.
Definition: luc.h:150
#define x(i)
Classes for PKCS padding schemes.
const Integer & GetPrime2() const
Definition: luc.h:115
const char * source
Definition: rpcconsole.cpp:60
A method was called which was not implemented.
Definition: cryptlib.h:205
CRYPTOPP_STATIC_CONSTEXPR const char * StaticAlgorithmName()
Definition: luc.h:258
LUC cryptosystem.
Definition: luc.h:139
Interface for Elgamal-like signature algorithms.
Definition: pubkey.h:1257
Classes for Diffie-Hellman key exchange.
const char * name
Definition: rest.cpp:36
const AbstractGroup< Element > & GetGroup() const
Definition: luc.h:169
bool Validate(int, bool, const char *)
Definition: test.cpp:884
Multiple precision integer with arithmetic operations.
Definition: integer.h:43
Integer-based GroupParameters default implementation.
Definition: gfpcrypt.h:120
virtual ~LUCFunction()
Definition: luc.h:41
static const Integer &CRYPTOPP_API Two()
Integer representing 2.
Definition: integer.cpp:3043
Applies the trapdoor function.
Definition: pubkey.h:128
Classes and functions for schemes based on Discrete Logs (DL) over GF(p)
DL_GroupParameters_LUC_DefaultSafePrime GroupParameters
Definition: luc.h:290
int GetFieldType() const
Definition: luc.h:239
#define b(i, j)
#define CRYPTOPP_ASSERT(exp)
Definition: trap.h:92
Diffie-Hellman domain.
Definition: dh.h:25
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:233
The LUC inverse function.
Definition: luc.h:75
Discrete Log (DL) public key in GF(p) groups.
Definition: gfpcrypt.h:475
Element CascadeExponentiate(const Element &element1, const Integer &exponent1, const Element &element2, const Integer &exponent2) const
Definition: luc.h:226
void Load(const DL_GroupPrecomputation< Element > &group, BufferedTransformation &storedPrecomputation)
Definition: luc.h:195
void DEREncode(BufferedTransformation &bt) const
Encode in DER format.
Definition: integer.cpp:3391
void DEREncode(BufferedTransformation &bt) const
Definition: luc.cpp:155
Integer CascadeExponentiate(const DL_GroupPrecomputation< Element > &group, const Integer &exponent, const DL_FixedBasePrecomputation< Integer > &pc2, const Integer &exponent2) const
Definition: luc.h:200
void SetPrime2(const Integer &q)
Definition: luc.h:119
static std::string StaticAlgorithmName()
Definition: luc.h:128
LUC-HMP, based on "Digital signature schemes based on Lucas functions" by Patrick Horster...
Definition: luc.h:283
DL_PublicKey_GFP< GroupParameters > PublicKey
Definition: luc.h:273
Discrete Log (DL) private key in GF(p) groups.
Definition: gfpcrypt.h:512
#define CRYPTOPP_UNUSED(x)
Definition: config.h:741
virtual ~DL_GroupParameters_LUC()
Definition: luc.h:216
void SetPrime1(const Integer &p)
Definition: luc.h:118
CRYPTOPP_STATIC_CONSTEXPR const char * StaticAlgorithmName()
Definition: luc.h:311
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
Definition: luc.cpp:206
void Initialize(const Integer &n, const Integer &e, const Integer &p, const Integer &q, const Integer &u)
Initialize a LUC private key with {n,e,p,q,dp,dq,u}.
Definition: luc.h:99
Element MultiplyElements(const Element &a, const Element &b) const
Definition: luc.h:221
Multiple precision integer with arithmetic operations.
void BERDecode(BufferedTransformation &bt)
Definition: luc.cpp:139
#define NAMESPACE_END
Definition: config.h:201
The LUC function.
Definition: luc.h:36
void SetPublicExponent(const Integer &e)
Definition: luc.h:65
#define e(i)
Definition: sha.cpp:733
Interface for public keys.
Definition: cryptlib.h:2181
Integer ImageBound() const
Returns the maximum size of a message after the trapdoor function is applied.
Definition: luc.h:54
LUCFunction PublicKey
Definition: luc.h:129
void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u)
Definition: luc.h:120
Element BERDecodeElement(BufferedTransformation &bt) const
Definition: luc.h:170
DL_PrivateKey_GFP< GroupParameters > PrivateKey
Definition: luc.h:292
LUCSS< PKCS1v15, SHA >::Verifier LUCSSA_PKCS1v15_SHA_Verifier
Definition: luc.h:159
virtual ~InvertibleLUCFunction()
Definition: luc.h:80
DH_Domain< DL_GroupParameters_LUC_DefaultSafePrime > LUC_DH
LUC-DH.
Definition: luc.h:317
void Save(const DL_GroupPrecomputation< Element > &group, BufferedTransformation &storedPrecomputation) const
Definition: luc.h:197
InvertibleLUCFunction PrivateKey
Definition: luc.h:130
unsigned int GetDefaultSubgroupOrderSize(unsigned int modulusSize) const
Definition: luc.h:250
unsigned int ByteCount() const
Determines the number of bytes required to represent the Integer.
Definition: integer.cpp:3296
virtual ~DL_Algorithm_LUC_HMP()
Definition: luc.h:260
void SetModulus(const Integer &n)
Definition: luc.h:64
virtual Integer GetGroupOrder() const
Retrieves the order of the group.
Definition: pubkey.h:843
void Initialize(const Integer &n, const Integer &e)
Initialize a LUC public key with {n,e}.
Definition: luc.h:46
Interface for retrieving values given their names.
Definition: cryptlib.h:279
Template implementing constructors for public key algorithm classes.
Definition: pubkey.h:1989
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:2105