Security Scol plugin
kalyna.h
Go to the documentation of this file.
1// kalyna.h - written and placed in the public domain by Jeffrey Walton
2// Based on public domain code by Keru Kuro.
3
13
14#ifndef CRYPTOPP_KALYNA_H
15#define CRYPTOPP_KALYNA_H
16
17#include "config.h"
18#include "seckey.h"
19#include "secblock.h"
20
21NAMESPACE_BEGIN(CryptoPP)
22
23
25struct CRYPTOPP_NO_VTABLE Kalyna128_Info : public FixedBlockSize<16>, VariableKeyLength<16, 16, 32>
26{
27 static const char* StaticAlgorithmName()
28 {
29 // Format is Cipher-Blocksize(Keylength)
30 return "Kalyna-128";
31 }
32};
33
36struct CRYPTOPP_NO_VTABLE Kalyna256_Info : public FixedBlockSize<32>, VariableKeyLength<32, 32, 64>
37{
38 static const char* StaticAlgorithmName()
39 {
40 // Format is Cipher-Blocksize(Keylength)
41 return "Kalyna-256";
42 }
43};
44
47struct CRYPTOPP_NO_VTABLE Kalyna512_Info : public FixedBlockSize<64>, FixedKeyLength<64>
48{
49 static const char* StaticAlgorithmName()
50 {
51 // Format is Cipher-Blocksize(Keylength)
52 return "Kalyna-512";
53 }
54};
55
58class CRYPTOPP_NO_VTABLE Kalyna_Base
59{
60public:
61 virtual ~Kalyna_Base() {}
62
63protected:
65 mutable AlignedSecBlock64 m_wspace; // work space
66 AlignedSecBlock64 m_mkey; // master key
67 AlignedSecBlock64 m_rkeys; // round keys
68 unsigned int m_kl, m_nb, m_nk; // number 64-bit blocks and keys
69};
70
75{
76public:
77 class CRYPTOPP_NO_VTABLE Base : public Kalyna_Base, public BlockCipherImpl<Kalyna128_Info>
78 {
79 public:
91 std::string AlgorithmName() const {
92 return std::string("Kalyna-128") + "(" + IntToString(m_kl*8) + ")";
93 }
94
98 unsigned int OptimalDataAlignment() const {
99 return GetAlignmentOf<word64>();
100 }
101
102 protected:
103 void UncheckedSetKey(const byte *key, unsigned int keylen, const NameValuePairs &params);
104 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
105
106 protected:
107 void SetKey_22(const word64 key[2]);
108 void SetKey_24(const word64 key[4]);
109 void ProcessBlock_22(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
110 void ProcessBlock_24(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
111 };
112
113 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
114 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
115};
116
121{
122public:
123 class CRYPTOPP_NO_VTABLE Base : public Kalyna_Base, public BlockCipherImpl<Kalyna256_Info>
124 {
125 public:
137 std::string AlgorithmName() const {
138 return std::string("Kalyna-256") + "(" + IntToString(m_kl*8) + ")";
139 }
140
144 unsigned int OptimalDataAlignment() const {
145 return GetAlignmentOf<word64>();
146 }
147
148 protected:
149 void UncheckedSetKey(const byte *key, unsigned int keylen, const NameValuePairs &params);
150 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
151
152 protected:
153 void SetKey_44(const word64 key[4]);
154 void SetKey_48(const word64 key[8]);
155 void ProcessBlock_44(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
156 void ProcessBlock_48(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
157 };
158
159 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
160 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
161};
162
167{
168public:
169 class CRYPTOPP_NO_VTABLE Base : public Kalyna_Base, public BlockCipherImpl<Kalyna512_Info>
170 {
171 public:
183 std::string AlgorithmName() const {
184 return std::string("Kalyna-512") + "(" + IntToString(m_kl*8) + ")";
185 }
186
190 unsigned int OptimalDataAlignment() const {
191 return GetAlignmentOf<word64>();
192 }
193
194 protected:
195 void UncheckedSetKey(const byte *key, unsigned int keylen, const NameValuePairs &params);
196 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
197
198 protected:
199 void SetKey_88(const word64 key[8]);
200 void ProcessBlock_88(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
201 };
202
203 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
204 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
205};
206
209
212
215
216NAMESPACE_END
217
218#endif // CRYPTOPP_KALYNA_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
Inherited by keyed algorithms with fixed key length.
Definition seckey.h:125
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition kalyna.h:98
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition kalyna.h:91
Kalyna 128-bit block cipher.
Definition kalyna.h:75
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition kalyna.h:144
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition kalyna.h:137
Kalyna 256-bit block cipher.
Definition kalyna.h:121
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition kalyna.h:183
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition kalyna.h:190
Kalyna 512-bit block cipher.
Definition kalyna.h:167
Kalyna block cipher base class.
Definition kalyna.h:59
Interface for retrieving values given their names.
Definition cryptlib.h:322
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.
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
Kalyna-128 block cipher information.
Definition kalyna.h:26
Kalyna-256 block cipher information.
Definition kalyna.h:37
Kalyna-512 block cipher information.
Definition kalyna.h:48