- Main Page
- Namespaces
- Classes
- Files

# luc.h

Go to the documentation of this file.

    00001 #ifndef CRYPTOPP_LUC_H
    00002 #define CRYPTOPP_LUC_H
    00003
    00004 /** \file
    00005 */
    00006
    00007 #include "pkcspad.h"
    00008 #include "oaep.h"
    00009 #include "integer.h"
    00010 #include "dh.h"
    00011
    00012 #include <limits.h>
    00013
    00014 NAMESPACE_BEGIN(CryptoPP)
    00015
    00016 //! The LUC function.
    00017 /*! This class is here for historical and pedagogical interest. It has no
    00018         practical advantages over other trapdoor functions and probably shouldn't
    00019         be used in production software. The discrete log based LUC schemes
    00020         defined later in this .h file may be of more practical interest.
    00021 */
    00022 class LUCFunction : public TrapdoorFunction, public PublicKey
    00023 {
    00024         typedef LUCFunction ThisClass;
    00025
    00026 public:
    00027         void Initialize(const Integer &n, const Integer &e)
    00028                 {m_n = n; m_e = e;}
    00029
    00030         void BERDecode(BufferedTransformation &bt);
    00031         void DEREncode(BufferedTransformation &bt) const;
    00032
    00033         Integer ApplyFunction(const Integer &x) const;
    00034         Integer PreimageBound() const {return m_n;}
    00035         Integer ImageBound() const {return m_n;}
    00036
    00037         bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
    00038         bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
    00039         void AssignFrom(const NameValuePairs &source);
    00040
    00041         // non-derived interface
    00042         const Integer & GetModulus() const {return m_n;}
    00043         const Integer & GetPublicExponent() const {return m_e;}
    00044
    00045         void SetModulus(const Integer &n) {m_n = n;}
    00046         void SetPublicExponent(const Integer &e) {m_e = e;}
    00047
    00048 protected:
    00049         Integer m_n, m_e;
    00050 };
    00051
    00052 //! _
    00053 class InvertibleLUCFunction : public LUCFunction, public TrapdoorFunctionInverse, public PrivateKey
    00054 {
    00055         typedef InvertibleLUCFunction ThisClass;
    00056
    00057 public:
    00058         void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits, const Integer &eStart=17);
    00059         void Initialize(const Integer &n, const Integer &e, const Integer &p, const Integer &q, const Integer &u)
    00060                 {m_n = n; m_e = e; m_p = p; m_q = q; m_u = u;}
    00061
    00062         void BERDecode(BufferedTransformation &bt);
    00063         void DEREncode(BufferedTransformation &bt) const;
    00064
    00065         Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const;
    00066
    00067         bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
    00068         bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
    00069         void AssignFrom(const NameValuePairs &source);
    00070         /*! parameters: (ModulusSize, PublicExponent (default 17)) */
    00071         void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
    00072
    00073         // non-derived interface
    00074         const Integer& GetPrime1() const {return m_p;}
    00075         const Integer& GetPrime2() const {return m_q;}
    00076         const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;}
    00077
    00078         void SetPrime1(const Integer &p) {m_p = p;}
    00079         void SetPrime2(const Integer &q) {m_q = q;}
    00080         void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;}
    00081
    00082 protected:
    00083         Integer m_p, m_q, m_u;
    00084 };
    00085
    00086 struct LUC
    00087 {
    00088         static std::string StaticAlgorithmName() {return "LUC";}
    00089         typedef LUCFunction PublicKey;
    00090         typedef InvertibleLUCFunction PrivateKey;
    00091 };
    00092
    00093 //! LUC cryptosystem
    00094 template <class STANDARD>
    00095 struct LUCES : public TF_ES<STANDARD, LUC>
    00096 {
    00097 };
    00098
    00099 //! LUC signature scheme with appendix
    00100 template <class STANDARD, class H>
    00101 struct LUCSS : public TF_SS<STANDARD, H, LUC>
    00102 {
    00103 };
    00104
    00105 // analagous to the RSA schemes defined in PKCS #1 v2.0
    00106 typedef LUCES<OAEP<SHA> >::Decryptor LUCES_OAEP_SHA_Decryptor;
    00107 typedef LUCES<OAEP<SHA> >::Encryptor LUCES_OAEP_SHA_Encryptor;
    00108
    00109 typedef LUCSS<PKCS1v15, SHA>::Signer LUCSSA_PKCS1v15_SHA_Signer;
    00110 typedef LUCSS<PKCS1v15, SHA>::Verifier LUCSSA_PKCS1v15_SHA_Verifier;
    00111
    00112 // ********************************************************
    00113
    00114 // no actual precomputation
    00115 class DL_GroupPrecomputation_LUC : public DL_GroupPrecomputation<Integer>
    00116 {
    00117 public:
    00118         const AbstractGroup<Element> & GetGroup() const {assert(false); throw 0;}
    00119         Element BERDecodeElement(BufferedTransformation &bt) const {return Integer(bt);}
    00120         void DEREncodeElement(BufferedTransformation &bt, const Element &v) const {v.DEREncode(bt);}
    00121
    00122         // non-inherited
    00123         void SetModulus(const Integer &v) {m_p = v;}
    00124         const Integer & GetModulus() const {return m_p;}
    00125
    00126 private:
    00127         Integer m_p;
    00128 };
    00129
    00130 //! _
    00131 class DL_BasePrecomputation_LUC : public DL_FixedBasePrecomputation<Integer>
    00132 {
    00133 public:
    00134         // DL_FixedBasePrecomputation
    00135         bool IsInitialized() const {return m_g.NotZero();}
    00136         void SetBase(const DL_GroupPrecomputation<Element> &group, const Integer &base) {m_g = base;}
    00137         const Integer & GetBase(const DL_GroupPrecomputation<Element> &group) const {return m_g;}
    00138         void Precompute(const DL_GroupPrecomputation<Element> &group, unsigned int maxExpBits, unsigned int storage) {}
    00139         void Load(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) {}
    00140         void Save(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) const {}
    00141         Integer Exponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent) const;
    00142         Integer CascadeExponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent, const DL_FixedBasePrecomputation<Integer> &pc2, const Integer &exponent2) const
    00143                 {throw NotImplemented("DL_BasePrecomputation_LUC: CascadeExponentiate not implemented");}       // shouldn't be called
    00144
    00145 private:
    00146         Integer m_g;
    00147 };
    00148
    00149 //! _
    00150 class DL_GroupParameters_LUC : public DL_GroupParameters_IntegerBasedImpl<DL_GroupPrecomputation_LUC, DL_BasePrecomputation_LUC>
    00151 {
    00152 public:
    00153         // DL_GroupParameters
    00154         bool IsIdentity(const Integer &element) const {return element == Integer::Two();}
    00155         void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const;
    00156         Element MultiplyElements(const Element &a, const Element &b) const
    00157                 {throw NotImplemented("LUC_GroupParameters: MultiplyElements can not be implemented");}
    00158         Element CascadeExponentiate(const Element &element1, const Integer &exponent1, const Element &element2, const Integer &exponent2) const
    00159                 {throw NotImplemented("LUC_GroupParameters: MultiplyElements can not be implemented");}
    00160
    00161         // NameValuePairs interface
    00162         bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
    00163         {
    00164                 return GetValueHelper<DL_GroupParameters_IntegerBased>(this, name, valueType, pValue).Assignable();
    00165         }
    00166
    00167 private:
    00168         int GetFieldType() const {return 2;}
    00169 };
    00170
    00171 //! _
    00172 class DL_GroupParameters_LUC_DefaultSafePrime : public DL_GroupParameters_LUC
    00173 {
    00174 public:
    00175         typedef NoCofactorMultiplication DefaultCofactorOption;
    00176
    00177 protected:
    00178         unsigned int GetDefaultSubgroupOrderSize(unsigned int modulusSize) const {return modulusSize-1;}
    00179 };
    00180
    00181 //! _
    00182 class DL_Algorithm_LUC_HMP : public DL_ElgamalLikeSignatureAlgorithm<Integer>
    00183 {
    00184 public:
    00185         static const char * StaticAlgorithmName() {return "LUC-HMP";}
    00186
    00187         void Sign(const DL_GroupParameters<Integer> &params, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const;
    00188         bool Verify(const DL_GroupParameters<Integer> &params, const DL_PublicKey<Integer> &publicKey, const Integer &e, const Integer &r, const Integer &s) const;
    00189
    00190         size_t RLen(const DL_GroupParameters<Integer> &params) const
    00191                 {return params.GetGroupOrder().ByteCount();}
    00192 };
    00193
    00194 //! _
    00195 struct DL_SignatureKeys_LUC
    00196 {
    00197         typedef DL_GroupParameters_LUC GroupParameters;
    00198         typedef DL_PublicKey_GFP<GroupParameters> PublicKey;
    00199         typedef DL_PrivateKey_GFP<GroupParameters> PrivateKey;
    00200 };
    00201
    00202 //! LUC-HMP, based on "Digital signature schemes based on Lucas functions" by Patrick Horster, Markus Michels, Holger Petersen
    00203 template <class H>
    00204 struct LUC_HMP : public DL_SS<DL_SignatureKeys_LUC, DL_Algorithm_LUC_HMP, DL_SignatureMessageEncodingMethod_DSA, H>
    00205 {
    00206 };
    00207
    00208 //! _
    00209 struct DL_CryptoKeys_LUC
    00210 {
    00211         typedef DL_GroupParameters_LUC_DefaultSafePrime GroupParameters;
    00212         typedef DL_PublicKey_GFP<GroupParameters> PublicKey;
    00213         typedef DL_PrivateKey_GFP<GroupParameters> PrivateKey;
    00214 };
    00215
    00216 //! LUC-IES
    00217 template <class COFACTOR_OPTION = NoCofactorMultiplication, bool DHAES_MODE = true>
    00218 struct LUC_IES
    00219         : public DL_ES<
    00220                 DL_CryptoKeys_LUC,
    00221                 DL_KeyAgreementAlgorithm_DH<Integer, COFACTOR_OPTION>,
    00222                 DL_KeyDerivationAlgorithm_P1363<Integer, DHAES_MODE, P1363_KDF2<SHA1> >,
    00223                 DL_EncryptionAlgorithm_Xor<HMAC<SHA1>, DHAES_MODE>,
    00224                 LUC_IES<> >
    00225 {
    00226         static std::string StaticAlgorithmName() {return "LUC-IES";}    // non-standard name
    00227 };
    00228
    00229 // ********************************************************
    00230
    00231 //! LUC-DH
    00232 typedef DH_Domain<DL_GroupParameters_LUC_DefaultSafePrime> LUC_DH;
    00233
    00234 NAMESPACE_END
    00235
    00236 #endif