summaryrefslogtreecommitdiff
path: root/extra/yassl/taocrypt/test/test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'extra/yassl/taocrypt/test/test.cpp')
-rw-r--r--extra/yassl/taocrypt/test/test.cpp158
1 files changed, 143 insertions, 15 deletions
diff --git a/extra/yassl/taocrypt/test/test.cpp b/extra/yassl/taocrypt/test/test.cpp
index f8177b31e2f..4cd5dba8ac6 100644
--- a/extra/yassl/taocrypt/test/test.cpp
+++ b/extra/yassl/taocrypt/test/test.cpp
@@ -41,6 +41,8 @@
#include "coding.hpp"
#include "random.hpp"
#include "pwdbased.hpp"
+#include "rabbit.hpp"
+#include "hc128.hpp"
@@ -100,16 +102,18 @@ using TaoCrypt::PBKDF2_HMAC;
using TaoCrypt::tcArrayDelete;
using TaoCrypt::GetCert;
using TaoCrypt::GetPKCS_Cert;
-
+using TaoCrypt::Rabbit;
+using TaoCrypt::HC128;
struct testVector {
byte* input_;
byte* output_;
- size_t inLen_;
- size_t outLen_;
+ word32 inLen_;
+ word32 outLen_;
testVector(const char* in, const char* out) : input_((byte*)in),
- output_((byte*)out), inLen_(strlen(in)), outLen_(strlen(out)) {}
+ output_((byte*)out), inLen_((word32)strlen(in)),
+ outLen_((word32)strlen(out)) {}
};
int sha_test();
@@ -134,13 +138,15 @@ int dsa_test();
int dh_test();
int pwdbased_test();
int pkcs12_test();
+int rabbit_test();
+int hc128_test();
TaoCrypt::RandomNumberGenerator rng;
void err_sys(const char* msg, int es)
{
- printf("%s", msg);
+ printf("%s\n", msg);
exit(es);
}
@@ -176,7 +182,7 @@ byte* cipher = 0; // block output
void taocrypt_test(void* args)
{
((func_args*)args)->return_code = -1; // error state
-
+
msg = NEW_TC byte[24];
plain = NEW_TC byte[24];
cipher = NEW_TC byte[24];
@@ -243,6 +249,16 @@ void taocrypt_test(void* args)
else
printf( "ARC4 test passed!\n");
+ if ( (ret = rabbit_test()) )
+ err_sys("Rabbit test failed!\n", ret);
+ else
+ printf( "Rabbit test passed!\n");
+
+ if ( (ret = hc128_test()) )
+ err_sys("HC128 test failed!\n", ret);
+ else
+ printf( "HC128 test passed!\n");
+
if ( (ret = des_test()) )
err_sys("DES test failed!\n", ret);
else
@@ -320,16 +336,16 @@ void taocrypt_test(void* args)
void file_test(const char* file, byte* check)
{
FILE* f;
- int i(0);
- MD5 md5;
- byte buf[1024];
- byte md5sum[MD5::DIGEST_SIZE];
+ int i = 0;
+ MD5 md5;
+ byte buf[1024];
+ byte md5sum[MD5::DIGEST_SIZE];
if( !( f = fopen( file, "rb" ) )) {
printf("Can't open %s\n", file);
return;
}
- while( ( i = fread(buf, 1, sizeof(buf), f )) > 0 )
+ while( ( i = (int)fread(buf, 1, sizeof(buf), f )) > 0 )
md5.Update(buf, i);
md5.Final(md5sum);
@@ -718,7 +734,7 @@ int hmac_test()
int times( sizeof(test_hmacMD5) / sizeof(testVector) );
for (int i = 0; i < times; ++i) {
- hmacMD5.SetKey((byte*)keys[i], strlen(keys[i]));
+ hmacMD5.SetKey((byte*)keys[i], (word32)strlen(keys[i]));
hmacMD5.Update(test_hmacMD5[i].input_, test_hmacMD5[i].inLen_);
hmacMD5.Final(hash);
@@ -761,8 +777,8 @@ int arc4_test()
ARC4::Encryption enc;
ARC4::Decryption dec;
- enc.SetKey((byte*)keys[i], strlen(keys[i]));
- dec.SetKey((byte*)keys[i], strlen(keys[i]));
+ enc.SetKey((byte*)keys[i], (word32)strlen(keys[i]));
+ dec.SetKey((byte*)keys[i], (word32)strlen(keys[i]));
enc.Process(cipher, test_arc4[i].input_, test_arc4[i].outLen_);
dec.Process(plain, cipher, test_arc4[i].outLen_);
@@ -778,6 +794,114 @@ int arc4_test()
}
+int rabbit_test()
+{
+ byte cipher[16];
+ byte plain[16];
+
+ const char* keys[] =
+ {
+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+ "\xAC\xC3\x51\xDC\xF1\x62\xFC\x3B\xFE\x36\x3D\x2E\x29\x13\x28\x91"
+ };
+
+ const char* ivs[] =
+ {
+ "\x00\x00\x00\x00\x00\x00\x00\x00",
+ "\x59\x7E\x26\xC1\x75\xF5\x73\xC3",
+ 0
+ };
+
+
+ testVector test_rabbit[] =
+ {
+ testVector("\x00\x00\x00\x00\x00\x00\x00\x00",
+ "\xED\xB7\x05\x67\x37\x5D\xCD\x7C"),
+ testVector("\x00\x00\x00\x00\x00\x00\x00\x00",
+ "\x6D\x7D\x01\x22\x92\xCC\xDC\xE0"),
+ testVector("\x00\x00\x00\x00\x00\x00\x00\x00",
+ "\x9C\x51\xE2\x87\x84\xC3\x7F\xE9")
+ };
+
+
+ int times( sizeof(test_rabbit) / sizeof(testVector) );
+ for (int i = 0; i < times; ++i) {
+ Rabbit::Encryption enc;
+ Rabbit::Decryption dec;
+
+ enc.SetKey((byte*)keys[i], (byte*)ivs[i]);
+ dec.SetKey((byte*)keys[i], (byte*)ivs[i]);
+
+ enc.Process(cipher, test_rabbit[i].input_, test_rabbit[i].outLen_);
+ dec.Process(plain, cipher, test_rabbit[i].outLen_);
+
+ if (memcmp(plain, test_rabbit[i].input_, test_rabbit[i].outLen_))
+ return -230 - i;
+
+ if (memcmp(cipher, test_rabbit[i].output_, test_rabbit[i].outLen_))
+ return -240 - i;
+ }
+
+ return 0;
+}
+
+
+int hc128_test()
+{
+ byte cipher[16];
+ byte plain[16];
+
+ const char* keys[] =
+ {
+ "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+ "\x00\x53\xA6\xF9\x4C\x9F\xF2\x45\x98\xEB\x3E\x91\xE4\x37\x8A\xDD",
+ "\x0F\x62\xB5\x08\x5B\xAE\x01\x54\xA7\xFA\x4D\xA0\xF3\x46\x99\xEC"
+ };
+
+ const char* ivs[] =
+ {
+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+ "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+ "\x0D\x74\xDB\x42\xA9\x10\x77\xDE\x45\xAC\x13\x7A\xE1\x48\xAF\x16",
+ "\x28\x8F\xF6\x5D\xC4\x2B\x92\xF9\x60\xC7\x2E\x95\xFC\x63\xCA\x31"
+ };
+
+ testVector test_hc128[] =
+ {
+ testVector("\x00\x00\x00\x00\x00\x00\x00\x00",
+ "\x37\x86\x02\xB9\x8F\x32\xA7\x48"),
+ testVector("\x00\x00\x00\x00\x00\x00\x00\x00",
+ "\x33\x7F\x86\x11\xC6\xED\x61\x5F"),
+ testVector("\x00\x00\x00\x00\x00\x00\x00\x00",
+ "\x2E\x1E\xD1\x2A\x85\x51\xC0\x5A"),
+ testVector("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+ "\x1C\xD8\xAE\xDD\xFE\x52\xE2\x17\xE8\x35\xD0\xB7\xE8\x4E\x29")
+ };
+
+ int times( sizeof(test_hc128) / sizeof(testVector) );
+ for (int i = 0; i < times; ++i) {
+ HC128::Encryption enc;
+ HC128::Decryption dec;
+
+ enc.SetKey((byte*)keys[i], (byte*)ivs[i]);
+ dec.SetKey((byte*)keys[i], (byte*)ivs[i]);
+
+ enc.Process(cipher, test_hc128[i].input_, test_hc128[i].outLen_);
+ dec.Process(plain, cipher, test_hc128[i].outLen_);
+
+ if (memcmp(plain, test_hc128[i].input_, test_hc128[i].outLen_))
+ return -330 - i;
+
+ if (memcmp(cipher, test_hc128[i].output_, test_hc128[i].outLen_))
+ return -340 - i;
+ }
+
+ return 0;
+}
+
+
int des_test()
{
//ECB mode
@@ -1040,7 +1164,7 @@ int rsa_test()
RSAES_Encryptor enc(priv);
byte message[] = "Everyone gets Friday off.";
- const int len(strlen((char*)message));
+ const word32 len = (word32)strlen((char*)message);
byte cipher[64];
enc.Encrypt(message, len, cipher, rng);
@@ -1068,6 +1192,8 @@ int rsa_test()
}
}
CertDecoder cd(source2, true, 0, false, CertDecoder::CA);
+ if (cd.GetError().What())
+ err_sys("cert error", -80);
Source source3(cd.GetPublicKey().GetKey(), cd.GetPublicKey().size());
RSA_PublicKey pub(source3);
@@ -1188,6 +1314,7 @@ int pwdbased_test()
}
+/*
int pkcs12_test()
{
Source cert;
@@ -1220,4 +1347,5 @@ int pkcs12_test()
return 0;
}
+*/