shark.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // shark.h - originally written and placed in the public domain by Wei Dai
  2. /// \file shark.h
  3. /// \brief Classes for the SHARK block cipher
  4. /// \since Crypto++ 2.1
  5. #ifndef CRYPTOPP_SHARK_H
  6. #define CRYPTOPP_SHARK_H
  7. #include "config.h"
  8. #include "seckey.h"
  9. #include "secblock.h"
  10. NAMESPACE_BEGIN(CryptoPP)
  11. /// \brief SHARK block cipher information
  12. /// \since Crypto++ 2.1
  13. struct SHARK_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<6, 2>
  14. {
  15. CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "SHARK-E";}
  16. };
  17. /// \brief SHARK block cipher
  18. /// <a href="http://www.cryptopp.com/wiki/SHARK-E">SHARK-E</a>
  19. /// \since Crypto++ 2.1
  20. class SHARK : public SHARK_Info, public BlockCipherDocumentation
  21. {
  22. /// \brief SHARK block cipher default operation
  23. /// \since Crypto++ 2.1
  24. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SHARK_Info>
  25. {
  26. public:
  27. void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &param);
  28. protected:
  29. unsigned int m_rounds;
  30. SecBlock<word64> m_roundKeys;
  31. };
  32. /// \brief SHARK block cipher encryption operation
  33. /// \since Crypto++ 2.1
  34. class CRYPTOPP_NO_VTABLE Enc : public Base
  35. {
  36. public:
  37. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  38. // used by Base to do key setup
  39. void InitForKeySetup();
  40. private:
  41. static const byte sbox[256];
  42. static const word64 cbox[8][256];
  43. };
  44. /// \brief SHARK block cipher decryption operation
  45. /// \since Crypto++ 2.1
  46. class CRYPTOPP_NO_VTABLE Dec : public Base
  47. {
  48. public:
  49. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  50. private:
  51. static const byte sbox[256];
  52. static const word64 cbox[8][256];
  53. };
  54. public:
  55. typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
  56. typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
  57. };
  58. typedef SHARK::Encryption SHARKEncryption;
  59. typedef SHARK::Decryption SHARKDecryption;
  60. NAMESPACE_END
  61. #endif