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.

83 lines
2.8 KiB

  1. // rijndael.h - written and placed in the public domain by Wei Dai
  2. //! \file rijndael.h
  3. //! \brief Classes for Rijndael encryption algorithm
  4. //! \details All key sizes are supported. The library only provides Rijndael with 128-bit blocks,
  5. //! and not 192-bit or 256-bit blocks
  6. #ifndef CRYPTOPP_RIJNDAEL_H
  7. #define CRYPTOPP_RIJNDAEL_H
  8. #include "seckey.h"
  9. #include "secblock.h"
  10. #if CRYPTOPP_BOOL_X32
  11. # define CRYPTOPP_DISABLE_RIJNDAEL_ASM
  12. #endif
  13. NAMESPACE_BEGIN(CryptoPP)
  14. //! \brief Rijndael block cipher information
  15. struct Rijndael_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8>
  16. {
  17. CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return CRYPTOPP_RIJNDAEL_NAME;}
  18. };
  19. //! \brief Rijndael block cipher implementation details
  20. //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#Rijndael">Rijndael</a>
  21. class CRYPTOPP_DLL Rijndael : public Rijndael_Info, public BlockCipherDocumentation
  22. {
  23. //! \brief Rijndael block cipher data processing functionss
  24. //! \details Provides implementation common to encryption and decryption
  25. class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Rijndael_Info>
  26. {
  27. public:
  28. void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
  29. protected:
  30. static void FillEncTable();
  31. static void FillDecTable();
  32. // VS2005 workaround: have to put these on seperate lines, or error C2487 is triggered in DLL build
  33. static const byte Se[256];
  34. static const byte Sd[256];
  35. static const word32 rcon[];
  36. unsigned int m_rounds;
  37. FixedSizeAlignedSecBlock<word32, 4*15> m_key;
  38. };
  39. //! \brief Rijndael block cipher data processing functions
  40. //! \details Provides implementation for encryption transformation
  41. class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Enc : public Base
  42. {
  43. public:
  44. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  45. #if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86
  46. size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
  47. #endif
  48. };
  49. //! \brief Rijndael block cipher data processing functions
  50. //! \details Provides implementation for decryption transformation
  51. class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Dec : public Base
  52. {
  53. public:
  54. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  55. #if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE
  56. size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
  57. #endif
  58. };
  59. public:
  60. typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
  61. typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
  62. };
  63. typedef Rijndael::Encryption RijndaelEncryption;
  64. typedef Rijndael::Decryption RijndaelDecryption;
  65. NAMESPACE_END
  66. #endif