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
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
00024
void BERDecode(
BufferedTransformation &bt);
00025
void DEREncode(
BufferedTransformation &bt)
const;
00026
00027
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
00033
Integer ApplyFunction(
const Integer &x)
const;
00034
Integer PreimageBound()
const {
return m_n;}
00035
Integer ImageBound()
const {
return Integer::Power2(GetK());}
00036
00037
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
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
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
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_DeterministicSignatureMessageEncodingMethod
00087 {
00088
public:
00089
static const char *StaticAlgorithmName() {
return "EMSA5";}
00090
00091
void ComputeMessageRepresentative(
RandomNumberGenerator &rng,
00092
const byte *recoverableMessage,
unsigned int recoverableMessageLength,
00093
HashTransformation &hash, HashIdentifier hashIdentifier,
bool messageEmpty,
00094 byte *representative,
unsigned int representativeBitLength)
const
00095
{
00096
SecByteBlock digest(hash.
DigestSize());
00097 hash.
Final(digest);
00098
unsigned int representativeByteLength = BitsToBytes(representativeBitLength);
00099 T mgf;
00100 mgf.GenerateAndMask(hash, representative, representativeByteLength, digest, digest.size(),
false);
00101
if (representativeBitLength % 8 != 0)
00102 representative[0] = (byte)Crop(representative[0], representativeBitLength % 8);
00103 }
00104 };
00105
00106
00107 struct P1363_EMSA5 :
public SignatureStandard
00108 {
00109
typedef EMSA5Pad<P1363_MGF1> SignatureMessageEncodingMethod;
00110 };
00111
00112
struct ESIGN_Keys
00113 {
00114
static std::string StaticAlgorithmName() {
return "ESIGN";}
00115
typedef ESIGNFunction PublicKey;
00116
typedef InvertibleESIGNFunction PrivateKey;
00117 };
00118
00119
00120 template <
class H,
class STANDARD = P1363_EMSA5>
00121
struct ESIGN :
public TF_SS<STANDARD, H, ESIGN_Keys>
00122 {
00123 };
00124
00125 NAMESPACE_END
00126
00127
#endif