Team Fortress 2 Source Code as on 22/4/2020
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.

73 lines
2.7 KiB

  1. // pssr.h - written and placed in the public domain by Wei Dai
  2. //! \file
  3. //! \headerfile pssr.h
  4. //! \brief Classes for probablistic signature schemes
  5. #ifndef CRYPTOPP_PSSR_H
  6. #define CRYPTOPP_PSSR_H
  7. #include "cryptlib.h"
  8. #include "pubkey.h"
  9. #include "emsa2.h"
  10. #ifdef CRYPTOPP_IS_DLL
  11. #include "sha.h"
  12. #endif
  13. NAMESPACE_BEGIN(CryptoPP)
  14. class CRYPTOPP_DLL PSSR_MEM_Base : public PK_RecoverableSignatureMessageEncodingMethod
  15. {
  16. virtual bool AllowRecovery() const =0;
  17. virtual size_t SaltLen(size_t hashLen) const =0;
  18. virtual size_t MinPadLen(size_t hashLen) const =0;
  19. virtual const MaskGeneratingFunction & GetMGF() const =0;
  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. template <bool USE_HASH_ID> class PSSR_MEM_BaseWithHashId;
  36. template<> class PSSR_MEM_BaseWithHashId<true> : public EMSA2HashIdLookup<PSSR_MEM_Base> {};
  37. template<> class PSSR_MEM_BaseWithHashId<false> : public PSSR_MEM_Base {};
  38. template <bool ALLOW_RECOVERY, class MGF=P1363_MGF1, int SALT_LEN=-1, int MIN_PAD_LEN=0, bool USE_HASH_ID=false>
  39. class PSSR_MEM : public PSSR_MEM_BaseWithHashId<USE_HASH_ID>
  40. {
  41. virtual bool AllowRecovery() const {return ALLOW_RECOVERY;}
  42. virtual size_t SaltLen(size_t hashLen) const {return SALT_LEN < 0 ? hashLen : SALT_LEN;}
  43. virtual size_t MinPadLen(size_t hashLen) const {return MIN_PAD_LEN < 0 ? hashLen : MIN_PAD_LEN;}
  44. virtual const MaskGeneratingFunction & GetMGF() const {static MGF mgf; return mgf;}
  45. public:
  46. static std::string CRYPTOPP_API StaticAlgorithmName() {return std::string(ALLOW_RECOVERY ? "PSSR-" : "PSS-") + MGF::StaticAlgorithmName();}
  47. };
  48. //! <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PSSR-MGF1">PSSR-MGF1</a>
  49. struct PSSR : public SignatureStandard
  50. {
  51. typedef PSSR_MEM<true> SignatureMessageEncodingMethod;
  52. };
  53. //! <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PSS-MGF1">PSS-MGF1</a>
  54. struct PSS : public SignatureStandard
  55. {
  56. typedef PSSR_MEM<false> SignatureMessageEncodingMethod;
  57. };
  58. NAMESPACE_END
  59. #endif