File indexing completed on 2025-01-18 09:55:07
0001
0002
0003
0004
0005
0006
0007 #ifndef CRYPTOPP_PSSR_H
0008 #define CRYPTOPP_PSSR_H
0009
0010 #include "cryptlib.h"
0011 #include "pubkey.h"
0012 #include "emsa2.h"
0013
0014 #ifdef CRYPTOPP_IS_DLL
0015 #include "sha.h"
0016 #endif
0017
0018 NAMESPACE_BEGIN(CryptoPP)
0019
0020
0021
0022 class CRYPTOPP_DLL PSSR_MEM_Base : public PK_RecoverableSignatureMessageEncodingMethod
0023 {
0024 public:
0025 virtual ~PSSR_MEM_Base() {}
0026
0027 protected:
0028 virtual bool AllowRecovery() const =0;
0029 virtual size_t SaltLen(size_t hashLen) const =0;
0030 virtual size_t MinPadLen(size_t hashLen) const =0;
0031 virtual const MaskGeneratingFunction & GetMGF() const =0;
0032
0033 private:
0034 size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const;
0035 size_t MaxRecoverableLength(size_t representativeBitLength, size_t hashIdentifierLength, size_t digestLength) const;
0036 bool IsProbabilistic() const;
0037 bool AllowNonrecoverablePart() const;
0038 bool RecoverablePartFirst() const;
0039 void ComputeMessageRepresentative(RandomNumberGenerator &rng,
0040 const byte *recoverableMessage, size_t recoverableMessageLength,
0041 HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
0042 byte *representative, size_t representativeBitLength) const;
0043 DecodingResult RecoverMessageFromRepresentative(
0044 HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
0045 byte *representative, size_t representativeBitLength,
0046 byte *recoverableMessage) const;
0047 };
0048
0049
0050
0051
0052 template <bool USE_HASH_ID> class PSSR_MEM_BaseWithHashId;
0053
0054
0055
0056 template<> class PSSR_MEM_BaseWithHashId<true> : public EMSA2HashIdLookup<PSSR_MEM_Base> {};
0057
0058
0059
0060
0061 template<> class PSSR_MEM_BaseWithHashId<false> : public PSSR_MEM_Base {};
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 template <bool ALLOW_RECOVERY, class MGF=P1363_MGF1, int SALT_LEN=-1, int MIN_PAD_LEN=0, bool USE_HASH_ID=false>
0074 class PSSR_MEM : public PSSR_MEM_BaseWithHashId<USE_HASH_ID>
0075 {
0076 virtual bool AllowRecovery() const {return ALLOW_RECOVERY;}
0077 virtual size_t SaltLen(size_t hashLen) const {return SALT_LEN < 0 ? hashLen : SALT_LEN;}
0078 virtual size_t MinPadLen(size_t hashLen) const {return MIN_PAD_LEN < 0 ? hashLen : MIN_PAD_LEN;}
0079 virtual const MaskGeneratingFunction & GetMGF() const {static MGF mgf; return mgf;}
0080
0081 public:
0082 static std::string CRYPTOPP_API StaticAlgorithmName() {return std::string(ALLOW_RECOVERY ? "PSSR-" : "PSS-") + MGF::StaticAlgorithmName();}
0083 };
0084
0085
0086
0087
0088
0089 struct PSSR : public SignatureStandard
0090 {
0091 typedef PSSR_MEM<true> SignatureMessageEncodingMethod;
0092 };
0093
0094
0095
0096
0097
0098 struct PSS : public SignatureStandard
0099 {
0100 typedef PSSR_MEM<false> SignatureMessageEncodingMethod;
0101 };
0102
0103 NAMESPACE_END
0104
0105 #endif