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.

99 lines
3.0 KiB

  1. // pkcspad.h - written and placed in the public domain by Wei Dai
  2. //! \headerfile pkcspad.h
  3. //! \brief Classes for PKCS padding schemes
  4. #ifndef CRYPTOPP_PKCSPAD_H
  5. #define CRYPTOPP_PKCSPAD_H
  6. #include "cryptlib.h"
  7. #include "pubkey.h"
  8. #ifdef CRYPTOPP_IS_DLL
  9. #include "sha.h"
  10. #endif
  11. NAMESPACE_BEGIN(CryptoPP)
  12. //! <a href="http://www.weidai.com/scan-mirror/ca.html#cem_PKCS1-1.5">EME-PKCS1-v1_5</a>
  13. class PKCS_EncryptionPaddingScheme : public PK_EncryptionMessageEncodingMethod
  14. {
  15. public:
  16. static const char * StaticAlgorithmName() {return "EME-PKCS1-v1_5";}
  17. size_t MaxUnpaddedLength(size_t paddedLength) const;
  18. void Pad(RandomNumberGenerator &rng, const byte *raw, size_t inputLength, byte *padded, size_t paddedLength, const NameValuePairs &parameters) const;
  19. DecodingResult Unpad(const byte *padded, size_t paddedLength, byte *raw, const NameValuePairs &parameters) const;
  20. };
  21. template <class H> class PKCS_DigestDecoration
  22. {
  23. public:
  24. static const byte decoration[];
  25. static const unsigned int length;
  26. };
  27. // PKCS_DigestDecoration can be instantiated with the following
  28. // classes as specified in PKCS#1 v2.0 and P1363a
  29. class SHA1;
  30. class RIPEMD160;
  31. class Tiger;
  32. class SHA224;
  33. class SHA256;
  34. class SHA384;
  35. class SHA512;
  36. namespace Weak1 {
  37. class MD2;
  38. class MD5;
  39. }
  40. // end of list
  41. #ifdef CRYPTOPP_IS_DLL
  42. CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA1>;
  43. CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA224>;
  44. CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA256>;
  45. CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA384>;
  46. CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA512>;
  47. #endif
  48. //! <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PKCS1-1.5">EMSA-PKCS1-v1_5</a>
  49. class CRYPTOPP_DLL PKCS1v15_SignatureMessageEncodingMethod : public PK_DeterministicSignatureMessageEncodingMethod
  50. {
  51. public:
  52. static const char * CRYPTOPP_API StaticAlgorithmName() {return "EMSA-PKCS1-v1_5";}
  53. size_t MinRepresentativeBitLength(size_t hashIdentifierSize, size_t digestSize) const
  54. {return 8 * (digestSize + hashIdentifierSize + 10);}
  55. void ComputeMessageRepresentative(RandomNumberGenerator &rng,
  56. const byte *recoverableMessage, size_t recoverableMessageLength,
  57. HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
  58. byte *representative, size_t representativeBitLength) const;
  59. struct HashIdentifierLookup
  60. {
  61. template <class H> struct HashIdentifierLookup2
  62. {
  63. static HashIdentifier Lookup()
  64. {
  65. return HashIdentifier(PKCS_DigestDecoration<H>::decoration, PKCS_DigestDecoration<H>::length);
  66. }
  67. };
  68. };
  69. };
  70. //! PKCS #1 version 1.5, for use with RSAES and RSASS
  71. /*! Only the following hash functions are supported by this signature standard:
  72. \dontinclude pkcspad.h
  73. \skip can be instantiated
  74. \until end of list
  75. */
  76. struct PKCS1v15 : public SignatureStandard, public EncryptionStandard
  77. {
  78. typedef PKCS_EncryptionPaddingScheme EncryptionMessageEncodingMethod;
  79. typedef PKCS1v15_SignatureMessageEncodingMethod SignatureMessageEncodingMethod;
  80. };
  81. NAMESPACE_END
  82. #endif