Crypto++
pssr.h
1 #ifndef CRYPTOPP_PSSR_H
2 #define CRYPTOPP_PSSR_H
3 
4 #include "pubkey.h"
5 #include "emsa2.h"
6 
7 #ifdef CRYPTOPP_IS_DLL
8 #include "sha.h"
9 #endif
10 
11 NAMESPACE_BEGIN(CryptoPP)
12 
14 {
15  virtual bool AllowRecovery() const =0;
16  virtual size_t SaltLen(size_t hashLen) const =0;
17  virtual size_t MinPadLen(size_t hashLen) const =0;
18  virtual const MaskGeneratingFunction & GetMGF() const =0;
19 
20 public:
21  size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const;
22  size_t MaxRecoverableLength(size_t representativeBitLength, size_t hashIdentifierLength, size_t digestLength) const;
23  bool IsProbabilistic() const;
24  bool AllowNonrecoverablePart() const;
25  bool RecoverablePartFirst() const;
26  void ComputeMessageRepresentative(RandomNumberGenerator &rng,
27  const byte *recoverableMessage, size_t recoverableMessageLength,
28  HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
29  byte *representative, size_t representativeBitLength) const;
30  DecodingResult RecoverMessageFromRepresentative(
31  HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
32  byte *representative, size_t representativeBitLength,
33  byte *recoverableMessage) const;
34 };
35 
36 template <bool USE_HASH_ID> class PSSR_MEM_BaseWithHashId;
37 template<> class PSSR_MEM_BaseWithHashId<true> : public EMSA2HashIdLookup<PSSR_MEM_Base> {};
38 template<> class PSSR_MEM_BaseWithHashId<false> : public PSSR_MEM_Base {};
39 
40 template <bool ALLOW_RECOVERY, class MGF=P1363_MGF1, int SALT_LEN=-1, int MIN_PAD_LEN=0, bool USE_HASH_ID=false>
41 class PSSR_MEM : public PSSR_MEM_BaseWithHashId<USE_HASH_ID>
42 {
43  virtual bool AllowRecovery() const {return ALLOW_RECOVERY;}
44  virtual size_t SaltLen(size_t hashLen) const {return SALT_LEN < 0 ? hashLen : SALT_LEN;}
45  virtual size_t MinPadLen(size_t hashLen) const {return MIN_PAD_LEN < 0 ? hashLen : MIN_PAD_LEN;}
46  virtual const MaskGeneratingFunction & GetMGF() const {static MGF mgf; return mgf;}
47 
48 public:
49  static std::string CRYPTOPP_API StaticAlgorithmName() {return std::string(ALLOW_RECOVERY ? "PSSR-" : "PSS-") + MGF::StaticAlgorithmName();}
50 };
51 
52 //! <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PSSR-MGF1">PSSR-MGF1</a>
53 struct PSSR : public SignatureStandard
54 {
56 };
57 
58 //! <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PSS-MGF1">PSS-MGF1</a>
59 struct PSS : public SignatureStandard
60 {
62 };
63 
64 NAMESPACE_END
65 
66 #endif
This file contains various padding schemes for public key algorithms.
This file contains helper classes/functions for implementing public key algorithms.
interface for random number generators
Definition: cryptlib.h:668
Base class for public key signature standard classes. These classes are used to select from variants ...
Definition: pubkey.h:1600
used to return decoding results
Definition: cryptlib.h:197
PSSR-MGF1
Definition: pssr.h:53
interface for hash functions and data processing part of MACs
Definition: cryptlib.h:530
Definition: pssr.h:41
PSS-MGF1
Definition: pssr.h:59