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.

88 lines
2.1 KiB

  1. // emsa2.h - written and placed in the public domain by Wei Dai
  2. //! \file emsa2.h
  3. //! \brief Classes and functions for various padding schemes used in public key algorithms
  4. #ifndef CRYPTOPP_EMSA2_H
  5. #define CRYPTOPP_EMSA2_H
  6. #include "cryptlib.h"
  7. #include "pubkey.h"
  8. #include "misc.h"
  9. #ifdef CRYPTOPP_IS_DLL
  10. #include "sha.h"
  11. #endif
  12. NAMESPACE_BEGIN(CryptoPP)
  13. template <class H> class EMSA2HashId
  14. {
  15. public:
  16. static const byte id;
  17. };
  18. template <class BASE>
  19. class EMSA2HashIdLookup : public BASE
  20. {
  21. public:
  22. struct HashIdentifierLookup
  23. {
  24. template <class H> struct HashIdentifierLookup2
  25. {
  26. static HashIdentifier Lookup()
  27. {
  28. return HashIdentifier(&EMSA2HashId<H>::id, 1);
  29. }
  30. };
  31. };
  32. };
  33. // EMSA2HashId can be instantiated with the following classes.
  34. class SHA1;
  35. class RIPEMD160;
  36. class RIPEMD128;
  37. class SHA256;
  38. class SHA384;
  39. class SHA512;
  40. class Whirlpool;
  41. class SHA224;
  42. // end of list
  43. #ifdef CRYPTOPP_IS_DLL
  44. CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA1>;
  45. CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA224>;
  46. CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA256>;
  47. CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA384>;
  48. CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA512>;
  49. #endif
  50. //! _
  51. class CRYPTOPP_DLL EMSA2Pad : public EMSA2HashIdLookup<PK_DeterministicSignatureMessageEncodingMethod>
  52. {
  53. public:
  54. static const char * CRYPTOPP_API StaticAlgorithmName() {return "EMSA2";}
  55. size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const
  56. {CRYPTOPP_UNUSED(hashIdentifierLength); return 8*digestLength + 31;}
  57. void ComputeMessageRepresentative(RandomNumberGenerator &rng,
  58. const byte *recoverableMessage, size_t recoverableMessageLength,
  59. HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
  60. byte *representative, size_t representativeBitLength) const;
  61. };
  62. //! EMSA2, for use with RWSS and RSA_ISO
  63. /*! Only the following hash functions are supported by this signature standard:
  64. \dontinclude emsa2.h
  65. \skip EMSA2HashId can be instantiated
  66. \until end of list
  67. */
  68. struct P1363_EMSA2 : public SignatureStandard
  69. {
  70. typedef EMSA2Pad SignatureMessageEncodingMethod;
  71. };
  72. NAMESPACE_END
  73. #endif