move ARC4 into Weak namespace

pull/2/head
weidai 2007-04-16 21:27:41 +00:00
parent 3a3fef7436
commit deb3228e83
6 changed files with 27 additions and 10 deletions

View File

@ -371,7 +371,7 @@ the mailing list.
- enabled optimization flags by default in GNUmakefile - enabled optimization flags by default in GNUmakefile
- changed PANAMA cipher interface to accept 256-bit key and 256-bit IV - changed PANAMA cipher interface to accept 256-bit key and 256-bit IV
- added blinding and error checking for RW private key operation - added blinding and error checking for RW private key operation
- moved MD2, MD4, MD5, PanamaHash, WAKE_CFB into the namespace "Weak" - moved MD2, MD4, MD5, PanamaHash, ARC4, WAKE_CFB into the namespace "Weak"
- removed HAVAL, MD5-MAC, XMAC - removed HAVAL, MD5-MAC, XMAC
Written by Wei Dai Written by Wei Dai

View File

@ -7,9 +7,11 @@
// completely in the public domain. // completely in the public domain.
#include "pch.h" #include "pch.h"
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK
#include "arc4.h" #include "arc4.h"
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
namespace Weak {
void ARC4_TestInstantiations() void ARC4_TestInstantiations()
{ {
@ -113,4 +115,5 @@ void ARC4_Base::DiscardBytes(size_t length)
m_y = y; m_y = y;
} }
}
NAMESPACE_END NAMESPACE_END

12
arc4.h
View File

@ -5,6 +5,8 @@
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
namespace Weak {
//! _ //! _
class CRYPTOPP_NO_VTABLE ARC4_Base : public VariableKeyLength<16, 1, 256>, public RandomNumberGenerator, public SymmetricCipher, public SymmetricCipherDocumentation class CRYPTOPP_NO_VTABLE ARC4_Base : public VariableKeyLength<16, 1, 256>, public RandomNumberGenerator, public SymmetricCipher, public SymmetricCipherDocumentation
{ {
@ -52,6 +54,16 @@ protected:
//! Modified ARC4: it discards the first 256 bytes of keystream which may be weaker than the rest //! Modified ARC4: it discards the first 256 bytes of keystream which may be weaker than the rest
DOCUMENTED_TYPEDEF(SymmetricCipherFinal<MARC4_Base>, MARC4) DOCUMENTED_TYPEDEF(SymmetricCipherFinal<MARC4_Base>, MARC4)
}
#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 NAMESPACE_END
#endif #endif

View File

@ -7,7 +7,6 @@
#include "adler32.h" #include "adler32.h"
#include "idea.h" #include "idea.h"
#include "des.h" #include "des.h"
#include "arc4.h"
#include "rc5.h" #include "rc5.h"
#include "blowfish.h" #include "blowfish.h"
#include "wake.h" #include "wake.h"
@ -280,7 +279,7 @@ void BenchmarkAll(double t, double hertz)
cout << "\n<TBODY style=\"background: yellow\">"; cout << "\n<TBODY style=\"background: yellow\">";
BenchMarkKeyless<CRC32>("CRC-32", t); BenchMarkKeyless<CRC32>("CRC-32", t);
BenchMarkKeyless<Adler32>("Adler-32", t); BenchMarkKeyless<Adler32>("Adler-32", t);
BenchMarkByNameKeyLess<HashTransformation>("MD5", "MD5 (broken)"); BenchMarkByNameKeyLess<HashTransformation>("MD5", "MD5 (weak)");
BenchMarkByNameKeyLess<HashTransformation>("SHA-1"); BenchMarkByNameKeyLess<HashTransformation>("SHA-1");
BenchMarkByNameKeyLess<HashTransformation>("SHA-256"); BenchMarkByNameKeyLess<HashTransformation>("SHA-256");
#ifdef WORD64_AVAILABLE #ifdef WORD64_AVAILABLE
@ -300,7 +299,7 @@ void BenchmarkAll(double t, double hertz)
BenchMarkByName<SymmetricCipher>("Salsa20", 0, "Salsa20/12", MakeParameters(Name::Rounds(), 12)); BenchMarkByName<SymmetricCipher>("Salsa20", 0, "Salsa20/12", MakeParameters(Name::Rounds(), 12));
BenchMarkByName<SymmetricCipher>("Salsa20", 0, "Salsa20/8", MakeParameters(Name::Rounds(), 8)); BenchMarkByName<SymmetricCipher>("Salsa20", 0, "Salsa20/8", MakeParameters(Name::Rounds(), 8));
BenchMarkByName<SymmetricCipher>("Sosemanuk"); BenchMarkByName<SymmetricCipher>("Sosemanuk");
BenchMarkKeyed<ARC4>("ARC4", t); BenchMarkByName<SymmetricCipher>("MARC4");
BenchMarkKeyed<SEAL<BigEndian>::Encryption>("SEAL-3.0-BE", t); BenchMarkKeyed<SEAL<BigEndian>::Encryption>("SEAL-3.0-BE", t);
BenchMarkKeyed<SEAL<LittleEndian>::Encryption>("SEAL-3.0-LE", t); BenchMarkKeyed<SEAL<LittleEndian>::Encryption>("SEAL-3.0-LE", t);
BenchMarkKeyed<WAKE_OFB<BigEndian>::Encryption>("WAKE-OFB-BE", t); BenchMarkKeyed<WAKE_OFB<BigEndian>::Encryption>("WAKE-OFB-BE", t);

View File

@ -24,6 +24,7 @@
#include "tiger.h" #include "tiger.h"
#include "md5.h" #include "md5.h"
#include "sosemanuk.h" #include "sosemanuk.h"
#include "arc4.h"
USING_NAMESPACE(CryptoPP) USING_NAMESPACE(CryptoPP)
@ -82,6 +83,7 @@ void RegisterFactories()
RegisterSymmetricCipherDefaultFactories<CTR_Mode<AES> >(); RegisterSymmetricCipherDefaultFactories<CTR_Mode<AES> >();
RegisterSymmetricCipherDefaultFactories<Salsa20>(); RegisterSymmetricCipherDefaultFactories<Salsa20>();
RegisterSymmetricCipherDefaultFactories<Sosemanuk>(); RegisterSymmetricCipherDefaultFactories<Sosemanuk>();
RegisterSymmetricCipherDefaultFactories<Weak::MARC4>();
s_registered = true; s_registered = true;
} }

View File

@ -2,6 +2,7 @@
#include "pch.h" #include "pch.h"
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK
#include "files.h" #include "files.h"
#include "hex.h" #include "hex.h"
#include "base32.h" #include "base32.h"
@ -991,39 +992,39 @@ bool ValidateARC4()
0xc0}; 0xc0};
// VC60 workaround: auto_ptr lacks reset() // VC60 workaround: auto_ptr lacks reset()
member_ptr<ARC4> arc4; member_ptr<Weak::ARC4> arc4;
bool pass=true, fail; bool pass=true, fail;
int i; int i;
cout << "\nARC4 validation suite running...\n\n"; cout << "\nARC4 validation suite running...\n\n";
arc4.reset(new ARC4(Key0, sizeof(Key0))); arc4.reset(new Weak::ARC4(Key0, sizeof(Key0)));
arc4->ProcessString(Input0, sizeof(Input0)); arc4->ProcessString(Input0, sizeof(Input0));
fail = memcmp(Input0, Output0, sizeof(Input0)) != 0; fail = memcmp(Input0, Output0, sizeof(Input0)) != 0;
cout << (fail ? "FAILED" : "passed") << " Test 0" << endl; cout << (fail ? "FAILED" : "passed") << " Test 0" << endl;
pass = pass && !fail; pass = pass && !fail;
arc4.reset(new ARC4(Key1, sizeof(Key1))); arc4.reset(new Weak::ARC4(Key1, sizeof(Key1)));
arc4->ProcessString(Key1, Input1, sizeof(Key1)); arc4->ProcessString(Key1, Input1, sizeof(Key1));
fail = memcmp(Output1, Key1, sizeof(Key1)) != 0; fail = memcmp(Output1, Key1, sizeof(Key1)) != 0;
cout << (fail ? "FAILED" : "passed") << " Test 1" << endl; cout << (fail ? "FAILED" : "passed") << " Test 1" << endl;
pass = pass && !fail; pass = pass && !fail;
arc4.reset(new ARC4(Key2, sizeof(Key2))); arc4.reset(new Weak::ARC4(Key2, sizeof(Key2)));
for (i=0, fail=false; i<sizeof(Input2); i++) for (i=0, fail=false; i<sizeof(Input2); i++)
if (arc4->ProcessByte(Input2[i]) != Output2[i]) if (arc4->ProcessByte(Input2[i]) != Output2[i])
fail = true; fail = true;
cout << (fail ? "FAILED" : "passed") << " Test 2" << endl; cout << (fail ? "FAILED" : "passed") << " Test 2" << endl;
pass = pass && !fail; pass = pass && !fail;
arc4.reset(new ARC4(Key3, sizeof(Key3))); arc4.reset(new Weak::ARC4(Key3, sizeof(Key3)));
for (i=0, fail=false; i<sizeof(Input3); i++) for (i=0, fail=false; i<sizeof(Input3); i++)
if (arc4->ProcessByte(Input3[i]) != Output3[i]) if (arc4->ProcessByte(Input3[i]) != Output3[i])
fail = true; fail = true;
cout << (fail ? "FAILED" : "passed") << " Test 3" << endl; cout << (fail ? "FAILED" : "passed") << " Test 3" << endl;
pass = pass && !fail; pass = pass && !fail;
arc4.reset(new ARC4(Key4, sizeof(Key4))); arc4.reset(new Weak::ARC4(Key4, sizeof(Key4)));
for (i=0, fail=false; i<sizeof(Input4); i++) for (i=0, fail=false; i<sizeof(Input4); i++)
if (arc4->ProcessByte(Input4[i]) != Output4[i]) if (arc4->ProcessByte(Input4[i]) != Output4[i])
fail = true; fail = true;