Crypto++
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 "pubkey.h"
10 #include "integer.h"
11 #include "asn.h"
12 
13 NAMESPACE_BEGIN(CryptoPP)
14 
15 //! _
17 {
18  typedef ESIGNFunction ThisClass;
19 
20 public:
21  void Initialize(const Integer &n, const Integer &e)
22  {m_n = n; m_e = e;}
23 
24  // PublicKey
25  void BERDecode(BufferedTransformation &bt);
26  void DEREncode(BufferedTransformation &bt) const;
27 
28  // CryptoMaterial
29  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
30  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
31  void AssignFrom(const NameValuePairs &source);
32 
33  // TrapdoorFunction
34  Integer ApplyFunction(const Integer &x) const;
35  Integer PreimageBound() const {return m_n;}
36  Integer ImageBound() const {return Integer::Power2(GetK());}
37 
38  // non-derived
39  const Integer & GetModulus() const {return m_n;}
40  const Integer & GetPublicExponent() const {return m_e;}
41 
42  void SetModulus(const Integer &n) {m_n = n;}
43  void SetPublicExponent(const Integer &e) {m_e = e;}
44 
45 protected:
46  unsigned int GetK() const {return m_n.BitCount()/3-1;}
47 
48  Integer m_n, m_e;
49 };
50 
51 //! _
53 {
55 
56 public:
57  void Initialize(const Integer &n, const Integer &e, const Integer &p, const Integer &q)
58  {m_n = n; m_e = e; m_p = p; m_q = q;}
59  // generate a random private key
60  void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
61  {GenerateRandomWithKeySize(rng, modulusBits);}
62 
64  void DEREncode(BufferedTransformation &bt) const;
65 
66  Integer CalculateRandomizedInverse(RandomNumberGenerator &rng, const Integer &x) const;
67 
68  // GeneratibleCryptoMaterial
69  bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
70  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
71  void AssignFrom(const NameValuePairs &source);
72  /*! parameters: (ModulusSize) */
74 
75  const Integer& GetPrime1() const {return m_p;}
76  const Integer& GetPrime2() const {return m_q;}
77 
78  void SetPrime1(const Integer &p) {m_p = p;}
79  void SetPrime2(const Integer &q) {m_q = q;}
80 
81 protected:
82  Integer m_p, m_q;
83 };
84 
85 //! _
86 template <class T>
88 {
89 public:
90  static const char *StaticAlgorithmName() {return "EMSA5";}
91 
92  void ComputeMessageRepresentative(RandomNumberGenerator &rng,
93  const byte *recoverableMessage, size_t recoverableMessageLength,
94  HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
95  byte *representative, size_t representativeBitLength) const
96  {
97  SecByteBlock digest(hash.DigestSize());
98  hash.Final(digest);
99  size_t representativeByteLength = BitsToBytes(representativeBitLength);
100  T mgf;
101  mgf.GenerateAndMask(hash, representative, representativeByteLength, digest, digest.size(), false);
102  if (representativeBitLength % 8 != 0)
103  representative[0] = (byte)Crop(representative[0], representativeBitLength % 8);
104  }
105 };
106 
107 //! EMSA5, for use with ESIGN
109 {
111 };
112 
114 {
115  static std::string StaticAlgorithmName() {return "ESIGN";}
116  typedef ESIGNFunction PublicKey;
118 };
119 
120 //! ESIGN, as defined in IEEE P1363a
121 template <class H, class STANDARD = P1363_EMSA5>
122 struct ESIGN : public TF_SS<STANDARD, H, ESIGN_Keys>
123 {
124 };
125 
126 NAMESPACE_END
127 
128 #endif
This file contains helper classes/functions for implementing public key algorithms.
ESIGN, as defined in IEEE P1363a.
Definition: esign.h:122
void DEREncode(BufferedTransformation &bt) const
encode this object into a BufferedTransformation, using DER (Distinguished Encoding Rules) ...
interface for random number generators
Definition: cryptlib.h:668
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
check this object for errors
interface for buffered transformations
Definition: cryptlib.h:770
interface for private keys
Definition: cryptlib.h:1121
Base class for public key signature standard classes. These classes are used to select from variants ...
Definition: pubkey.h:1600
unsigned int BitCount() const
number of significant bits = floor(log2(abs(*this))) + 1
void BERDecode(BufferedTransformation &bt)
decode this object from a BufferedTransformation, using BER (Basic Encoding Rules) ...
_
Definition: esign.h:87
void AssignFrom(const NameValuePairs &source)
assign values from source to this object
multiple precision integer and basic arithmetics
Definition: integer.h:26
EMSA5, for use with ESIGN.
Definition: esign.h:108
static Integer Power2(size_t e)
return the integer 2**e
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
to be implemented by derived classes, users should use one of the above functions instead ...
virtual unsigned int DigestSize() const =0
size of the hash/digest/MAC returned by Final()
interface for hash functions and data processing part of MACs
Definition: cryptlib.h:530
Trapdoor Function Based Signature Scheme.
Definition: pubkey.h:1625
void GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize)
calls the above function with a NameValuePairs object that just specifies "KeySize" ...
interface for public keys
Definition: cryptlib.h:1115
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
virtual void Final(byte *digest)
compute hash for current message, then restart for a new message
Definition: cryptlib.h:544
interface for retrieving values given their names
Definition: cryptlib.h:224