Crypto++ 8.7
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
30NAMESPACE_BEGIN(CryptoPP)
31
32/// \brief LEA block cipher information
33/// \since Crypto++ 8.0
34struct 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
54class CRYPTOPP_NO_VTABLE LEA : public LEA_Info, public BlockCipherDocumentation
55{
56public:
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
101};
102
105
106NAMESPACE_END
107
108#endif // CRYPTOPP_LEA_H
Classes for working with NameValuePairs.
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:306
Inherited by algorithms with fixed block size.
Definition: seckey.h:41
LEA block cipher transformation functions.
Definition: lea.h:61
Decryption transformation.
Definition: lea.h:90
Encryption transformation.
Definition: lea.h:76
LEA 128-bit block cipher.
Definition: lea.h:55
Interface for retrieving values given their names.
Definition: cryptlib.h:322
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:166
Library configuration file.
unsigned int word32
32-bit unsigned datatype
Definition: config_int.h:62
Crypto++ library namespace.
Classes and functions for secure memory allocations.
Classes and functions for implementing secret key algorithms.
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher.
Definition: seckey.h:399
BlockCipher Decryption
implements the BlockCipher interface
Definition: seckey.h:403
BlockCipher Encryption
implements the BlockCipher interface
Definition: seckey.h:401
LEA block cipher information.
Definition: lea.h:35
static const std::string StaticAlgorithmName()
The algorithm name.
Definition: lea.h:40