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