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.

56 lines
1.7 KiB

  1. // blowfish.h - written and placed in the public domain by Wei Dai
  2. //! \file blowfish.h
  3. //! \brief Classes for the Blowfish block cipher
  4. #ifndef CRYPTOPP_BLOWFISH_H
  5. #define CRYPTOPP_BLOWFISH_H
  6. #include "seckey.h"
  7. #include "secblock.h"
  8. NAMESPACE_BEGIN(CryptoPP)
  9. //! \class Blowfish_Info
  10. //! \brief The cipher's key, iv, block size and name information.
  11. struct Blowfish_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 4, 56>, public FixedRounds<16>
  12. {
  13. static const char *StaticAlgorithmName() {return "Blowfish";}
  14. };
  15. // <a href="http://www.weidai.com/scan-mirror/cs.html#Blowfish">Blowfish</a>
  16. //! \class Blowfish
  17. //! \brief Provides Blowfish encryption and decryption
  18. class Blowfish : public Blowfish_Info, public BlockCipherDocumentation
  19. {
  20. //! \class Base
  21. //! \brief Class specific implementation and overrides used to operate the cipher.
  22. //! \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions
  23. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Blowfish_Info>
  24. {
  25. public:
  26. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  27. void UncheckedSetKey(const byte *key_string, unsigned int keylength, const NameValuePairs &params);
  28. private:
  29. void crypt_block(const word32 in[2], word32 out[2]) const;
  30. static const word32 p_init[ROUNDS+2];
  31. static const word32 s_init[4*256];
  32. FixedSizeSecBlock<word32, ROUNDS+2> pbox;
  33. FixedSizeSecBlock<word32, 4*256> sbox;
  34. };
  35. public:
  36. typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
  37. typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
  38. };
  39. typedef Blowfish::Encryption BlowfishEncryption;
  40. typedef Blowfish::Decryption BlowfishDecryption;
  41. NAMESPACE_END
  42. #endif