Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // lea.h - written and placed in the public domain by Kim Sung Hee and Jeffrey Walton

0002 //         Based on "LEA: A 128-Bit Block Cipher for Fast Encryption on Common

0003 //         Processors" by Deukjo Hong, Jung-Keun Lee, Dong-Chan Kim, Daesung Kwon,

0004 //         Kwon Ho Ryu, and Dong-Geon Lee.

0005 
0006 /// \file lea.h

0007 /// \brief Classes for the LEA block cipher

0008 /// \since Crypto++ 8.0

0009 
0010 #ifndef CRYPTOPP_LEA_H
0011 #define CRYPTOPP_LEA_H
0012 
0013 #include "config.h"
0014 #include "seckey.h"
0015 #include "secblock.h"
0016 #include "algparam.h"
0017 
0018 #if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARMV8)
0019 # ifndef CRYPTOPP_DISABLE_LEA_SIMD
0020 #  define CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS 1
0021 # endif
0022 #endif
0023 
0024 // Yet another SunStudio/SunCC workaround. Failed self tests

0025 // in SSE code paths on i386 for SunStudio 12.3 and below.

0026 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5120)
0027 # undef CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS
0028 #endif
0029 
0030 NAMESPACE_BEGIN(CryptoPP)
0031 
0032 /// \brief LEA block cipher information

0033 /// \since Crypto++ 8.0

0034 struct LEA_Info : public FixedBlockSize<16>, public VariableKeyLength<16,16,32,8>
0035 {
0036     /// \brief The algorithm name

0037     /// \return the algorithm name

0038     /// \details StaticAlgorithmName returns the algorithm's name as a static

0039     ///   member function.

0040     static const std::string StaticAlgorithmName()
0041     {
0042         // Format is Cipher-Blocksize

0043         return "LEA-128";
0044     }
0045 };
0046 
0047 /// \brief LEA 128-bit block cipher

0048 /// \details LEA provides 128-bit block size. The valid key size is 128-bits, 192-bits and 256-bits.

0049 /// \note Crypto++ provides a byte oriented implementation

0050 /// \sa <a href="http://www.cryptopp.com/wiki/LEA">LEA</a>,

0051 ///   <a href="https://seed.kisa.or.kr/html/egovframework/iwt/ds/ko/ref/LEA%20A%20128-Bit%20Block%20Cipher%20for%20Fast%20Encryption%20on%20Common%20Processors-English.pdf">

0052 ///   LEA: A 128-Bit Block Cipher for Fast Encryption on Common Processors</a>

0053 /// \since Crypto++ 8.0

0054 class CRYPTOPP_NO_VTABLE LEA : public LEA_Info, public BlockCipherDocumentation
0055 {
0056 public:
0057     /// \brief LEA block cipher transformation functions

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

0059     /// \since Crypto++ 8.0

0060     class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<LEA_Info>
0061     {
0062     protected:
0063         void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
0064         std::string AlgorithmProvider() const;
0065 
0066         SecBlock<word32> m_rkey;
0067         mutable SecBlock<word32> m_temp;
0068         unsigned int m_rounds;
0069     };
0070 
0071     /// \brief Encryption transformation

0072     /// \details Enc provides implementation for encryption transformation. All key and block

0073     ///   sizes are supported.

0074     /// \since Crypto++ 8.0

0075     class CRYPTOPP_NO_VTABLE Enc : public Base
0076     {
0077     public:
0078         void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0079 
0080 #if CRYPTOPP_LEA_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 and block

0087     ///   sizes are supported.

0088     /// \since Crypto++ 8.0

0089     class CRYPTOPP_NO_VTABLE Dec : public Base
0090     {
0091     public:
0092         void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0093 
0094 #if CRYPTOPP_LEA_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     typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
0100     typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
0101 };
0102 
0103 typedef LEA::Encryption LEAEncryption;
0104 typedef LEA::Decryption LEADecryption;
0105 
0106 NAMESPACE_END
0107 
0108 #endif  // CRYPTOPP_LEA_H