diff --git a/md2.cpp b/md2.cpp index 1021932f..9e07712f 100644 --- a/md2.cpp +++ b/md2.cpp @@ -15,10 +15,12 @@ */ #include "pch.h" +#define CRYPTOPP_ENABLE_NAMESPACE_WEAK #include "md2.h" NAMESPACE_BEGIN(CryptoPP) - +namespace Weak { + MD2::MD2() : m_X(48), m_C(16), m_buf(16) { @@ -114,4 +116,5 @@ void MD2::TruncatedFinal(byte *hash, size_t size) Init(); } +} NAMESPACE_END diff --git a/md2.h b/md2.h index 01af36d7..4e8ac4b0 100644 --- a/md2.h +++ b/md2.h @@ -6,8 +6,9 @@ NAMESPACE_BEGIN(CryptoPP) -/// MD2 -/** 128 Bit Hash */ +namespace Weak { + +/// MD2 class MD2 : public HashTransformation { public: @@ -28,6 +29,16 @@ private: unsigned int m_count; }; +} +#ifndef CRYPTOPP_ENABLE_NAMESPACE_WEAK +using namespace Weak; +#ifdef __GNUC__ +#warning "You may be using a weak algorithm that has been retained for backwards compatibility. Please define CRYPTOPP_ENABLE_NAMESPACE_WEAK and prepend the class name with 'Weak::' to remove this warning." +#else +#pragma message("You may be using a weak algorithm that has been retained for backwards compatibility. Please define CRYPTOPP_ENABLE_NAMESPACE_WEAK and prepend the class name with 'Weak::' to remove this warning.") +#endif +#endif + NAMESPACE_END #endif diff --git a/md4.cpp b/md4.cpp index c67ef066..f032fc05 100644 --- a/md4.cpp +++ b/md4.cpp @@ -15,10 +15,12 @@ */ #include "pch.h" +#define CRYPTOPP_ENABLE_NAMESPACE_WEAK #include "md4.h" #include "misc.h" NAMESPACE_BEGIN(CryptoPP) +namespace Weak { void MD4::InitState(HashWordType *state) { @@ -104,4 +106,5 @@ void MD4::Transform (word32 *digest, const word32 *in) digest[3]+=D; } +} NAMESPACE_END diff --git a/md4.h b/md4.h index bf5399c1..d80a3d70 100644 --- a/md4.h +++ b/md4.h @@ -5,6 +5,8 @@ NAMESPACE_BEGIN(CryptoPP) +namespace Weak { + //! MD4 /*! \warning MD4 is considered insecure, and should not be used unless you absolutely need it for compatibility. */ @@ -16,6 +18,16 @@ public: static const char *StaticAlgorithmName() {return "MD4";} }; +} +#ifndef CRYPTOPP_ENABLE_NAMESPACE_WEAK +using namespace Weak; +#ifdef __GNUC__ +#warning "You may be using a weak algorithm that has been retained for backwards compatibility. Please define CRYPTOPP_ENABLE_NAMESPACE_WEAK and prepend the class name with 'Weak::' to remove this warning." +#else +#pragma message("You may be using a weak algorithm that has been retained for backwards compatibility. Please define CRYPTOPP_ENABLE_NAMESPACE_WEAK and prepend the class name with 'Weak::' to remove this warning.") +#endif +#endif + NAMESPACE_END #endif diff --git a/md5.cpp b/md5.cpp index cfe81a27..839d0191 100644 --- a/md5.cpp +++ b/md5.cpp @@ -2,10 +2,12 @@ // any modifications are placed in the public domain #include "pch.h" +#define CRYPTOPP_ENABLE_NAMESPACE_WEAK #include "md5.h" #include "misc.h" NAMESPACE_BEGIN(CryptoPP) +namespace Weak { void MD5_TestInstantiations() { @@ -112,4 +114,5 @@ void MD5::Transform (word32 *digest, const word32 *in) digest[3]+=d; } +} NAMESPACE_END diff --git a/md5.h b/md5.h index 7fb9f172..944a4eec 100644 --- a/md5.h +++ b/md5.h @@ -5,9 +5,9 @@ NAMESPACE_BEGIN(CryptoPP) -//! MD5 -/*! \warning MD5 is considered insecure, and should not be used - unless you absolutely need it for compatibility. */ +namespace Weak { + +//! MD5 class MD5 : public IteratedHashWithStaticTransform { public: @@ -16,6 +16,16 @@ public: static const char * StaticAlgorithmName() {return "MD5";} }; +} +#ifndef CRYPTOPP_ENABLE_NAMESPACE_WEAK +using namespace Weak; +#ifdef __GNUC__ +#warning "You may be using a weak algorithm that has been retained for backwards compatibility. Please define CRYPTOPP_ENABLE_NAMESPACE_WEAK and prepend the class name with 'Weak::' to remove this warning." +#else +#pragma message("You may be using a weak algorithm that has been retained for backwards compatibility. Please define CRYPTOPP_ENABLE_NAMESPACE_WEAK and prepend the class name with 'Weak::' to remove this warning.") +#endif +#endif + NAMESPACE_END #endif diff --git a/wake.cpp b/wake.cpp index 2ada966c..504c2d35 100644 --- a/wake.cpp +++ b/wake.cpp @@ -7,8 +7,8 @@ NAMESPACE_BEGIN(CryptoPP) void WAKE_TestInstantiations() { - WAKE_CFB<>::Encryption x1; - WAKE_CFB<>::Decryption x3; + Weak::WAKE_CFB<>::Encryption x1; + Weak::WAKE_CFB<>::Decryption x3; WAKE_OFB<>::Encryption x2; WAKE_OFB<>::Decryption x4; } @@ -85,16 +85,21 @@ void WAKE_Policy::Iterate(byte *output, const byte *input, CipherDir dir, siz template void WAKE_Policy::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount) { - KeystreamOutput keystreamOperation(operation, output, input); - - while (iterationCount--) - { - keystreamOperation(r6); - r3 = M(r3, r6); - r4 = M(r4, r3); - r5 = M(r5, r4); - r6 = M(r6, r5); +#define WAKE_OUTPUT(x)\ + while (iterationCount--)\ + {\ + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 0, r6);\ + r3 = M(r3, r6);\ + r4 = M(r4, r3);\ + r5 = M(r5, r4);\ + r6 = M(r6, r5);\ + output += 4;\ + if (x == XOR_KEYSTREAM)\ + input += 4;\ } + + typedef word32 WordType; + CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH(WAKE_OUTPUT, 0); } /* template diff --git a/wake.h b/wake.h index 5186a50e..2fa00a8e 100644 --- a/wake.h +++ b/wake.h @@ -47,13 +47,15 @@ protected: bool IsRandomAccess() const {return false;} }; -//! WAKE-CFB-BE +namespace Weak { +//! WAKE-CFB-BE template struct WAKE_CFB : public WAKE_CFB_Info, public SymmetricCipherDocumentation { typedef SymmetricCipherFinal, CFB_EncryptionTemplate<> >, WAKE_CFB_Info > Encryption; typedef SymmetricCipherFinal, CFB_DecryptionTemplate<> >, WAKE_CFB_Info > Decryption; }; +} //! WAKE-OFB template