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