Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:08

0001 // rijndael.h - originally written and placed in the public domain by Wei Dai

0002 
0003 /// \file rijndael.h

0004 /// \brief Classes for Rijndael encryption algorithm

0005 /// \details All key sizes are supported. The library only provides Rijndael with 128-bit blocks,

0006 ///   and not 192-bit or 256-bit blocks

0007 /// \since Rijndael since Crypto++ 3.1, Intel AES-NI since Crypto++ 5.6.1, ARMv8 AES since Crypto++ 6.0,

0008 ///   Power8 AES since Crypto++ 6.0, ARMv7 AES since Crypto++ 8.0

0009 
0010 #ifndef CRYPTOPP_RIJNDAEL_H
0011 #define CRYPTOPP_RIJNDAEL_H
0012 
0013 #include "seckey.h"
0014 #include "secblock.h"
0015 
0016 // Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler

0017 // error with .intel_syntax, http://llvm.org/bugs/show_bug.cgi?id=24232

0018 #if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM)
0019 # define CRYPTOPP_DISABLE_RIJNDAEL_ASM 1
0020 #endif
0021 
0022 #if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_ARM32 || \
0023     CRYPTOPP_BOOL_ARMV8 || CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64
0024 # define CRYPTOPP_RIJNDAEL_ADVANCED_PROCESS_BLOCKS 1
0025 #endif
0026 
0027 NAMESPACE_BEGIN(CryptoPP)
0028 
0029 /// \brief Rijndael block cipher information

0030 /// \details All key sizes are supported. The library only provides Rijndael with 128-bit blocks,

0031 ///   and not 192-bit or 256-bit blocks

0032 /// \since Rijndael since Crypto++ 3.1, Intel AES-NI since Crypto++ 5.6.1, ARMv8 AES since Crypto++ 6.0,

0033 ///   Power8 AES since Crypto++ 6.0, ARMv7 AES since Crypto++ 8.0

0034 struct Rijndael_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8>
0035 {
0036     CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "AES";}
0037 };
0038 
0039 /// \brief Rijndael block cipher

0040 /// \details All key sizes are supported. The library only provides Rijndael with 128-bit blocks,

0041 ///   and not 192-bit or 256-bit blocks

0042 /// \since Rijndael since Crypto++ 3.1, Intel AES-NI since Crypto++ 5.6.1, ARMv8 AES since Crypto++ 6.0,

0043 ///   Power8 AES since Crypto++ 6.0, ARMv7 AES since Crypto++ 8.0

0044 /// \sa <a href="http://www.cryptopp.com/wiki/Rijndael">Rijndael</a>

0045 class CRYPTOPP_DLL Rijndael : public Rijndael_Info, public BlockCipherDocumentation
0046 {
0047     /// \brief Rijndael block cipher transformation functions

0048     /// \details Provides implementation common to encryption and decryption

0049     class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Rijndael_Info>
0050     {
0051     public:
0052         void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
0053         std::string AlgorithmProvider() const;
0054         unsigned int OptimalDataAlignment() const;
0055 
0056     protected:
0057         static void FillEncTable();
0058         static void FillDecTable();
0059 
0060         // VS2005 workaround: have to put these on separate lines, or error C2487 is triggered in DLL build

0061         static const byte Se[256];
0062         static const byte Sd[256];
0063 
0064         static const word32 rcon[];
0065 
0066         unsigned int m_rounds;
0067         SecBlock<word32, AllocatorWithCleanup<word32, true> > m_key;
0068         mutable SecByteBlock m_aliasBlock;
0069     };
0070 
0071     /// \brief Encryption transformation

0072     /// \details Enc provides implementation for encryption transformation. All key sizes are supported.

0073     ///   The library only provides Rijndael with 128-bit blocks, and not 192-bit or 256-bit blocks

0074     /// \since Rijndael since Crypto++ 3.1, Intel AES-NI since Crypto++ 5.6.1, ARMv8 AES since Crypto++ 6.0,

0075     ///   Power8 AES since Crypto++ 6.0, ARMv7 AES since Crypto++ 8.0

0076     class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Enc : public Base
0077     {
0078     public:
0079         void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0080 #if CRYPTOPP_RIJNDAEL_ADVANCED_PROCESS_BLOCKS
0081         size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
0082 #endif
0083     };
0084 
0085     /// \brief Decryption transformation

0086     /// \details Dec provides implementation for decryption transformation. All key sizes are supported.

0087     ///   The library only provides Rijndael with 128-bit blocks, and not 192-bit or 256-bit blocks

0088     /// \since Rijndael since Crypto++ 3.1, Intel AES-NI since Crypto++ 5.6.1, ARMv8 AES since Crypto++ 6.0,

0089     ///   Power8 AES since Crypto++ 6.0, ARMv7 AES since Crypto++ 8.0

0090     class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Dec : public Base
0091     {
0092     public:
0093         void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0094 #if CRYPTOPP_RIJNDAEL_ADVANCED_PROCESS_BLOCKS
0095         size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
0096 #endif
0097     };
0098 
0099 public:
0100     typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
0101     typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
0102 };
0103 
0104 typedef Rijndael::Encryption RijndaelEncryption;
0105 typedef Rijndael::Decryption RijndaelDecryption;
0106 
0107 NAMESPACE_END
0108 
0109 #endif