summaryrefslogtreecommitdiff
path: root/validat4.cpp
diff options
context:
space:
mode:
authorRăzvan Cojocaru <36885180+rzvncj@users.noreply.github.com>2019-09-30 03:18:56 +0300
committerJeffrey Walton <noloader@gmail.com>2019-09-29 20:18:56 -0400
commit9912d0630e4aea48b9cdd7c5dd2ca4a5d856e7b1 (patch)
tree3cbf07995f7a678c89393e8b9f39ee736b0eaec0 /validat4.cpp
parent7a927b4d8270c017d533a29f1e21be8c6d595ba9 (diff)
downloadcryptopp-git-9912d0630e4aea48b9cdd7c5dd2ca4a5d856e7b1.tar.gz
Add support for Mcrypt's blowfish-compat (PR #877)
Diffstat (limited to 'validat4.cpp')
-rw-r--r--validat4.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/validat4.cpp b/validat4.cpp
index 59a8c35d..143122da 100644
--- a/validat4.cpp
+++ b/validat4.cpp
@@ -1126,6 +1126,69 @@ bool ValidateBlowfish()
return pass1 && pass2 && pass3;
}
+bool ValidateBlowfishCompat()
+{
+ std::cout << "\nBlowfishCompat validation suite running...\n\n";
+ bool pass1 = true, pass2 = true, pass3 = true, fail;
+
+ BlowfishCompatEncryption enc1; // 32 to 448-bits (4 to 56-bytes)
+ pass1 = enc1.StaticGetValidKeyLength(3) == 4 && pass1;
+ pass1 = enc1.StaticGetValidKeyLength(4) == 4 && pass1;
+ pass1 = enc1.StaticGetValidKeyLength(5) == 5 && pass1;
+ pass1 = enc1.StaticGetValidKeyLength(8) == 8 && pass1;
+ pass1 = enc1.StaticGetValidKeyLength(16) == 16 && pass1;
+ pass1 = enc1.StaticGetValidKeyLength(24) == 24 && pass1;
+ pass1 = enc1.StaticGetValidKeyLength(32) == 32 && pass1;
+ pass1 = enc1.StaticGetValidKeyLength(56) == 56 && pass1;
+ pass1 = enc1.StaticGetValidKeyLength(57) == 56 && pass1;
+ pass1 = enc1.StaticGetValidKeyLength(60) == 56 && pass1;
+ pass1 = enc1.StaticGetValidKeyLength(64) == 56 && pass1;
+ pass1 = enc1.StaticGetValidKeyLength(128) == 56 && pass1;
+
+ BlowfishCompatDecryption dec1; // 32 to 448-bits (4 to 56-bytes)
+ pass2 = dec1.StaticGetValidKeyLength(3) == 4 && pass2;
+ pass2 = dec1.StaticGetValidKeyLength(4) == 4 && pass2;
+ pass2 = dec1.StaticGetValidKeyLength(5) == 5 && pass2;
+ pass2 = dec1.StaticGetValidKeyLength(8) == 8 && pass2;
+ pass2 = dec1.StaticGetValidKeyLength(16) == 16 && pass2;
+ pass2 = dec1.StaticGetValidKeyLength(24) == 24 && pass2;
+ pass2 = dec1.StaticGetValidKeyLength(32) == 32 && pass2;
+ pass2 = dec1.StaticGetValidKeyLength(56) == 56 && pass2;
+ pass2 = dec1.StaticGetValidKeyLength(57) == 56 && pass2;
+ pass2 = dec1.StaticGetValidKeyLength(60) == 56 && pass2;
+ pass2 = dec1.StaticGetValidKeyLength(64) == 56 && pass2;
+ pass2 = dec1.StaticGetValidKeyLength(128) == 56 && pass2;
+ std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
+
+ HexEncoder output(new FileSink(std::cout));
+ const char *key[]={"abcdefghijklmnopqrstuvwxyz", "Who is John Galt?"};
+ byte *plain[]={(byte *)"BLOWFISH", (byte *)"\xfe\xdc\xba\x98\x76\x54\x32\x10"};
+ byte *cipher[]={(byte *)"\x82\x4d\x92\x0d\x00\x4d\x7e\xe3", (byte *)"\xd4\xf9\xb0\x06\xd3\x84\x92\x7e"};
+ byte out[8], outplain[8];
+
+ for (int i=0; i<2; i++)
+ {
+ ECB_Mode<BlowfishCompat>::Encryption enc2((byte *)key[i], strlen(key[i]));
+ enc2.ProcessData(out, plain[i], 8);
+ fail = memcmp(out, cipher[i], 8) != 0;
+
+ ECB_Mode<BlowfishCompat>::Decryption dec2((byte *)key[i], strlen(key[i]));
+ dec2.ProcessData(outplain, cipher[i], 8);
+ fail = fail || memcmp(outplain, plain[i], 8);
+ pass3 = pass3 && !fail;
+
+ std::cout << (fail ? "FAILED " : "passed ");
+ std::cout << '\"' << key[i] << '\"';
+ for (int j=0; j<(signed int)(30-strlen(key[i])); j++)
+ std::cout << ' ';
+ output.Put(outplain, 8);
+ std::cout << " ";
+ output.Put(out, 8);
+ std::cout << std::endl;
+ }
+ return pass1 && pass2 && pass3;
+}
+
bool ValidateThreeWay()
{
std::cout << "\n3-WAY validation suite running...\n\n";