Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# esign.h

Go to the documentation of this file.

    00001 #ifndef CRYPTOPP_ESIGN_H
    00002 #define CRYPTOPP_ESIGN_H
    00003
    00004 /** \file
    00005         This file contains classes that implement the
    00006         ESIGN signature schemes as defined in IEEE P1363a.
    00007 */
    00008
    00009 #include "pubkey.h"
    00010 #include "integer.h"
    00011
    00012 NAMESPACE_BEGIN(CryptoPP)
    00013
    00014 //! .
    00015 class ESIGNFunction : public TrapdoorFunction, public PublicKey, public ASN1CryptoMaterial
    00016 {
    00017         typedef ESIGNFunction ThisClass;
    00018
    00019 public:
    00020         void Initialize(const Integer &n, const Integer &e)
    00021                 {m_n = n; m_e = e;}
    00022
    00023         // PublicKey
    00024         void BERDecode(BufferedTransformation &bt);
    00025         void DEREncode(BufferedTransformation &bt) const;
    00026
    00027         // CryptoMaterial
    00028         bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
    00029         bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
    00030         void AssignFrom(const NameValuePairs &source);
    00031
    00032         // TrapdoorFunction
    00033         Integer ApplyFunction(const Integer &x) const;
    00034         Integer PreimageBound() const {return m_n;}
    00035         Integer ImageBound() const {return Integer::Power2(GetK());}
    00036
    00037         // non-derived
    00038         const Integer & GetModulus() const {return m_n;}
    00039         const Integer & GetPublicExponent() const {return m_e;}
    00040
    00041         void SetModulus(const Integer &n) {m_n = n;}
    00042         void SetPublicExponent(const Integer &e) {m_e = e;}
    00043
    00044 protected:
    00045         unsigned int GetK() const {return m_n.BitCount()/3-1;}
    00046
    00047         Integer m_n, m_e;
    00048 };
    00049
    00050 //! .
    00051 class InvertibleESIGNFunction : public ESIGNFunction, public RandomizedTrapdoorFunctionInverse, public PrivateKey
    00052 {
    00053         typedef InvertibleESIGNFunction ThisClass;
    00054
    00055 public:
    00056         void Initialize(const Integer &n, const Integer &e, const Integer &p, const Integer &q)
    00057                 {m_n = n; m_e = e; m_p = p; m_q = q;}
    00058         // generate a random private key
    00059         void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
    00060                 {GenerateRandomWithKeySize(rng, modulusBits);}
    00061
    00062         void BERDecode(BufferedTransformation &bt);
    00063         void DEREncode(BufferedTransformation &bt) const;
    00064
    00065         Integer CalculateRandomizedInverse(RandomNumberGenerator &rng, const Integer &x) const;
    00066
    00067         // GeneratibleCryptoMaterial
    00068         bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
    00069         bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
    00070         void AssignFrom(const NameValuePairs &source);
    00071         /*! parameters: (ModulusSize) */
    00072         void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
    00073
    00074         const Integer& GetPrime1() const {return m_p;}
    00075         const Integer& GetPrime2() const {return m_q;}
    00076
    00077         void SetPrime1(const Integer &p) {m_p = p;}
    00078         void SetPrime2(const Integer &q) {m_q = q;}
    00079
    00080 protected:
    00081         Integer m_p, m_q;
    00082 };
    00083
    00084 //! .
    00085 template <class T>
    00086 class EMSA5Pad : public PK_NonreversiblePaddingAlgorithm
    00087 {
    00088 public:
    00089         static const char *StaticAlgorithmName() {return "EMSA5";}
    00090
    00091         unsigned int MaxUnpaddedLength(unsigned int paddedLength) const {return UINT_MAX;}
    00092
    00093         void Pad(RandomNumberGenerator &rng, const byte *raw, unsigned int inputLength, byte *padded, unsigned int paddedLength) const
    00094         {
    00095                 unsigned int paddedByteLength = BitsToBytes(paddedLength);
    00096                 memset(padded, 0, paddedByteLength);
    00097                 T::GenerateAndMask(padded, paddedByteLength, raw, inputLength);
    00098                 if (paddedLength % 8 != 0)
    00099                         padded[0] = (byte)Crop(padded[0], paddedLength % 8);
    00100         }
    00101 };
    00102
    00103 //! EMSA5, for use with ESIGN
    00104 struct P1363_EMSA5 : public SignatureStandard
    00105 {
    00106         template <class H> struct SignaturePaddingAlgorithm {typedef EMSA5Pad<P1363_MGF1<H> > type;};
    00107         template <class H> struct DecoratedHashingAlgorithm {typedef H type;};
    00108 };
    00109
    00110 template<> struct CryptoStandardTraits<P1363_EMSA5> : public P1363_EMSA5 {};
    00111
    00112 struct ESIGN_Keys
    00113 {
    00114         static std::string StaticAlgorithmName() {return "ESIGN";}
    00115         typedef ESIGNFunction PublicKey;
    00116         typedef InvertibleESIGNFunction PrivateKey;
    00117 };
    00118
    00119 //! ESIGN, as defined in IEEE P1363a
    00120 template <class H, class STANDARD = P1363_EMSA5>
    00121 struct ESIGN : public TF_SSA<STANDARD, H, ESIGN_Keys>
    00122 {
    00123 };
    00124
    00125 NAMESPACE_END
    00126
    00127 #endif