blowfish.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // blowfish.h - originally 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. /// \brief Blowfish block cipher information
  10. struct Blowfish_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 4, 56>, public FixedRounds<16>
  11. {
  12. CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Blowfish";}
  13. };
  14. // <a href="http://www.cryptopp.com/wiki/Blowfish">Blowfish</a>
  15. /// \brief Blowfish block cipher
  16. /// \since Crypto++ 1.0
  17. class Blowfish : public Blowfish_Info, public BlockCipherDocumentation
  18. {
  19. /// \brief Class specific implementation and overrides used to operate the cipher.
  20. /// \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions
  21. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Blowfish_Info>
  22. {
  23. public:
  24. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  25. void UncheckedSetKey(const byte *key_string, unsigned int keylength, const NameValuePairs &params);
  26. private:
  27. void crypt_block(const word32 in[2], word32 out[2]) const;
  28. static const word32 p_init[ROUNDS+2];
  29. static const word32 s_init[4*256];
  30. FixedSizeSecBlock<word32, ROUNDS+2> pbox;
  31. FixedSizeSecBlock<word32, 4*256> sbox;
  32. };
  33. public:
  34. typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
  35. typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
  36. };
  37. typedef Blowfish::Encryption BlowfishEncryption;
  38. typedef Blowfish::Decryption BlowfishDecryption;
  39. NAMESPACE_END
  40. #endif