Security Scol plugin
speck.h
Go to the documentation of this file.
1// speck.h - written and placed in the public domain by Jeffrey Walton
2
12
13#ifndef CRYPTOPP_SPECK_H
14#define CRYPTOPP_SPECK_H
15
16#include "config.h"
17#include "seckey.h"
18#include "secblock.h"
19
20#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86 || \
21 CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARMV8 || \
22 CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64
23# ifndef CRYPTOPP_DISABLE_SPECK_SIMD
24# define CRYPTOPP_SPECK128_ADVANCED_PROCESS_BLOCKS 1
25# endif
26#endif
27
28// Yet another SunStudio/SunCC workaround. Failed self tests
29// in SSE code paths on i386 for SunStudio 12.3 and below.
30#if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5120)
31# undef CRYPTOPP_SPECK128_ADVANCED_PROCESS_BLOCKS
32#endif
33
34NAMESPACE_BEGIN(CryptoPP)
35
36
42template <unsigned int L, unsigned int D, unsigned int N, unsigned int M>
43struct SPECK_Info : public FixedBlockSize<L>, VariableKeyLength<D, N, M>
44{
49 static const std::string StaticAlgorithmName()
50 {
51 // Format is Cipher-Blocksize(Keylength)
52 return "SPECK-" + IntToString(L*8);
53 }
54};
55
61template <class W>
63{
64 virtual ~SPECK_Base() {}
65 SPECK_Base() : m_kwords(0), m_rounds(0) {}
66
68 mutable AlignedSecBlock m_wspace; // workspace
69 AlignedSecBlock m_rkeys; // round keys
70 unsigned int m_kwords; // number of key words
71 unsigned int m_rounds; // number of rounds
72};
73
83class CRYPTOPP_NO_VTABLE SPECK64 : public SPECK_Info<8, 12, 12, 16>, public BlockCipherDocumentation
84{
85public:
89 class CRYPTOPP_NO_VTABLE Base : protected SPECK_Base<word32>, public BlockCipherImpl<SPECK_Info<8, 12, 12, 16> >
90 {
91 public:
96 std::string AlgorithmName() const {
97 return StaticAlgorithmName() + (m_kwords == 0 ? "" :
98 "(" + IntToString(m_kwords*sizeof(word32)*8) + ")");
99 }
100
101 std::string AlgorithmProvider() const;
102
106 unsigned int OptimalDataAlignment() const;
107
108 protected:
109 void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
110 };
111
116 class CRYPTOPP_NO_VTABLE Enc : public Base
117 {
118 public:
119 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
120 };
121
126 class CRYPTOPP_NO_VTABLE Dec : public Base
127 {
128 public:
129 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
130 };
131
134};
135
145class CRYPTOPP_NO_VTABLE SPECK128 : public SPECK_Info<16, 16, 16, 32>, public BlockCipherDocumentation
146{
147public:
151 class CRYPTOPP_NO_VTABLE Base : protected SPECK_Base<word64>, public BlockCipherImpl<SPECK_Info<16, 16, 16, 32> >
152 {
153 public:
158 std::string AlgorithmName() const {
159 return StaticAlgorithmName() + (m_kwords == 0 ? "" :
160 "(" + IntToString(m_kwords*sizeof(word64)*8) + ")");
161 }
162
163 std::string AlgorithmProvider() const;
164
168 unsigned int OptimalDataAlignment() const;
169
170 protected:
171 void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
172 };
173
178 class CRYPTOPP_NO_VTABLE Enc : public Base
179 {
180 public:
181 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
182#if CRYPTOPP_SPECK128_ADVANCED_PROCESS_BLOCKS
183 size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
184#endif
185 };
186
191 class CRYPTOPP_NO_VTABLE Dec : public Base
192 {
193 public:
194 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
195#if CRYPTOPP_SPECK128_ADVANCED_PROCESS_BLOCKS
196 size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
197#endif
198 };
199
202};
203
204NAMESPACE_END
205
206#endif // CRYPTOPP_SPECK_H
Provides class member functions to key a block cipher.
Definition seckey.h:318
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
Interface for retrieving values given their names.
Definition cryptlib.h:322
SPECK128 block cipher base implementation.
Definition speck.h:152
std::string AlgorithmName() const
The algorithm name.
Definition speck.h:158
SPECK128 decryption transformation.
Definition speck.h:192
SPECK128 encryption transformation.
Definition speck.h:179
SPECK 128-bit block cipher.
Definition speck.h:146
SPECK64 block cipher base implementation.
Definition speck.h:90
std::string AlgorithmName() const
The algorithm name.
Definition speck.h:96
SPECK64 decryption transformation.
Definition speck.h:127
SPECK64 encryption transformation.
Definition speck.h:117
SPECK 64-bit block cipher.
Definition speck.h:84
Secure memory block with allocator and cleanup.
Definition secblock.h:731
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
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Definition misc.h:724
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
SPECK block cipher base class.
Definition speck.h:63
SPECK block cipher information.
Definition speck.h:44
static const std::string StaticAlgorithmName()
The algorithm name.
Definition speck.h:49