Crypto++  8.0
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 # define CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS 1
20 #endif
21 
22 // Yet another SunStudio/SunCC workaround. Failed self tests
23 // in SSE code paths on i386 for SunStudio 12.3 and below.
24 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5120)
25 # undef CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS
26 #endif
27 
28 NAMESPACE_BEGIN(CryptoPP)
29 
30 /// \brief LEA block cipher information
31 /// \since Crypto++ 8.0
32 struct LEA_Info : public FixedBlockSize<16>, public VariableKeyLength<16,16,32,8>
33 {
34  /// \brief The algorithm name
35  /// \returns the algorithm name
36  /// \details StaticAlgorithmName returns the algorithm's name as a static
37  /// member function.
38  static const std::string StaticAlgorithmName()
39  {
40  // Format is Cipher-Blocksize
41  return "LEA-128";
42  }
43 };
44 
45 /// \brief LEA 128-bit block cipher
46 /// \details LEA provides 128-bit block size. The valid key size is 128-bits, 192-bits and 256-bits.
47 /// \note Crypto++ provides a byte oriented implementation
48 /// \sa <a href="http://www.cryptopp.com/wiki/LEA">LEA</a>,
49 /// <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">
50 /// LEA: A 128-Bit Block Cipher for Fast Encryption on Common Processors</a>
51 /// \since Crypto++ 8.0
52 class CRYPTOPP_NO_VTABLE LEA : public LEA_Info, public BlockCipherDocumentation
53 {
54 public:
55  /// \brief LEA block cipher transformation functions
56  /// \details Provides implementation common to encryption and decryption
57  /// \since Crypto++ 8.0
58  class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<LEA_Info>
59  {
60  protected:
61  void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
62  std::string AlgorithmProvider() const;
63 
64  SecBlock<word32> m_rkey;
65  mutable SecBlock<word32> m_temp;
66  unsigned int m_rounds;
67  };
68 
69  /// \brief Encryption transformation
70  /// \details Enc provides implementation for encryption transformation. All key and block
71  /// sizes are supported.
72  /// \since Crypto++ 8.0
73  class CRYPTOPP_NO_VTABLE Enc : public Base
74  {
75  public:
76  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
77 
78 #if CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS
79  size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
80 #endif
81  };
82 
83  /// \brief Encryption transformation
84  /// \details Dec provides implementation for decryption transformation. All key and block
85  /// sizes are supported.
86  /// \since Crypto++ 8.0
87  class CRYPTOPP_NO_VTABLE Dec : public Base
88  {
89  public:
90  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
91 
92 #if CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS
93  size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
94 #endif
95  };
96 
99 };
100 
103 
104 NAMESPACE_END
105 
106 #endif // CRYPTOPP_LEA_H
Classes for working with NameValuePairs.
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher...
Definition: seckey.h:398
LEA block cipher transformation functions.
Definition: lea.h:58
LEA 128-bit block cipher.
Definition: lea.h:52
Library configuration file.
LEA block cipher information.
Definition: lea.h:32
Classes and functions for secure memory allocations.
Inherited by algorithms with fixed block size.
Definition: seckey.h:40
Classes and functions for implementing secret key algorithms.
Encryption transformation.
Definition: lea.h:73
Encryption transformation.
Definition: lea.h:87
static const std::string StaticAlgorithmName()
The algorithm name.
Definition: lea.h:38
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:165
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:305
Crypto++ library namespace.
Interface for retrieving values given their names.
Definition: cryptlib.h:293