Crypto++  6.0
Free C++ class library of cryptographic schemes
pssr.h
Go to the documentation of this file.
1 // pssr.h - originally written and placed in the public domain by Wei Dai
2 
3 /// \file pssr.h
4 /// \brief Classes for probablistic signature schemes
5 
6 #ifndef CRYPTOPP_PSSR_H
7 #define CRYPTOPP_PSSR_H
8 
9 #include "cryptlib.h"
10 #include "pubkey.h"
11 #include "emsa2.h"
12 
13 #ifdef CRYPTOPP_IS_DLL
14 #include "sha.h"
15 #endif
16 
17 NAMESPACE_BEGIN(CryptoPP)
18 
19 /// \brief PSSR Message Encoding Method interface
21 {
22 public:
23  virtual ~PSSR_MEM_Base() {}
24 
25 protected:
26  virtual bool AllowRecovery() const =0;
27  virtual size_t SaltLen(size_t hashLen) const =0;
28  virtual size_t MinPadLen(size_t hashLen) const =0;
29  virtual const MaskGeneratingFunction & GetMGF() const =0;
30 
31 private:
32  size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const;
33  size_t MaxRecoverableLength(size_t representativeBitLength, size_t hashIdentifierLength, size_t digestLength) const;
34  bool IsProbabilistic() const;
35  bool AllowNonrecoverablePart() const;
36  bool RecoverablePartFirst() const;
37  void ComputeMessageRepresentative(RandomNumberGenerator &rng,
38  const byte *recoverableMessage, size_t recoverableMessageLength,
39  HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
40  byte *representative, size_t representativeBitLength) const;
41  DecodingResult RecoverMessageFromRepresentative(
42  HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
43  byte *representative, size_t representativeBitLength,
44  byte *recoverableMessage) const;
45 };
46 
47 /// \brief PSSR Message Encoding Method with Hash Identifier
48 /// \tparam USE_HASH_ID flag indicating whether the HashId is used
49 template <bool USE_HASH_ID> class PSSR_MEM_BaseWithHashId;
50 
51 /// \brief PSSR Message Encoding Method with Hash Identifier
52 /// \details If USE_HASH_ID is true, then EMSA2HashIdLookup<PSSR_MEM_Base> is used for the base class
53 template<> class PSSR_MEM_BaseWithHashId<true> : public EMSA2HashIdLookup<PSSR_MEM_Base> {};
54 
55 /// \brief PSSR Message Encoding Method without Hash Identifier
56 /// \details If USE_HASH_ID is false, then PSSR_MEM_Base is used for the base class
57 template<> class PSSR_MEM_BaseWithHashId<false> : public PSSR_MEM_Base {};
58 
59 /// \brief PSSR Message Encoding Method
60 /// \tparam ALLOW_RECOVERY flag indicating whether the scheme provides message recovery
61 /// \tparam MGF mask generation function
62 /// \tparam SALT_LEN length of the salt
63 /// \tparam MIN_PAD_LEN minimum length of the pad
64 /// \tparam USE_HASH_ID flag indicating whether the HashId is used
65 /// \details If ALLOW_RECOVERY is true, the the signature scheme provides message recovery. If
66 /// ALLOW_RECOVERY is false, the the signature scheme is appendix, and the message must be
67 /// provided during verification.
68 template <bool ALLOW_RECOVERY, class MGF=P1363_MGF1, int SALT_LEN=-1, int MIN_PAD_LEN=0, bool USE_HASH_ID=false>
69 class PSSR_MEM : public PSSR_MEM_BaseWithHashId<USE_HASH_ID>
70 {
71  virtual bool AllowRecovery() const {return ALLOW_RECOVERY;}
72  virtual size_t SaltLen(size_t hashLen) const {return SALT_LEN < 0 ? hashLen : SALT_LEN;}
73  virtual size_t MinPadLen(size_t hashLen) const {return MIN_PAD_LEN < 0 ? hashLen : MIN_PAD_LEN;}
74  virtual const MaskGeneratingFunction & GetMGF() const {static MGF mgf; return mgf;}
75 
76 public:
77  static std::string CRYPTOPP_API StaticAlgorithmName() {return std::string(ALLOW_RECOVERY ? "PSSR-" : "PSS-") + MGF::StaticAlgorithmName();}
78 };
79 
80 /// \brief Probabilistic Signature Scheme with Recovery
81 /// \details Signature Schemes with Recovery encode the message with the signature.
82 /// \sa <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PSSR-MGF1">PSSR-MGF1</a>
83 struct PSSR : public SignatureStandard
84 {
86 };
87 
88 /// \brief Probabilistic Signature Scheme with Appendix
89 /// \details Signature Schemes with Appendix require the message to be provided during verification.
90 /// \sa <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PSS-MGF1">PSS-MGF1</a>
91 struct PSS : public SignatureStandard
92 {
94 };
95 
96 NAMESPACE_END
97 
98 #endif
Classes and functions for various padding schemes used in public key algorithms.
This file contains helper classes/functions for implementing public key algorithms.
Abstract base classes that provide a uniform interface to this library.
Interface for random number generators.
Definition: cryptlib.h:1327
PSSR Message Encoding Method interface.
Definition: pssr.h:20
Base class for public key signature standard classes.
Definition: pubkey.h:2197
Returns a decoding results.
Definition: cryptlib.h:253
P1363 mask generation function.
Definition: pubkey.h:714
PSSR Message Encoding Method with Hash Identifier.
Definition: pssr.h:49
Mask generation function interface.
Definition: pubkey.h:685
EMSA2 padding method.
Definition: emsa2.h:33
Classes for SHA-1 and SHA-2 family of message digests.
Probabilistic Signature Scheme with Recovery.
Definition: pssr.h:83
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:1065
Crypto++ library namespace.
PSSR Message Encoding Method.
Definition: pssr.h:69
Interface for message encoding method for public key signature schemes.
Definition: pubkey.h:402
Probabilistic Signature Scheme with Appendix.
Definition: pssr.h:91