Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.5 KiB

  1. #ifndef CRYPTOPP_PSSR_H
  2. #define CRYPTOPP_PSSR_H
  3. #include "pubkey.h"
  4. #include "emsa2.h"
  5. #ifdef CRYPTOPP_IS_DLL
  6. #include "sha.h"
  7. #endif
  8. NAMESPACE_BEGIN(CryptoPP)
  9. class CRYPTOPP_DLL PSSR_MEM_Base : public PK_RecoverableSignatureMessageEncodingMethod
  10. {
  11. virtual bool AllowRecovery() const =0;
  12. virtual size_t SaltLen(size_t hashLen) const =0;
  13. virtual size_t MinPadLen(size_t hashLen) const =0;
  14. virtual const MaskGeneratingFunction & GetMGF() const =0;
  15. public:
  16. size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const;
  17. size_t MaxRecoverableLength(size_t representativeBitLength, size_t hashIdentifierLength, size_t digestLength) const;
  18. bool IsProbabilistic() const;
  19. bool AllowNonrecoverablePart() const;
  20. bool RecoverablePartFirst() const;
  21. void ComputeMessageRepresentative(RandomNumberGenerator &rng,
  22. const byte *recoverableMessage, size_t recoverableMessageLength,
  23. HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
  24. byte *representative, size_t representativeBitLength) const;
  25. DecodingResult RecoverMessageFromRepresentative(
  26. HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
  27. byte *representative, size_t representativeBitLength,
  28. byte *recoverableMessage) const;
  29. };
  30. template <bool USE_HASH_ID> class PSSR_MEM_BaseWithHashId;
  31. template<> class PSSR_MEM_BaseWithHashId<true> : public EMSA2HashIdLookup<PSSR_MEM_Base> {};
  32. template<> class PSSR_MEM_BaseWithHashId<false> : public PSSR_MEM_Base {};
  33. template <bool ALLOW_RECOVERY, class MGF=P1363_MGF1, int SALT_LEN=-1, int MIN_PAD_LEN=0, bool USE_HASH_ID=false>
  34. class PSSR_MEM : public PSSR_MEM_BaseWithHashId<USE_HASH_ID>
  35. {
  36. virtual bool AllowRecovery() const {return ALLOW_RECOVERY;}
  37. virtual size_t SaltLen(size_t hashLen) const {return SALT_LEN < 0 ? hashLen : SALT_LEN;}
  38. virtual size_t MinPadLen(size_t hashLen) const {return MIN_PAD_LEN < 0 ? hashLen : MIN_PAD_LEN;}
  39. virtual const MaskGeneratingFunction & GetMGF() const {static MGF mgf; return mgf;}
  40. public:
  41. static std::string CRYPTOPP_API StaticAlgorithmName() {return std::string(ALLOW_RECOVERY ? "PSSR-" : "PSS-") + MGF::StaticAlgorithmName();}
  42. };
  43. //! <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PSSR-MGF1">PSSR-MGF1</a>
  44. struct PSSR : public SignatureStandard
  45. {
  46. typedef PSSR_MEM<true> SignatureMessageEncodingMethod;
  47. };
  48. //! <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PSS-MGF1">PSS-MGF1</a>
  49. struct PSS : public SignatureStandard
  50. {
  51. typedef PSSR_MEM<false> SignatureMessageEncodingMethod;
  52. };
  53. NAMESPACE_END
  54. #endif