Warning, file /include/cryptopp/simon.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef CRYPTOPP_SIMON_H
0014 #define CRYPTOPP_SIMON_H
0015
0016 #include "config.h"
0017 #include "seckey.h"
0018 #include "secblock.h"
0019
0020 #if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86 || \
0021 CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARMV8 || \
0022 CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64
0023 # ifndef CRYPTOPP_DISABLE_SIMON_SIMD
0024 # define CRYPTOPP_SIMON128_ADVANCED_PROCESS_BLOCKS 1
0025 # endif
0026 #endif
0027
0028
0029
0030 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5120)
0031 # undef CRYPTOPP_SIMON128_ADVANCED_PROCESS_BLOCKS
0032 #endif
0033
0034 NAMESPACE_BEGIN(CryptoPP)
0035
0036
0037
0038
0039
0040
0041
0042 template <unsigned int L, unsigned int D, unsigned int N, unsigned int M>
0043 struct SIMON_Info : public FixedBlockSize<L>, VariableKeyLength<D, N, M>
0044 {
0045
0046
0047
0048
0049 static const std::string StaticAlgorithmName()
0050 {
0051
0052 return "SIMON-" + IntToString(L*8);
0053 }
0054 };
0055
0056
0057
0058
0059
0060
0061 template <class W>
0062 struct SIMON_Base
0063 {
0064 virtual ~SIMON_Base() {}
0065 SIMON_Base() : m_kwords(0), m_rounds(0) {}
0066
0067 typedef SecBlock<W, AllocatorWithCleanup<W, true> > AlignedSecBlock;
0068 mutable AlignedSecBlock m_wspace;
0069 AlignedSecBlock m_rkeys;
0070 unsigned int m_kwords;
0071 unsigned int m_rounds;
0072 };
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083 class CRYPTOPP_NO_VTABLE SIMON64 : public SIMON_Info<8, 12, 12, 16>, public BlockCipherDocumentation
0084 {
0085 public:
0086
0087
0088
0089 class CRYPTOPP_NO_VTABLE Base : protected SIMON_Base<word32>, public BlockCipherImpl<SIMON_Info<8, 12, 12, 16> >
0090 {
0091 public:
0092
0093
0094
0095
0096 std::string AlgorithmName() const {
0097 return StaticAlgorithmName() + (m_kwords == 0 ? "" :
0098 "(" + IntToString(m_kwords*sizeof(word32)*8) + ")");
0099 }
0100
0101 std::string AlgorithmProvider() const;
0102
0103
0104
0105
0106 unsigned int OptimalDataAlignment() const;
0107
0108 protected:
0109 void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs ¶ms);
0110 };
0111
0112
0113
0114
0115
0116 class CRYPTOPP_NO_VTABLE Enc : public Base
0117 {
0118 public:
0119 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0120 };
0121
0122
0123
0124
0125
0126 class CRYPTOPP_NO_VTABLE Dec : public Base
0127 {
0128 public:
0129 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0130 };
0131
0132 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
0133 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
0134 };
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145 class CRYPTOPP_NO_VTABLE SIMON128 : public SIMON_Info<16, 16, 16, 32>, public BlockCipherDocumentation
0146 {
0147 public:
0148
0149
0150
0151 class CRYPTOPP_NO_VTABLE Base : protected SIMON_Base<word64>, public BlockCipherImpl<SIMON_Info<16, 16, 16, 32> >
0152 {
0153 public:
0154
0155
0156
0157
0158 std::string AlgorithmName() const {
0159 return StaticAlgorithmName() + (m_kwords == 0 ? "" :
0160 "(" + IntToString(m_kwords*sizeof(word64)*8) + ")");
0161 }
0162
0163 std::string AlgorithmProvider() const;
0164
0165
0166
0167
0168 unsigned int OptimalDataAlignment() const;
0169
0170 protected:
0171 void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs ¶ms);
0172 };
0173
0174
0175
0176
0177
0178 class CRYPTOPP_NO_VTABLE Enc : public Base
0179 {
0180 public:
0181 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0182 #if CRYPTOPP_SIMON128_ADVANCED_PROCESS_BLOCKS
0183 size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
0184 #endif
0185 };
0186
0187
0188
0189
0190
0191 class CRYPTOPP_NO_VTABLE Dec : public Base
0192 {
0193 public:
0194 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0195 #if CRYPTOPP_SIMON128_ADVANCED_PROCESS_BLOCKS
0196 size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
0197 #endif
0198 };
0199
0200 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
0201 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
0202 };
0203
0204 NAMESPACE_END
0205
0206 #endif