Go to the documentation of this file.00001 #ifndef CRYPTOPP_ESIGN_H
00002 #define CRYPTOPP_ESIGN_H
00003
00004
00005
00006
00007
00008
00009 #include "pubkey.h"
00010 #include "integer.h"
00011 #include "asn.h"
00012
00013 NAMESPACE_BEGIN(CryptoPP)
00014
00015
00016 class ESIGNFunction : public TrapdoorFunction, public ASN1CryptoMaterial<PublicKey>
00017 {
00018 typedef ESIGNFunction ThisClass;
00019
00020 public:
00021 void Initialize(const Integer &n, const Integer &e)
00022 {m_n = n; m_e = e;}
00023
00024
00025 void BERDecode(BufferedTransformation &bt);
00026 void DEREncode(BufferedTransformation &bt) const;
00027
00028
00029 bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
00030 bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
00031 void AssignFrom(const NameValuePairs &source);
00032
00033
00034 Integer ApplyFunction(const Integer &x) const;
00035 Integer PreimageBound() const {return m_n;}
00036 Integer ImageBound() const {return Integer::Power2(GetK());}
00037
00038
00039 const Integer & GetModulus() const {return m_n;}
00040 const Integer & GetPublicExponent() const {return m_e;}
00041
00042 void SetModulus(const Integer &n) {m_n = n;}
00043 void SetPublicExponent(const Integer &e) {m_e = e;}
00044
00045 protected:
00046 unsigned int GetK() const {return m_n.BitCount()/3-1;}
00047
00048 Integer m_n, m_e;
00049 };
00050
00051
00052 class InvertibleESIGNFunction : public ESIGNFunction, public RandomizedTrapdoorFunctionInverse, public PrivateKey
00053 {
00054 typedef InvertibleESIGNFunction ThisClass;
00055
00056 public:
00057 void Initialize(const Integer &n, const Integer &e, const Integer &p, const Integer &q)
00058 {m_n = n; m_e = e; m_p = p; m_q = q;}
00059
00060 void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
00061 {GenerateRandomWithKeySize(rng, modulusBits);}
00062
00063 void BERDecode(BufferedTransformation &bt);
00064 void DEREncode(BufferedTransformation &bt) const;
00065
00066 Integer CalculateRandomizedInverse(RandomNumberGenerator &rng, const Integer &x) const;
00067
00068
00069 bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
00070 bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
00071 void AssignFrom(const NameValuePairs &source);
00072
00073 void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
00074
00075 const Integer& GetPrime1() const {return m_p;}
00076 const Integer& GetPrime2() const {return m_q;}
00077
00078 void SetPrime1(const Integer &p) {m_p = p;}
00079 void SetPrime2(const Integer &q) {m_q = q;}
00080
00081 protected:
00082 Integer m_p, m_q;
00083 };
00084
00085
00086 template <class T>
00087 class EMSA5Pad : public PK_DeterministicSignatureMessageEncodingMethod
00088 {
00089 public:
00090 static const char *StaticAlgorithmName() {return "EMSA5";}
00091
00092 void ComputeMessageRepresentative(RandomNumberGenerator &rng,
00093 const byte *recoverableMessage, size_t recoverableMessageLength,
00094 HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
00095 byte *representative, size_t representativeBitLength) const
00096 {
00097 SecByteBlock digest(hash.DigestSize());
00098 hash.Final(digest);
00099 size_t representativeByteLength = BitsToBytes(representativeBitLength);
00100 T mgf;
00101 mgf.GenerateAndMask(hash, representative, representativeByteLength, digest, digest.size(), false);
00102 if (representativeBitLength % 8 != 0)
00103 representative[0] = (byte)Crop(representative[0], representativeBitLength % 8);
00104 }
00105 };
00106
00107
00108 struct P1363_EMSA5 : public SignatureStandard
00109 {
00110 typedef EMSA5Pad<P1363_MGF1> SignatureMessageEncodingMethod;
00111 };
00112
00113 struct ESIGN_Keys
00114 {
00115 static std::string StaticAlgorithmName() {return "ESIGN";}
00116 typedef ESIGNFunction PublicKey;
00117 typedef InvertibleESIGNFunction PrivateKey;
00118 };
00119
00120
00121 template <class H, class STANDARD = P1363_EMSA5>
00122 struct ESIGN : public TF_SS<STANDARD, H, ESIGN_Keys>
00123 {
00124 };
00125
00126 NAMESPACE_END
00127
00128 #endif