ext-cryptopp/rw.h

115 lines
3.3 KiB
C
Raw Normal View History

2002-10-04 17:31:41 +00:00
#ifndef CRYPTOPP_RW_H
#define CRYPTOPP_RW_H
/** \file
This file contains classes that implement the
Rabin-Williams signature schemes as defined in IEEE P1363.
*/
#include "integer.h"
2003-03-20 01:24:12 +00:00
#include "pssr.h"
2002-10-04 17:31:41 +00:00
NAMESPACE_BEGIN(CryptoPP)
//! .
class RWFunction : virtual public TrapdoorFunction, public PublicKey
{
typedef RWFunction ThisClass;
public:
void Initialize(const Integer &n)
{m_n = n;}
void BERDecode(BufferedTransformation &bt);
void DEREncode(BufferedTransformation &bt) const;
Integer ApplyFunction(const Integer &x) const;
2003-03-20 03:09:44 +00:00
Integer PreimageBound() const {return ++(m_n>>1);}
Integer ImageBound() const {return m_n;}
2002-10-04 17:31:41 +00:00
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);
const Integer& GetModulus() const {return m_n;}
void SetModulus(const Integer &n) {m_n = n;}
protected:
Integer m_n;
};
//! .
2003-03-20 01:24:12 +00:00
class InvertibleRWFunction : public RWFunction, public TrapdoorFunctionInverse, public PrivateKey
2002-10-04 17:31:41 +00:00
{
typedef InvertibleRWFunction ThisClass;
public:
void Initialize(const Integer &n, const Integer &p, const Integer &q, const Integer &u)
{m_n = n; m_p = p; m_q = q; m_u = u;}
// generate a random private key
void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
{GenerateRandomWithKeySize(rng, modulusBits);}
void BERDecode(BufferedTransformation &bt);
void DEREncode(BufferedTransformation &bt) const;
2003-03-20 01:24:12 +00:00
Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const;
2002-10-04 17:31:41 +00:00
// GeneratibleCryptoMaterial
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) */
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
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;
};
//! .
2003-03-20 01:24:12 +00:00
class EMSA2Pad : public EMSA2HashIdLookup<PK_DeterministicSignatureMessageEncodingMethod>
2002-10-04 17:31:41 +00:00
{
public:
static const char *StaticAlgorithmName() {return "EMSA2";}
unsigned int MaxUnpaddedLength(unsigned int paddedLength) const {return (paddedLength+1)/8-2;}
2003-03-20 01:24:12 +00:00
void ComputeMessageRepresentative(RandomNumberGenerator &rng,
const byte *recoverableMessage, unsigned int recoverableMessageLength,
HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
byte *representative, unsigned int representativeBitLength) const;
2002-10-04 17:31:41 +00:00
};
//! EMSA2, for use with RW
2003-08-25 21:41:09 +00:00
/*! See pssr.h for a list of hash functions supported by this signature standard. */
2002-10-04 17:31:41 +00:00
struct P1363_EMSA2 : public SignatureStandard
{
2003-03-20 01:24:12 +00:00
typedef EMSA2Pad SignatureMessageEncodingMethod;
2002-10-04 17:31:41 +00:00
};
//! .
struct RW
{
static std::string StaticAlgorithmName() {return "RW";}
2003-03-20 01:24:12 +00:00
typedef RWFunction PublicKey;
typedef InvertibleRWFunction PrivateKey;
2002-10-04 17:31:41 +00:00
};
2003-03-20 01:24:12 +00:00
//! RWSS
template <class STANDARD, class H>
struct RWSS : public TF_SS<STANDARD, H, RW>
2002-10-04 17:31:41 +00:00
{
};
NAMESPACE_END
#endif