Crypto++ 8.9 Free C++ class library of cryptographic schemes

lea.h
Go to the documentation of this file.
1 // lea.h - written and placed in the public domain by Kim Sung Hee and Jeffrey Walton
2 // Based on "LEA: A 128-Bit Block Cipher for Fast Encryption on Common
3 // Processors" by Deukjo Hong, Jung-Keun Lee, Dong-Chan Kim, Daesung Kwon,
4 // Kwon Ho Ryu, and Dong-Geon Lee.
5
6 /// \file lea.h
7 /// \brief Classes for the LEA block cipher
8 /// \since Crypto++ 8.0
9
10 #ifndef CRYPTOPP_LEA_H
11 #define CRYPTOPP_LEA_H
12
13 #include "config.h"
14 #include "seckey.h"
15 #include "secblock.h"
16 #include "algparam.h"
17
18 #if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARMV8)
19 # ifndef CRYPTOPP_DISABLE_LEA_SIMD
20 # define CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS 1
21 # endif
22 #endif
23
24 // Yet another SunStudio/SunCC workaround. Failed self tests
25 // in SSE code paths on i386 for SunStudio 12.3 and below.
26 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5120)
27 # undef CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS
28 #endif
29
30 NAMESPACE_BEGIN(CryptoPP)
31
32 /// \brief LEA block cipher information
33 /// \since Crypto++ 8.0
34 struct LEA_Info : public FixedBlockSize<16>, public VariableKeyLength<16,16,32,8>
35 {
36 /// \brief The algorithm name
37 /// \return the algorithm name
38 /// \details StaticAlgorithmName returns the algorithm's name as a static
39 /// member function.
40 static const std::string StaticAlgorithmName()
41 {
42 // Format is Cipher-Blocksize
43 return "LEA-128";
44 }
45 };
46
47 /// \brief LEA 128-bit block cipher
48 /// \details LEA provides 128-bit block size. The valid key size is 128-bits, 192-bits and 256-bits.
49 /// \note Crypto++ provides a byte oriented implementation
50 /// \sa <a href="http://www.cryptopp.com/wiki/LEA">LEA</a>,
51 /// <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">
52 /// LEA: A 128-Bit Block Cipher for Fast Encryption on Common Processors</a>
53 /// \since Crypto++ 8.0
54 class CRYPTOPP_NO_VTABLE LEA : public LEA_Info, public BlockCipherDocumentation
55 {
56 public:
57 /// \brief LEA block cipher transformation functions
58 /// \details Provides implementation common to encryption and decryption
59 /// \since Crypto++ 8.0
60 class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<LEA_Info>
61 {
62 protected:
63 void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
64 std::string AlgorithmProvider() const;
65
66 SecBlock<word32> m_rkey;
67 mutable SecBlock<word32> m_temp;
68 unsigned int m_rounds;
69 };
70
71 /// \brief Encryption transformation
72 /// \details Enc provides implementation for encryption transformation. All key and block
73 /// sizes are supported.
74 /// \since Crypto++ 8.0
75 class CRYPTOPP_NO_VTABLE Enc : public Base
76 {
77 public:
78 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
79
80 #if CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS
81 size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
82 #endif
83 };
84
85 /// \brief Decryption transformation
86 /// \details Dec provides implementation for decryption transformation. All key and block
87 /// sizes are supported.
88 /// \since Crypto++ 8.0
89 class CRYPTOPP_NO_VTABLE Dec : public Base
90 {
91 public:
92 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
93
94 #if CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS
95 size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
96 #endif
97 };
98
99 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
100 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
101 };
102
103 typedef LEA::Encryption LEAEncryption;
104 typedef LEA::Decryption LEADecryption;
105
106 NAMESPACE_END
107
108 #endif // CRYPTOPP_LEA_H
algparam.h
Classes for working with NameValuePairs.
BlockCipherFinal< ENCRYPTION, Enc >
BlockCipherImpl
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:306
FixedBlockSize
Inherited by algorithms with fixed block size.
Definition: seckey.h:41
LEA::Base
LEA block cipher transformation functions.
Definition: lea.h:61
LEA::Dec
Decryption transformation.
Definition: lea.h:90
LEA::Enc
Encryption transformation.
Definition: lea.h:76
LEA
LEA 128-bit block cipher.
Definition: lea.h:55
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:327
SecBlock< word32 >
VariableKeyLength
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:166
config.h
Library configuration file.
word32
unsigned int word32
32-bit unsigned datatype
Definition: config_int.h:72
CryptoPP
Crypto++ library namespace.
secblock.h
Classes and functions for secure memory allocations.
seckey.h
Classes and functions for implementing secret key algorithms.
BlockCipherDocumentation
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher.
Definition: seckey.h:399
BlockCipherDocumentation::Decryption
BlockCipher Decryption
implements the BlockCipher interface
Definition: seckey.h:403
BlockCipherDocumentation::Encryption
BlockCipher Encryption
implements the BlockCipher interface
Definition: seckey.h:401
LEA_Info
LEA block cipher information.
Definition: lea.h:35
LEA_Info::StaticAlgorithmName
static const std::string StaticAlgorithmName()
The algorithm name.
Definition: lea.h:40