File indexing completed on 2025-01-18 09:55:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef CRYPTOPP_KALYNA_H
0015 #define CRYPTOPP_KALYNA_H
0016
0017 #include "config.h"
0018 #include "seckey.h"
0019 #include "secblock.h"
0020
0021 NAMESPACE_BEGIN(CryptoPP)
0022
0023
0024
0025 struct CRYPTOPP_NO_VTABLE Kalyna128_Info : public FixedBlockSize<16>, VariableKeyLength<16, 16, 32>
0026 {
0027 static const char* StaticAlgorithmName()
0028 {
0029
0030 return "Kalyna-128";
0031 }
0032 };
0033
0034
0035
0036 struct CRYPTOPP_NO_VTABLE Kalyna256_Info : public FixedBlockSize<32>, VariableKeyLength<32, 32, 64>
0037 {
0038 static const char* StaticAlgorithmName()
0039 {
0040
0041 return "Kalyna-256";
0042 }
0043 };
0044
0045
0046
0047 struct CRYPTOPP_NO_VTABLE Kalyna512_Info : public FixedBlockSize<64>, FixedKeyLength<64>
0048 {
0049 static const char* StaticAlgorithmName()
0050 {
0051
0052 return "Kalyna-512";
0053 }
0054 };
0055
0056
0057
0058 class CRYPTOPP_NO_VTABLE Kalyna_Base
0059 {
0060 public:
0061 virtual ~Kalyna_Base() {}
0062
0063 protected:
0064 typedef SecBlock<word64, AllocatorWithCleanup<word64, true> > AlignedSecBlock64;
0065 mutable AlignedSecBlock64 m_wspace;
0066 AlignedSecBlock64 m_mkey;
0067 AlignedSecBlock64 m_rkeys;
0068 unsigned int m_kl, m_nb, m_nk;
0069 };
0070
0071
0072
0073
0074 class Kalyna128 : public Kalyna128_Info, public BlockCipherDocumentation
0075 {
0076 public:
0077 class CRYPTOPP_NO_VTABLE Base : public Kalyna_Base, public BlockCipherImpl<Kalyna128_Info>
0078 {
0079 public:
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 std::string AlgorithmName() const {
0092 return std::string("Kalyna-128") + "(" + IntToString(m_kl*8) + ")";
0093 }
0094
0095
0096
0097
0098 unsigned int OptimalDataAlignment() const {
0099 return GetAlignmentOf<word64>();
0100 }
0101
0102 protected:
0103 void UncheckedSetKey(const byte *key, unsigned int keylen, const NameValuePairs ¶ms);
0104 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0105
0106 protected:
0107 void SetKey_22(const word64 key[2]);
0108 void SetKey_24(const word64 key[4]);
0109 void ProcessBlock_22(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0110 void ProcessBlock_24(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0111 };
0112
0113 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
0114 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
0115 };
0116
0117
0118
0119
0120 class Kalyna256 : public Kalyna256_Info, public BlockCipherDocumentation
0121 {
0122 public:
0123 class CRYPTOPP_NO_VTABLE Base : public Kalyna_Base, public BlockCipherImpl<Kalyna256_Info>
0124 {
0125 public:
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137 std::string AlgorithmName() const {
0138 return std::string("Kalyna-256") + "(" + IntToString(m_kl*8) + ")";
0139 }
0140
0141
0142
0143
0144 unsigned int OptimalDataAlignment() const {
0145 return GetAlignmentOf<word64>();
0146 }
0147
0148 protected:
0149 void UncheckedSetKey(const byte *key, unsigned int keylen, const NameValuePairs ¶ms);
0150 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0151
0152 protected:
0153 void SetKey_44(const word64 key[4]);
0154 void SetKey_48(const word64 key[8]);
0155 void ProcessBlock_44(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0156 void ProcessBlock_48(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0157 };
0158
0159 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
0160 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
0161 };
0162
0163
0164
0165
0166 class Kalyna512 : public Kalyna512_Info, public BlockCipherDocumentation
0167 {
0168 public:
0169 class CRYPTOPP_NO_VTABLE Base : public Kalyna_Base, public BlockCipherImpl<Kalyna512_Info>
0170 {
0171 public:
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183 std::string AlgorithmName() const {
0184 return std::string("Kalyna-512") + "(" + IntToString(m_kl*8) + ")";
0185 }
0186
0187
0188
0189
0190 unsigned int OptimalDataAlignment() const {
0191 return GetAlignmentOf<word64>();
0192 }
0193
0194 protected:
0195 void UncheckedSetKey(const byte *key, unsigned int keylen, const NameValuePairs ¶ms);
0196 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0197
0198 protected:
0199 void SetKey_88(const word64 key[8]);
0200 void ProcessBlock_88(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0201 };
0202
0203 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
0204 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
0205 };
0206
0207 typedef Kalyna128::Encryption Kalyna128Encryption;
0208 typedef Kalyna128::Decryption Kalyna128Decryption;
0209
0210 typedef Kalyna256::Encryption Kalyna256Encryption;
0211 typedef Kalyna256::Decryption Kalyna256Decryption;
0212
0213 typedef Kalyna512::Encryption Kalyna512Encryption;
0214 typedef Kalyna512::Decryption Kalyna512Decryption;
0215
0216 NAMESPACE_END
0217
0218 #endif