Crypto++  6.1
Free C++ class library of cryptographic schemes
sm4.h
Go to the documentation of this file.
1 // sm4.h - written and placed in the public domain by Jeffrey Walton and Han Lulu
2 
3 /// \file sm4.h
4 /// \brief Classes for the SM4 block cipher
5 /// \details SM4 is a block cipher designed by Xiaoyun Wang, et al. The block cipher is part of the
6 /// Chinese State Cryptography Administration portfolio. The cipher was formely known as SMS4.
7 /// \sa <A HREF="http://eprint.iacr.org/2008/329.pdf">SMS4 Encryption Algorithm for Wireless Networks</A> and
8 /// <A HREF="http://github.com/guanzhi/GmSSL">Reference implementation using OpenSSL</A>.
9 /// \since Crypto++ 6.0
10 
11 #ifndef CRYPTOPP_SM4_H
12 #define CRYPTOPP_SM4_H
13 
14 #include "config.h"
15 #include "seckey.h"
16 #include "secblock.h"
17 
18 NAMESPACE_BEGIN(CryptoPP)
19 
20 /// \brief SM4 block cipher information
21 /// \since Crypto++ 6.0
22 struct SM4_Info : public FixedBlockSize<16>, FixedKeyLength<16>
23 {
24  static const std::string StaticAlgorithmName()
25  {
26  return "SM4";
27  }
28 };
29 
30 /// \brief Classes for the SM4 block cipher
31 /// \details SM4 is a block cipher designed by Xiaoyun Wang, et al. The block cipher is part of the
32 /// Chinese State Cryptography Administration portfolio. The cipher was formely known as SMS4.
33 /// \sa <A HREF="http://eprint.iacr.org/2008/329.pdf">SMS4 Encryption Algorithm for Wireless Networks</A>
34 /// \since Crypto++ 6.0
35 class CRYPTOPP_NO_VTABLE SM4 : public SM4_Info, public BlockCipherDocumentation
36 {
37 public:
38  /// \brief SM4 block cipher transformation functions
39  /// \details Provides implementation common to encryption and decryption
40  /// \since Crypto++ 6.0
41  class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SM4_Info>
42  {
43  protected:
44  void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
45  protected:
48  };
49 
50  /// \brief Provides implementation for encryption transformation
51  /// \details Enc provides implementation for encryption transformation. All key
52  /// sizes are supported.
53  /// \since Crypto++ 6.0
54  class CRYPTOPP_NO_VTABLE Enc : public Base
55  {
56  protected:
57  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
58  };
59 
60  /// \brief Provides implementation for encryption transformation
61  /// \details Dec provides implementation for decryption transformation. All key
62  /// sizes are supported.
63  /// \since Crypto++ 6.0
64  class CRYPTOPP_NO_VTABLE Dec : public Base
65  {
66  protected:
67  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
68  };
69 
72 };
73 
74 NAMESPACE_END
75 
76 #endif // CRYPTOPP_SM4_H
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:147
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher...
Definition: seckey.h:420
Secure memory block with allocator and cleanup.
Definition: secblock.h:454
Library configuration file.
Provides implementation for encryption transformation.
Definition: sm4.h:54
Interface for one direction (encryption or decryption) of a block cipher.
Definition: cryptlib.h:1231
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.
Classes for the SM4 block cipher.
Definition: sm4.h:35
SM4 block cipher transformation functions.
Definition: sm4.h:41
SM4 block cipher information.
Definition: sm4.h:22
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:327
Crypto++ library namespace.
Provides implementation for encryption transformation.
Definition: sm4.h:64
Interface for retrieving values given their names.
Definition: cryptlib.h:290