Crypto++  5.6.5
Free C++ class library of cryptographic schemes
esign.h
Go to the documentation of this file.
1 #ifndef CRYPTOPP_ESIGN_H
2 #define CRYPTOPP_ESIGN_H
3 
4 /** \file
5  This file contains classes that implement the
6  ESIGN signature schemes as defined in IEEE P1363a.
7 */
8 
9 #include "cryptlib.h"
10 #include "pubkey.h"
11 #include "integer.h"
12 #include "asn.h"
13 #include "misc.h"
14 
15 NAMESPACE_BEGIN(CryptoPP)
16 
17 //! _
19 {
20  typedef ESIGNFunction ThisClass;
21 
22 public:
23  void Initialize(const Integer &n, const Integer &e)
24  {m_n = n; m_e = e;}
25 
26  // PublicKey
27  void BERDecode(BufferedTransformation &bt);
28  void DEREncode(BufferedTransformation &bt) const;
29 
30  // CryptoMaterial
31  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
32  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
33  void AssignFrom(const NameValuePairs &source);
34 
35  // TrapdoorFunction
36  Integer ApplyFunction(const Integer &x) const;
37  Integer PreimageBound() const {return m_n;}
38  Integer ImageBound() const {return Integer::Power2(GetK());}
39 
40  // non-derived
41  const Integer & GetModulus() const {return m_n;}
42  const Integer & GetPublicExponent() const {return m_e;}
43 
44  void SetModulus(const Integer &n) {m_n = n;}
45  void SetPublicExponent(const Integer &e) {m_e = e;}
46 
47 protected:
48  // Covertiy finding on overflow. The library allows small values for research purposes.
49  unsigned int GetK() const {return SaturatingSubtract(m_n.BitCount()/3, 1U);}
50 
51  Integer m_n, m_e;
52 };
53 
54 //! _
56 {
58 
59 public:
60  void Initialize(const Integer &n, const Integer &e, const Integer &p, const Integer &q)
61  {m_n = n; m_e = e; m_p = p; m_q = q;}
62  // generate a random private key
63  void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
64  {GenerateRandomWithKeySize(rng, modulusBits);}
65 
67  void DEREncode(BufferedTransformation &bt) const;
68 
70 
71  // GeneratibleCryptoMaterial
72  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
73  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
74  void AssignFrom(const NameValuePairs &source);
75  /*! parameters: (ModulusSize) */
77 
78  const Integer& GetPrime1() const {return m_p;}
79  const Integer& GetPrime2() const {return m_q;}
80 
81  void SetPrime1(const Integer &p) {m_p = p;}
82  void SetPrime2(const Integer &q) {m_q = q;}
83 
84 protected:
85  Integer m_p, m_q;
86 };
87 
88 //! _
89 template <class T>
91 {
92 public:
93  CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "EMSA5";}
94 
95  void ComputeMessageRepresentative(RandomNumberGenerator &rng,
96  const byte *recoverableMessage, size_t recoverableMessageLength,
97  HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
98  byte *representative, size_t representativeBitLength) const
99  {
100  CRYPTOPP_UNUSED(rng), CRYPTOPP_UNUSED(recoverableMessage), CRYPTOPP_UNUSED(recoverableMessageLength);
101  CRYPTOPP_UNUSED(messageEmpty), CRYPTOPP_UNUSED(hashIdentifier);
102  SecByteBlock digest(hash.DigestSize());
103  hash.Final(digest);
104  size_t representativeByteLength = BitsToBytes(representativeBitLength);
105  T mgf;
106  mgf.GenerateAndMask(hash, representative, representativeByteLength, digest, digest.size(), false);
107  if (representativeBitLength % 8 != 0)
108  representative[0] = (byte)Crop(representative[0], representativeBitLength % 8);
109  }
110 };
111 
112 //! EMSA5, for use with ESIGN
114 {
116 };
117 
119 {
120  static std::string StaticAlgorithmName() {return "ESIGN";}
121  typedef ESIGNFunction PublicKey;
123 };
124 
125 //! ESIGN, as defined in IEEE P1363a
126 template <class H, class STANDARD = P1363_EMSA5>
127 struct ESIGN : public TF_SS<STANDARD, H, ESIGN_Keys>
128 {
129 };
130 
131 NAMESPACE_END
132 
133 #endif
ESIGNFunction
_
Definition: esign.h:18
PrivateKey
Interface for private keys.
Definition: cryptlib.h:2198
EMSA5Pad
_
Definition: esign.h:90
TrapdoorFunction
Applies the trapdoor function.
Definition: pubkey.h:133
ESIGNFunction::ImageBound
Integer ImageBound() const
Returns the maximum size of a message after the trapdoor function is applied.
Definition: esign.h:38
ASN1CryptoMaterial
Encode and decode ASN.1 objects with additional information.
Definition: asn.h:365
HashTransformation
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:931
InvertibleESIGNFunction::DEREncode
void DEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
Definition: esign.cpp:141
BufferedTransformation
Interface for buffered transformations.
Definition: cryptlib.h:1359
SecByteBlock
SecBlock<byte> typedef.
Definition: secblock.h:731
InvertibleESIGNFunction::Validate
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
Definition: esign.cpp:192
pubkey.h
This file contains helper classes/functions for implementing public key algorithms.
ESIGNFunction::PreimageBound
Integer PreimageBound() const
Returns the maximum size of a message before the trapdoor function is applied.
Definition: esign.h:37
PK_DeterministicSignatureMessageEncodingMethod
Interface for message encoding method for public key signature schemes.
Definition: pubkey.h:415
Integer::Power2
static Integer Power2(size_t e)
Exponentiates to a power of 2.
Definition: integer.cpp:3013
RandomNumberGenerator
Interface for random number generators.
Definition: cryptlib.h:1193
BitsToBytes
size_t BitsToBytes(size_t bitCount)
Returns the number of 8-bit bytes or octets required for the specified number of bits.
Definition: misc.h:743
misc.h
Utility functions for the Crypto++ library.
InvertibleESIGNFunction::GenerateRandom
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
Definition: esign.cpp:86
PublicKey
Interface for public keys.
Definition: cryptlib.h:2193
InvertibleESIGNFunction::BERDecode
void BERDecode(BufferedTransformation &bt)
Decode this object from a BufferedTransformation.
Definition: esign.cpp:131
P1363_EMSA5
EMSA5, for use with ESIGN.
Definition: esign.h:113
asn.h
Classes and functions for working with ANS.1 objects.
InvertibleESIGNFunction::CalculateRandomizedInverse
Integer CalculateRandomizedInverse(RandomNumberGenerator &rng, const Integer &x) const
Applies the inverse of the trapdoor function, using random data if required.
Definition: esign.cpp:151
SecBlock::size
size_type size() const
Provides the count of elements in the SecBlock.
Definition: secblock.h:524
GeneratableCryptoMaterial::GenerateRandomWithKeySize
void GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize)
Generate a random key or crypto parameters.
Definition: cryptlib.cpp:768
HashTransformation::DigestSize
virtual unsigned int DigestSize() const =0
Provides the digest size of the hash.
InvertibleESIGNFunction::AssignFrom
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
Definition: esign.cpp:213
ESIGN
ESIGN, as defined in IEEE P1363a.
Definition: esign.h:127
RandomizedTrapdoorFunctionInverse
Applies the inverse of the trapdoor function, using random data if required.
Definition: pubkey.h:165
Crop
T Crop(T value, size_t bits)
Truncates the value to the specified number of bits.
Definition: misc.h:731
CryptoPP
Crypto++ library namespace.
SaturatingSubtract
T1 SaturatingSubtract(const T1 &a, const T2 &b)
Performs a saturating subtract clamped at 0.
Definition: misc.h:841
TF_SS
Trapdoor Function (TF) Signature Scheme.
Definition: pubkey.h:2188
ESIGN_Keys
Definition: esign.h:118
InvertibleESIGNFunction::GetVoidValue
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
Definition: esign.cpp:205
InvertibleESIGNFunction
_
Definition: esign.h:55
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:282
cryptlib.h
Abstract base classes that provide a uniform interface to this library.
integer.h
Multiple precision integer with arithmetic operations.
Integer
Multiple precision integer with arithmetic operations.
Definition: integer.h:45
SignatureStandard
Base class for public key signature standard classes.
Definition: pubkey.h:2154
HashTransformation::Final
virtual void Final(byte *digest)
Computes the hash of the current message.
Definition: cryptlib.h:963