Skip to content

Commit

Permalink
fix EC2N skipping of optional seed, switch to public domain MARS code…
Browse files Browse the repository at this point in the history
…, deliver vc80.pdb to OutDir
  • Loading branch information
weidai11 committed Mar 28, 2009
1 parent 88e0d15 commit 3be02e9
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 153 deletions.
7 changes: 1 addition & 6 deletions License.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ This copyright applies only to this software distribution package
as a compilation, and does not imply a copyright on any particular
file in the package.

The following files are copyrighted by their respective original authors,
and their use is subject to additional licenses included in these files.

mars.cpp - Copyright 1998 Brian Gladman.

All other files in this compilation are placed in the public domain by
All individual files in this compilation are placed in the public domain by
Wei Dai and other contributors.

I would like to thank the following authors for placing their works into
Expand Down
7 changes: 5 additions & 2 deletions Readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Crypto++: a C++ Class Library of Cryptographic Schemes
Version 5.6.0 (3/15/2009)
Version 5.6.1 (in development)

Crypto++ Library is a free C++ class library of cryptographic schemes.
Currently the library contains the following algorithms:
Expand Down Expand Up @@ -28,7 +28,7 @@ Currently the library contains the following algorithms:
RIPEMD-256, RIPEMD-160, RIPEMD-320

RSA, DSA, ElGamal, Nyberg-Rueppel (NR),
public-key cryptography Rabin, Rabin-Williams (RW), LUC, LUCELG,
public-key cryptography Rabin-Williams (RW), LUC, LUCELG,
DLIES (variants of DHAES), ESIGN

padding schemes for public-key PKCS#1 v2.0, OAEP, PSS, PSSR, IEEE P1363
Expand Down Expand Up @@ -417,6 +417,7 @@ the mailing list.
5.6 - added AuthenticatedSymmetricCipher interface class and Filter wrappers
- added CCM, GCM (with SSE2 assembly), EAX, CMAC, XSalsa20, and SEED
- added support for variable length IVs
- added OIDs for Brainpool elliptic curve parameters
- improved AES and SHA-256 speed on x86 and x64
- fixed incorrect VMAC computation on message lengths
that are >64 mod 128 (x86 assembly version is not affected)
Expand All @@ -425,5 +426,7 @@ the mailing list.
- fixed HashFilter bug when putMessage=true
- removed WORD64_AVAILABLE; compiler support for 64-bit int is now required
- ported to GCC 4.3, C++Builder 2009, Sun CC 5.10, Intel C++ Compiler 11

5.6.1 - switched to a public domain implementation of MARS

Written by Wei Dai
1 change: 1 addition & 0 deletions TestVectors/all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ Test: TestVectors/ccm.txt
Test: TestVectors/gcm.txt
Test: TestVectors/cmac.txt
Test: TestVectors/eax.txt
Test: TestVectors/mars.txt
66 changes: 66 additions & 0 deletions TestVectors/mars.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
AlgorithmType: SymmetricCipher
Name: MARS/ECB
Key: 80000000000000000000000000000000
Plaintext: 00000000000000000000000000000000
Ciphertext: B3E2AD5608AC1B6733A7CB4FDF8F9952
Test: Encrypt
Key: 00000000000000000000000000000000
Plaintext: 00000000000000000000000000000000
Ciphertext: DCC07B8DFB0738D6E30A22DFCF27E886
Test: Encrypt
Key: 00000000000000000000000000000000
Plaintext: DCC07B8DFB0738D6E30A22DFCF27E886
Ciphertext: 33CAFFBDDC7F1DDA0F9C15FA2F30E2FF
Test: Encrypt
Key: CB14A1776ABBC1CDAFE7243DEF2CEA02
Plaintext: F94512A9B42D034EC4792204D708A69B
Ciphertext: 225DA2CB64B73F79069F21A5E3CB8522
Test: Encrypt
Key: 86EDF4DA31824CABEF6A4637C40B0BAB
Plaintext: 4DF955AD5B398D66408D620A2B27E1A9
Ciphertext: A4B737340AE6D2CAFD930BA97D86129F
Test: Encrypt
Key: 000000000000000000000000000000000000000000000000
Plaintext: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Ciphertext: 97778747D60E425C2B4202599DB856FB
Test: Encrypt
Key: D158860838874D9500000000000000000000000000000000
Plaintext: 93A953A82C10411DD158860838874D95
Ciphertext: 4FA0E5F64893131712F01408D233E9F7
Test: Encrypt
Key: 791739A58B04581A93A953A82C10411DD158860838874D95
Plaintext: 6761C42D3E6142D2A84FBFADB383158F
Ciphertext: F706BC0FD97E28B6F1AF4E17D8755FFF
Test: Encrypt
Key: 0000000000000000000000000000000000000000000000000000000000000000
Plaintext: 62E45B4CF3477F1DD65063729D9ABA8F
Ciphertext: 0F4B897EA014D21FBC20F1054A42F719
Test: Encrypt
Key: FBA167983E7AEF22317CE28C02AAE1A3E8E5CC3CEDBEA82A99DBC39AD65E7227
Plaintext: 1344ABA4D3C44708A8A72116D4F49384
Ciphertext: 458335D95EA42A9F4DCCD41AECC2390D
Test: Encrypt
Key: 00000000000000000000000000000000
Plaintext: 00000000000000000000000000000000
Ciphertext: 3FE24DC09173D15F4616A849D396F7E3
Test: EncryptionMCT
Key: 00000000000000000000000000000000
Plaintext: 24BD3D2FC6FEE152D1D64545E2230584
Ciphertext: 00000000000000000000000000000000
Test: DecryptionMCT
Key: 000000000000000000000000000000000000000000000000
Plaintext: 00000000000000000000000000000000
Ciphertext: 34EC834E2F30741ECB476DA7E9662BBD
Test: EncryptionMCT
Key: 000000000000000000000000000000000000000000000000
Plaintext: 7F27C3397A8CEEF1BDF859459690FEA8
Ciphertext: 00000000000000000000000000000000
Test: DecryptionMCT
Key: 0000000000000000000000000000000000000000000000000000000000000000
Plaintext: 00000000000000000000000000000000
Ciphertext: EDE145C10E279501D921C5E3B04420A6
Test: EncryptionMCT
Key: 0000000000000000000000000000000000000000000000000000000000000000
Plaintext: 95615ADB0DDF6613A5E84F849AC8C00D
Ciphertext: 00000000000000000000000000000000
Test: DecryptionMCT
4 changes: 4 additions & 0 deletions cryptdll.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
EnableEnhancedInstructionSet="1"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="pch.h"
ProgramDataBaseFileName="$(OutDir)\vc80.pdb"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="3"
Expand Down Expand Up @@ -167,6 +168,7 @@
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="pch.h"
ProgramDataBaseFileName="$(OutDir)\vc80.pdb"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="3"
Expand Down Expand Up @@ -263,6 +265,7 @@
EnableEnhancedInstructionSet="1"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="pch.h"
ProgramDataBaseFileName="$(OutDir)\vc80.pdb"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="3"
Expand Down Expand Up @@ -357,6 +360,7 @@
RuntimeLibrary="1"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="pch.h"
ProgramDataBaseFileName="$(OutDir)\vc80.pdb"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="3"
Expand Down
4 changes: 4 additions & 0 deletions cryptest.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,10 @@
RelativePath=".\TestVectors\hmac.txt"
>
</File>
<File
RelativePath=".\TestVectors\mars.txt"
>
</File>
<File
RelativePath=".\TestVectors\nr.txt"
>
Expand Down
8 changes: 8 additions & 0 deletions cryptlib.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="pch.h"
ProgramDataBaseFileName="$(OutDir)\vc80.pdb"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="3"
Expand Down Expand Up @@ -127,6 +128,7 @@
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="pch.h"
ProgramDataBaseFileName="$(OutDir)\vc80.pdb"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="3"
Expand Down Expand Up @@ -199,6 +201,7 @@
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="pch.h"
ProgramDataBaseFileName="$(OutDir)\vc80.pdb"
WarningLevel="3"
SuppressStartupBanner="true"
Detect64BitPortabilityProblems="true"
Expand Down Expand Up @@ -273,6 +276,7 @@
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="pch.h"
ProgramDataBaseFileName="$(OutDir)\vc80.pdb"
WarningLevel="3"
SuppressStartupBanner="true"
Detect64BitPortabilityProblems="true"
Expand Down Expand Up @@ -341,6 +345,7 @@
EnableEnhancedInstructionSet="1"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="pch.h"
ProgramDataBaseFileName="$(OutDir)\vc80.pdb"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
Expand Down Expand Up @@ -408,6 +413,7 @@
RuntimeLibrary="1"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="pch.h"
ProgramDataBaseFileName="$(OutDir)\vc80.pdb"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="3"
Expand Down Expand Up @@ -474,6 +480,7 @@
RuntimeLibrary="1"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="pch.h"
ProgramDataBaseFileName="$(OutDir)\vc80.pdb"
WarningLevel="3"
SuppressStartupBanner="true"
Detect64BitPortabilityProblems="true"
Expand Down Expand Up @@ -542,6 +549,7 @@
RuntimeLibrary="1"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="pch.h"
ProgramDataBaseFileName="$(OutDir)\vc80.pdb"
WarningLevel="3"
SuppressStartupBanner="true"
Detect64BitPortabilityProblems="true"
Expand Down
41 changes: 40 additions & 1 deletion datatest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void TestSymmetricCipher(TestData &v, const NameValuePairs &overrideParameters)
TestDataNameValuePairs testDataPairs(v);
CombinedNameValuePairs pairs(overrideParameters, testDataPairs);

if (test == "Encrypt" || test == "EncryptXorDigest" || test == "Resync")
if (test == "Encrypt" || test == "EncryptXorDigest" || test == "Resync" || test == "EncryptionMCT" || test == "DecryptionMCT")
{
static member_ptr<SymmetricCipher> encryptor, decryptor;
static std::string lastName;
Expand Down Expand Up @@ -339,7 +339,46 @@ void TestSymmetricCipher(TestData &v, const NameValuePairs &overrideParameters)
encryptor->Seek(seek);
decryptor->Seek(seek);
}

std::string encrypted, xorDigest, ciphertext, ciphertextXorDigest;
if (test == "EncryptionMCT" || test == "DecryptionMCT")
{
SymmetricCipher *cipher = encryptor.get();
SecByteBlock buf((byte *)plaintext.data(), plaintext.size()), keybuf((byte *)key.data(), key.size());

if (test == "DecryptionMCT")
{
cipher = decryptor.get();
ciphertext = GetDecodedDatum(v, "Ciphertext");
buf.Assign((byte *)ciphertext.data(), ciphertext.size());
}

for (int i=0; i<400; i++)
{
encrypted.reserve(10000 * plaintext.size());
for (int j=0; j<10000; j++)
{
cipher->ProcessString(buf.begin(), buf.size());
encrypted.append((char *)buf.begin(), buf.size());
}

encrypted.erase(0, encrypted.size() - keybuf.size());
xorbuf(keybuf.begin(), (const byte *)encrypted.data(), keybuf.size());
cipher->SetKey(keybuf, keybuf.size());
}
encrypted.assign((char *)buf.begin(), buf.size());
ciphertext = GetDecodedDatum(v, test == "EncryptionMCT" ? "Ciphertext" : "Plaintext");
if (encrypted != ciphertext)
{
std::cout << "incorrectly encrypted: ";
StringSource xx(encrypted, false, new HexEncoder(new FileSink(std::cout)));
xx.Pump(256); xx.Flush(false);
std::cout << "\n";
SignalTestFailure();
}
return;
}

StringSource ss(plaintext, false, new StreamTransformationFilter(*encryptor, new StringSink(encrypted), StreamTransformationFilter::NO_PADDING));
ss.Pump(plaintext.size()/2 + 1);
ss.PumpAll();
Expand Down
6 changes: 5 additions & 1 deletion ec2n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ EC2N::EC2N(BufferedTransformation &bt)
m_field->BERDecodeElement(seq, m_b);
// skip optional seed
if (!seq.EndReached())
BERDecodeOctetString(seq, TheBitBucket());
{
SecByteBlock seed;
unsigned int unused;
BERDecodeBitString(seq, seed, unused);
}
seq.MessageEnd();
}

Expand Down
Loading

0 comments on commit 3be02e9

Please sign in to comment.