#ifndef CRYPTOPP_LUC_H #define CRYPTOPP_LUC_H /** \file */ #include "pkcspad.h" #include "oaep.h" #include "integer.h" #include "dh.h" #include NAMESPACE_BEGIN(CryptoPP) //! . class LUCFunction : public TrapdoorFunction, public PublicKey { typedef LUCFunction ThisClass; public: void Initialize(const Integer &n, const Integer &e) {m_n = n; m_e = e;} void BERDecode(BufferedTransformation &bt); void DEREncode(BufferedTransformation &bt) const; Integer ApplyFunction(const Integer &x) const; Integer PreimageBound() const {return m_n;} Integer ImageBound() const {return m_n;} bool Validate(RandomNumberGenerator &rng, unsigned int level) const; bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; void AssignFrom(const NameValuePairs &source); // non-derived interface const Integer & GetModulus() const {return m_n;} const Integer & GetPublicExponent() const {return m_e;} void SetModulus(const Integer &n) {m_n = n;} void SetPublicExponent(const Integer &e) {m_e = e;} protected: Integer m_n, m_e; }; //! . class InvertibleLUCFunction : public LUCFunction, public TrapdoorFunctionInverse, public PrivateKey { typedef InvertibleLUCFunction ThisClass; public: void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits, const Integer &eStart=17); void Initialize(const Integer &n, const Integer &e, const Integer &p, const Integer &q, const Integer &u) {m_n = n; m_e = e; m_p = p; m_q = q; m_u = u;} void BERDecode(BufferedTransformation &bt); void DEREncode(BufferedTransformation &bt) const; Integer CalculateInverse(const Integer &x) const; bool Validate(RandomNumberGenerator &rng, unsigned int level) const; bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; void AssignFrom(const NameValuePairs &source); /*! parameters: (ModulusSize, PublicExponent (default 17)) */ void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg); // non-derived interface const Integer& GetPrime1() const {return m_p;} const Integer& GetPrime2() const {return m_q;} const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;} void SetPrime1(const Integer &p) {m_p = p;} void SetPrime2(const Integer &q) {m_q = q;} void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;} protected: Integer m_p, m_q, m_u; }; struct LUC { static std::string StaticAlgorithmName() {return "LUC";} typedef LUCFunction PublicKey; typedef InvertibleLUCFunction PrivateKey; }; //! LUC cryptosystem template struct LUCES : public TF_ES { }; //! LUC signature scheme with appendix template struct LUCSSA : public TF_SSA { }; // analagous to the RSA schemes defined in PKCS #1 v2.0 typedef LUCES >::Decryptor LUCES_OAEP_SHA_Decryptor; typedef LUCES >::Encryptor LUCES_OAEP_SHA_Encryptor; typedef LUCSSA::Signer LUCSSA_PKCS1v15_SHA_Signer; typedef LUCSSA::Verifier LUCSSA_PKCS1v15_SHA_Verifier; // ******************************************************** // no actual precomputation class DL_GroupPrecomputation_LUC : public DL_GroupPrecomputation { public: const AbstractGroup & GetGroup() const {assert(false); throw 0;} Element BERDecodeElement(BufferedTransformation &bt) const {return Integer(bt);} void DEREncodeElement(BufferedTransformation &bt, const Element &v) const {v.DEREncode(bt);} // non-inherited void SetModulus(const Integer &v) {m_p = v;} const Integer & GetModulus() const {return m_p;} private: Integer m_p; }; //! . class DL_BasePrecomputation_LUC : public DL_FixedBasePrecomputation { public: // DL_FixedBasePrecomputation bool IsInitialized() const {return m_g.NotZero();} void SetBase(const DL_GroupPrecomputation &group, const Integer &base) {m_g = base;} const Integer & GetBase(const DL_GroupPrecomputation &group) const {return m_g;} void Precompute(const DL_GroupPrecomputation &group, unsigned int maxExpBits, unsigned int storage) {} void Load(const DL_GroupPrecomputation &group, BufferedTransformation &storedPrecomputation) {} void Save(const DL_GroupPrecomputation &group, BufferedTransformation &storedPrecomputation) const {} Integer Exponentiate(const DL_GroupPrecomputation &group, const Integer &exponent) const; Integer CascadeExponentiate(const DL_GroupPrecomputation &group, const Integer &exponent, const DL_FixedBasePrecomputation &pc2, const Integer &exponent2) const {throw NotImplemented("DL_BasePrecomputation_LUC: CascadeExponentiate not implemented");} // shouldn't be called private: Integer m_g; }; //! . class DL_GroupParameters_LUC : public DL_GroupParameters_IntegerBasedImpl { public: // DL_GroupParameters bool IsIdentity(const Integer &element) const {return element == Integer::Two();} void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const; Element MultiplyElements(const Element &a, const Element &b) const {throw NotImplemented("LUC_GroupParameters: MultiplyElements can not be implemented");} Element CascadeExponentiate(const Element &element1, const Integer &exponent1, const Element &element2, const Integer &exponent2) const {throw NotImplemented("LUC_GroupParameters: MultiplyElements can not be implemented");} // NameValuePairs interface bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const { return GetValueHelper(this, name, valueType, pValue).Assignable(); } private: int GetFieldType() const {return 2;} }; //! . class DL_GroupParameters_LUC_DefaultSafePrime : public DL_GroupParameters_LUC { public: typedef NoCofactorMultiplication DefaultCofactorOption; protected: unsigned int GetDefaultSubgroupOrderSize(unsigned int modulusSize) const {return modulusSize-1;} }; //! . class DL_Algorithm_LUC_HMP : public DL_ElgamalLikeSignatureAlgorithm { public: static const char * StaticAlgorithmName() {return "LUC-HMP";} Integer EncodeDigest(unsigned int modulusBits, const byte *digest, unsigned int digestLen) const {return DSA_EncodeDigest(modulusBits, digest, digestLen);} bool Sign(const DL_GroupParameters ¶ms, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const; bool Verify(const DL_GroupParameters ¶ms, const DL_PublicKey &publicKey, const Integer &e, const Integer &r, const Integer &s) const; unsigned int RLen(const DL_GroupParameters ¶ms) const {return params.GetGroupOrder().ByteCount();} }; //! . struct DL_SignatureKeys_LUC { typedef DL_GroupParameters_LUC GroupParameters; typedef DL_PublicKey_GFP PublicKey; typedef DL_PrivateKey_GFP PrivateKey; }; //! LUC-HMP, based on "Digital signature schemes based on Lucas functions" by Patrick Horster, Markus Michels, Holger Petersen template struct LUC_HMP : public DL_SSA { }; //! . struct DL_CryptoKeys_LUC { typedef DL_GroupParameters_LUC_DefaultSafePrime GroupParameters; typedef DL_PublicKey_GFP PublicKey; typedef DL_PrivateKey_GFP PrivateKey; }; //! LUC-IES template struct LUC_IES : public DL_ES< DL_CryptoKeys_LUC, DL_KeyAgreementAlgorithm_DH, DL_KeyDerivationAlgorithm_P1363 >, DL_EncryptionAlgorithm_Xor, DHAES_MODE>, LUC_IES<> > { static std::string StaticAlgorithmName() {return "LUC-IES";} // non-standard name }; // ******************************************************** //! LUC-DH typedef DH_Domain LUC_DH; NAMESPACE_END #endif