00001
00002
00003
00004
00005
00006
00007 #ifndef CRYPTOPP_PSSR_H
00008 #define CRYPTOPP_PSSR_H
00009
00010 #include "cryptlib.h"
00011 #include "pubkey.h"
00012 #include "emsa2.h"
00013
00014 #ifdef CRYPTOPP_IS_DLL
00015 #include "sha.h"
00016 #endif
00017
00018 NAMESPACE_BEGIN(CryptoPP)
00019
00020 class CRYPTOPP_DLL PSSR_MEM_Base : public PK_RecoverableSignatureMessageEncodingMethod
00021 {
00022 virtual bool AllowRecovery() const =0;
00023 virtual size_t SaltLen(size_t hashLen) const =0;
00024 virtual size_t MinPadLen(size_t hashLen) const =0;
00025 virtual const MaskGeneratingFunction & GetMGF() const =0;
00026
00027 public:
00028 size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const;
00029 size_t MaxRecoverableLength(size_t representativeBitLength, size_t hashIdentifierLength, size_t digestLength) const;
00030 bool IsProbabilistic() const;
00031 bool AllowNonrecoverablePart() const;
00032 bool RecoverablePartFirst() const;
00033 void ComputeMessageRepresentative(RandomNumberGenerator &rng,
00034 const byte *recoverableMessage, size_t recoverableMessageLength,
00035 HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
00036 byte *representative, size_t representativeBitLength) const;
00037 DecodingResult RecoverMessageFromRepresentative(
00038 HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
00039 byte *representative, size_t representativeBitLength,
00040 byte *recoverableMessage) const;
00041 };
00042
00043 template <bool USE_HASH_ID> class PSSR_MEM_BaseWithHashId;
00044 template<> class PSSR_MEM_BaseWithHashId<true> : public EMSA2HashIdLookup<PSSR_MEM_Base> {};
00045 template<> class PSSR_MEM_BaseWithHashId<false> : public PSSR_MEM_Base {};
00046
00047 template <bool ALLOW_RECOVERY, class MGF=P1363_MGF1, int SALT_LEN=-1, int MIN_PAD_LEN=0, bool USE_HASH_ID=false>
00048 class PSSR_MEM : public PSSR_MEM_BaseWithHashId<USE_HASH_ID>
00049 {
00050 virtual bool AllowRecovery() const {return ALLOW_RECOVERY;}
00051 virtual size_t SaltLen(size_t hashLen) const {return SALT_LEN < 0 ? hashLen : SALT_LEN;}
00052 virtual size_t MinPadLen(size_t hashLen) const {return MIN_PAD_LEN < 0 ? hashLen : MIN_PAD_LEN;}
00053 virtual const MaskGeneratingFunction & GetMGF() const {static MGF mgf; return mgf;}
00054
00055 public:
00056 static std::string CRYPTOPP_API StaticAlgorithmName() {return std::string(ALLOW_RECOVERY ? "PSSR-" : "PSS-") + MGF::StaticAlgorithmName();}
00057 };
00058
00059
00060 struct PSSR : public SignatureStandard
00061 {
00062 typedef PSSR_MEM<true> SignatureMessageEncodingMethod;
00063 };
00064
00065
00066 struct PSS : public SignatureStandard
00067 {
00068 typedef PSSR_MEM<false> SignatureMessageEncodingMethod;
00069 };
00070
00071 NAMESPACE_END
00072
00073 #endif