File indexing completed on 2025-01-18 09:55:08
0001
0002
0003
0004
0005
0006
0007 #ifndef CRYPTOPP_RC2_H
0008 #define CRYPTOPP_RC2_H
0009
0010 #include "seckey.h"
0011 #include "secblock.h"
0012 #include "algparam.h"
0013
0014 NAMESPACE_BEGIN(CryptoPP)
0015
0016
0017
0018 struct RC2_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 1, 128>
0019 {
0020 CRYPTOPP_CONSTANT(DEFAULT_EFFECTIVE_KEYLENGTH = 1024);
0021 CRYPTOPP_CONSTANT(MAX_EFFECTIVE_KEYLENGTH = 1024);
0022 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "RC2";}
0023 };
0024
0025
0026
0027
0028 class RC2 : public RC2_Info, public BlockCipherDocumentation
0029 {
0030
0031
0032 class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<RC2_Info>
0033 {
0034 public:
0035 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
0036 unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word16>();}
0037
0038 protected:
0039 FixedSizeSecBlock<word16, 64> K;
0040 };
0041
0042
0043
0044 class CRYPTOPP_NO_VTABLE Enc : public Base
0045 {
0046 public:
0047 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0048 };
0049
0050
0051
0052 class CRYPTOPP_NO_VTABLE Dec : public Base
0053 {
0054 public:
0055 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0056 };
0057
0058 public:
0059
0060
0061
0062 class Encryption : public BlockCipherFinal<ENCRYPTION, Enc>
0063 {
0064 public:
0065 Encryption() {}
0066 Encryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
0067 {SetKey(key, keyLen);}
0068 Encryption(const byte *key, size_t keyLen, int effectiveKeyLen)
0069 {SetKey(key, keyLen, MakeParameters("EffectiveKeyLength", effectiveKeyLen));}
0070 };
0071
0072
0073
0074 class Decryption : public BlockCipherFinal<DECRYPTION, Dec>
0075 {
0076 public:
0077 Decryption() {}
0078 Decryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
0079 {SetKey(key, keyLen);}
0080 Decryption(const byte *key, size_t keyLen, int effectiveKeyLen)
0081 {SetKey(key, keyLen, MakeParameters("EffectiveKeyLength", effectiveKeyLen));}
0082 };
0083 };
0084
0085 typedef RC2::Encryption RC2Encryption;
0086 typedef RC2::Decryption RC2Decryption;
0087
0088 NAMESPACE_END
0089
0090 #endif