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