added libtomcrypt-1.03

This commit is contained in:
Tom St Denis
2005-06-09 00:08:13 +00:00
committed by Steffen Jaeckel
parent 65c1317eee
commit 3964a6523a
285 changed files with 5920 additions and 2287 deletions
+5 -1
View File
@@ -12,9 +12,13 @@ int base64_test(void)
l2 = sizeof(tmp);
DO(base64_decode(out, l1, tmp, &l2));
if (l2 != x || memcmp(tmp, in, x)) {
printf("base64 failed %lu %lu %lu", x, l1, l2);
fprintf(stderr, "base64 failed %lu %lu %lu", x, l1, l2);
return 1;
}
}
return 0;
}
/* $Source$ */
/* $Revision$ */
/* $Date$ */
+4
View File
@@ -39,3 +39,7 @@ int cipher_hash_test(void)
return 0;
}
/* $Source$ */
/* $Revision$ */
/* $Date$ */
+186 -50
View File
@@ -4,7 +4,7 @@
int der_tests(void)
{
printf("NOP");
fprintf(stderr, "NOP");
return 0;
}
@@ -12,83 +12,219 @@ int der_tests(void)
int der_tests(void)
{
unsigned long x, y, z, zz;
unsigned char buf[2][4096];
unsigned long x, y, z, zz, oid[2][32];
unsigned char buf[3][2048];
mp_int a, b, c, d, e, f, g;
static const unsigned char rsa_oid_der[] = { 0x06, 0x06, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d };
static const unsigned long rsa_oid[] = { 1, 2, 840, 113549 };
static const unsigned char rsa_ia5[] = "test1@rsa.com";
static const unsigned char rsa_ia5_der[] = { 0x16, 0x0d, 0x74, 0x65, 0x73, 0x74, 0x31,
0x40, 0x72, 0x73, 0x61, 0x2e, 0x63, 0x6f, 0x6d };
static const unsigned char rsa_printable[] = "Test User 1";
static const unsigned char rsa_printable_der[] = { 0x13, 0x0b, 0x54, 0x65, 0x73, 0x74, 0x20, 0x55,
0x73, 0x65, 0x72, 0x20, 0x31 };
DO(mpi_to_ltc_error(mp_init_multi(&a, &b, &c, &d, &e, &f, &g, NULL)));
for (zz = 0; zz < 16; zz++) {
for (z = 0; z < 1024; z++) {
if (yarrow_read(buf[0], z, &yarrow_prng) != z) {
printf("Failed to read %lu bytes from yarrow\n", z);
fprintf(stderr, "Failed to read %lu bytes from yarrow\n", z);
return 1;
}
DO(mpi_to_ltc_error(mp_read_unsigned_bin(&a, buf[0], z)));
if (mp_iszero(&a) == MP_NO) { a.sign = buf[0][0] & 1 ? MP_ZPOS : MP_NEG; }
x = sizeof(buf[0]);
DO(der_encode_integer(&a, buf[0], &x));
y = x;
DO(der_length_integer(&a, &y));
if (y != x) { fprintf(stderr, "DER INTEGER size mismatch\n"); return 1; }
mp_zero(&b);
DO(der_decode_integer(buf[0], &y, &b));
DO(der_decode_integer(buf[0], y, &b));
if (y != x || mp_cmp(&a, &b) != MP_EQ) {
printf("%lu: %lu vs %lu\n", z, x, y);
fprintf(stderr, "%lu: %lu vs %lu\n", z, x, y);
#ifdef BN_MP_TORADIX_C
mp_todecimal(&a, buf[0]);
mp_todecimal(&b, buf[1]);
printf("a == %s\nb == %s\n", buf[0], buf[1]);
fprintf(stderr, "a == %s\nb == %s\n", buf[0], buf[1]);
#endif
mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
return 1;
}
}
}
/* test the multi */
mp_set(&a, 1);
x = sizeof(buf[0]);
DO(der_put_multi_integer(buf[0], &x, &a, NULL));
y = x;
mp_zero(&a);
DO(der_get_multi_integer(buf[0], &y, &a, NULL));
if (x != y || mp_cmp_d(&a, 1)) {
printf("%lu, %lu, %d\n", x, y, mp_cmp_d(&a, 1));
mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
return 1;
}
/* test short integer */
for (zz = 0; zz < 256; zz++) {
for (z = 1; z < 4; z++) {
if (yarrow_read(buf[0], z, &yarrow_prng) != z) {
fprintf(stderr, "Failed to read %lu bytes from yarrow\n", z);
return 1;
}
/* encode with normal */
DO(mpi_to_ltc_error(mp_read_unsigned_bin(&a, buf[0], z)));
mp_set(&a, 1);
mp_set(&b, 2);
x = sizeof(buf[0]);
DO(der_put_multi_integer(buf[0], &x, &a, &b, NULL));
y = x;
mp_zero(&a);
mp_zero(&b);
DO(der_get_multi_integer(buf[0], &y, &a, &b, NULL));
if (x != y || mp_cmp_d(&a, 1) || mp_cmp_d(&b, 2)) {
printf("%lu, %lu, %d, %d\n", x, y, mp_cmp_d(&a, 1), mp_cmp_d(&b, 2));
mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
return 1;
}
mp_set(&a, 1);
mp_set(&b, 2);
mp_set(&c, 3);
x = sizeof(buf[0]);
DO(der_put_multi_integer(buf[0], &x, &a, &b, &c, NULL));
y = x;
mp_zero(&a);
mp_zero(&b);
mp_zero(&c);
DO(der_get_multi_integer(buf[0], &y, &a, &b, &c, NULL));
if (x != y || mp_cmp_d(&a, 1) || mp_cmp_d(&b, 2) || mp_cmp_d(&c, 3)) {
printf("%lu, %lu, %d, %d, %d\n", x, y, mp_cmp_d(&a, 1), mp_cmp_d(&b, 2), mp_cmp_d(&c, 3));
mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
return 1;
}
x = sizeof(buf[0]);
DO(der_encode_integer(&a, buf[0], &x));
/* encode with short */
y = sizeof(buf[1]);
DO(der_encode_short_integer(mp_get_int(&a), buf[1], &y));
if (x != y || memcmp(buf[0], buf[1], x)) {
fprintf(stderr, "DER INTEGER short encoding failed, %lu, %lu\n", x, y);
for (z = 0; z < x; z++) fprintf(stderr, "%02x ", buf[0][z]); fprintf(stderr, "\n");
for (z = 0; z < y; z++) fprintf(stderr, "%02x ", buf[1][z]); fprintf(stderr, "\n");
mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
return 1;
}
/* decode it */
x = 0;
DO(der_decode_short_integer(buf[1], y, &x));
if (x != mp_get_int(&a)) {
fprintf(stderr, "DER INTEGER short decoding failed, %lu, %lu\n", x, mp_get_int(&a));
mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
return 1;
}
}
}
mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
/* Test bit string */
for (zz = 1; zz < 1536; zz++) {
yarrow_read(buf[0], zz, &yarrow_prng);
for (z = 0; z < zz; z++) {
buf[0][z] &= 0x01;
}
x = sizeof(buf[1]);
DO(der_encode_bit_string(buf[0], zz, buf[1], &x));
DO(der_length_bit_string(zz, &y));
if (y != x) {
fprintf(stderr, "\nDER BIT STRING length of encoded not match expected : %lu, %lu, %lu\n", z, x, y);
return 1;
}
y = sizeof(buf[2]);
DO(der_decode_bit_string(buf[1], x, buf[2], &y));
if (y != zz || memcmp(buf[0], buf[2], zz)) {
fprintf(stderr, "%lu, %lu, %d\n", y, zz, memcmp(buf[0], buf[2], zz));
return 1;
}
}
/* Test octet string */
for (zz = 1; zz < 1536; zz++) {
yarrow_read(buf[0], zz, &yarrow_prng);
x = sizeof(buf[1]);
DO(der_encode_octet_string(buf[0], zz, buf[1], &x));
DO(der_length_octet_string(zz, &y));
if (y != x) {
fprintf(stderr, "\nDER OCTET STRING length of encoded not match expected : %lu, %lu, %lu\n", z, x, y);
return 1;
}
y = sizeof(buf[2]);
DO(der_decode_octet_string(buf[1], x, buf[2], &y));
if (y != zz || memcmp(buf[0], buf[2], zz)) {
fprintf(stderr, "%lu, %lu, %d\n", y, zz, memcmp(buf[0], buf[2], zz));
return 1;
}
}
/* test OID */
x = sizeof(buf[0]);
DO(der_encode_object_identifier(rsa_oid, sizeof(rsa_oid)/sizeof(rsa_oid[0]), buf[0], &x));
if (x != sizeof(rsa_oid_der) || memcmp(rsa_oid_der, buf[0], x)) {
fprintf(stderr, "rsa_oid_der encode failed to match, %lu, ", x);
for (y = 0; y < x; y++) fprintf(stderr, "%02x ", buf[0][y]);
fprintf(stderr, "\n");
return 1;
}
y = sizeof(oid[0])/sizeof(oid[0][0]);
DO(der_decode_object_identifier(buf[0], x, oid[0], &y));
if (y != sizeof(rsa_oid)/sizeof(rsa_oid[0]) || memcmp(rsa_oid, oid[0], sizeof(rsa_oid))) {
fprintf(stderr, "rsa_oid_der decode failed to match, %lu, ", y);
for (z = 0; z < y; z++) fprintf(stderr, "%lu ", oid[0][z]);
fprintf(stderr, "\n");
return 1;
}
/* do random strings */
for (zz = 0; zz < 5000; zz++) {
/* pick a random number of words */
yarrow_read(buf[0], 4, &yarrow_prng);
LOAD32L(z, buf[0]);
z = 2 + (z % ((sizeof(oid[0])/sizeof(oid[0][0])) - 2));
/* fill them in */
oid[0][0] = buf[0][0] % 3;
oid[0][1] = buf[0][1] % 40;
for (y = 2; y < z; y++) {
yarrow_read(buf[0], 4, &yarrow_prng);
LOAD32L(oid[0][y], buf[0]);
}
/* encode it */
x = sizeof(buf[0]);
DO(der_encode_object_identifier(oid[0], z, buf[0], &x));
DO(der_length_object_identifier(oid[0], z, &y));
if (x != y) {
fprintf(stderr, "Random OID %lu test failed, length mismatch: %lu, %lu\n", z, x, y);
for (x = 0; x < z; x++) fprintf(stderr, "%lu\n", oid[0][x]);
return 1;
}
/* decode it */
y = sizeof(oid[0])/sizeof(oid[0][0]);
DO(der_decode_object_identifier(buf[0], x, oid[1], &y));
if (y != z) {
fprintf(stderr, "Random OID %lu test failed, decode length mismatch: %lu, %lu\n", z, x, y);
return 1;
}
if (memcmp(oid[0], oid[1], sizeof(oid[0][0]) * z)) {
fprintf(stderr, "Random OID %lu test failed, decoded values wrong\n", z);
for (x = 0; x < z; x++) fprintf(stderr, "%lu\n", oid[0][x]); fprintf(stderr, "\n\n Got \n\n");
for (x = 0; x < z; x++) fprintf(stderr, "%lu\n", oid[1][x]);
return 1;
}
}
/* IA5 string */
x = sizeof(buf[0]);
DO(der_encode_ia5_string(rsa_ia5, strlen(rsa_ia5), buf[0], &x));
if (x != sizeof(rsa_ia5_der) || memcmp(buf[0], rsa_ia5_der, x)) {
fprintf(stderr, "IA5 encode failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_ia5_der));
return 1;
}
y = sizeof(buf[1]);
DO(der_decode_ia5_string(buf[0], x, buf[1], &y));
if (y != strlen(rsa_ia5) || memcmp(buf[1], rsa_ia5, strlen(rsa_ia5))) {
fprintf(stderr, "DER IA5 failed test vector\n");
return 1;
}
/* Printable string */
x = sizeof(buf[0]);
DO(der_encode_printable_string(rsa_printable, strlen(rsa_printable), buf[0], &x));
if (x != sizeof(rsa_printable_der) || memcmp(buf[0], rsa_printable_der, x)) {
fprintf(stderr, "PRINTABLE encode failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_printable_der));
return 1;
}
y = sizeof(buf[1]);
DO(der_decode_printable_string(buf[0], x, buf[1], &y));
if (y != strlen(rsa_printable) || memcmp(buf[1], rsa_printable, strlen(rsa_printable))) {
fprintf(stderr, "DER printable failed test vector\n");
return 1;
}
return 0;
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
+12 -8
View File
@@ -22,11 +22,11 @@ int dh_tests (void)
y = 4096;
DO(dh_shared_secret (&userb, &usera, buf[1], &y));
if (y != x) {
printf ("DH Shared keys are not same size.\n");
fprintf(stderr, "DH Shared keys are not same size.\n");
return 1;
}
if (memcmp (buf[0], buf[1], x)) {
printf ("DH Shared keys not same contents.\n");
fprintf(stderr, "DH Shared keys not same contents.\n");
return 1;
}
@@ -41,11 +41,11 @@ int dh_tests (void)
DO(dh_shared_secret (&usera, &userb, buf[2], &z));
if (z != x) {
printf ("failed. Size don't match?\n");
fprintf(stderr, "failed. Size don't match?\n");
return 1;
}
if (memcmp (buf[0], buf[2], x)) {
printf ("Failed. Content didn't match.\n");
fprintf(stderr, "Failed. Content didn't match.\n");
return 1;
}
dh_free (&usera);
@@ -62,12 +62,12 @@ int dh_tests (void)
x = sizeof (buf[0]);
DO(dh_decrypt_key (buf[1], y, buf[0], &x, &usera));
if (x != 16) {
printf ("Failed (length)\n");
fprintf(stderr, "Failed (length)\n");
return 1;
}
for (x = 0; x < 16; x++)
if (buf[0][x] != x) {
printf ("Failed (contents)\n");
fprintf(stderr, "Failed (contents)\n");
return 1;
}
@@ -81,7 +81,7 @@ int dh_tests (void)
buf[0][0] ^= 1;
DO(dh_verify_hash (buf[1], x, buf[0], 16, &stat2, &usera));
if (!(stat == 1 && stat2 == 0)) {
printf("dh_sign/verify_hash %d %d", stat, stat2);
fprintf(stderr, "dh_sign/verify_hash %d %d", stat, stat2);
return 1;
}
dh_free (&usera);
@@ -92,8 +92,12 @@ int dh_tests (void)
int dh_tests(void)
{
printf("NOP");
fprintf(stderr, "NOP");
return 0;
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
+10 -5
View File
@@ -14,7 +14,7 @@ int dsa_test(void)
/* verify it */
DO(dsa_verify_key(&key, &stat1));
if (stat1 == 0) { printf("dsa_verify_key "); return 1; }
if (stat1 == 0) { fprintf(stderr, "dsa_verify_key "); return 1; }
/* sign the message */
x = sizeof(out);
@@ -27,7 +27,7 @@ int dsa_test(void)
msg[0] ^= 1;
DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat2, &key));
msg[0] ^= 1;
if (!(stat1 == 1 && stat2 == 0)) { printf("dsa_verify %d %d", stat1, stat2); return 1; }
if (!(stat1 == 1 && stat2 == 0)) { fprintf(stderr, "dsa_verify %d %d", stat1, stat2); return 1; }
/* test exporting it */
x = sizeof(out2);
@@ -36,16 +36,17 @@ int dsa_test(void)
/* verify a signature with it */
DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2));
if (stat1 == 0) { printf("dsa_verify (import private) %d ", stat1); return 1; }
if (stat1 == 0) { fprintf(stderr, "dsa_verify (import private) %d ", stat1); return 1; }
dsa_free(&key2);
/* export as public now */
x = sizeof(out2);
DO(dsa_export(out2, &x, PK_PUBLIC, &key));
DO(dsa_import(out2, x, &key2));
/* verify a signature with it */
DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2));
if (stat1 == 0) { printf("dsa_verify (import public) %d ", stat1); return 1; }
if (stat1 == 0) { fprintf(stderr, "dsa_verify (import public) %d ", stat1); return 1; }
dsa_free(&key2);
dsa_free(&key);
@@ -56,8 +57,12 @@ int dsa_test(void)
int dsa_test(void)
{
printf("NOP");
fprintf(stderr, "NOP");
return 0;
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
+110 -85
View File
@@ -2,102 +2,123 @@
#ifdef MECC
static int sizes[] = {
#ifdef ECC192
24,
#endif
#ifdef ECC224
28,
#endif
#ifdef ECC256
32,
#endif
#ifdef ECC384
48,
#endif
#ifdef ECC512
65
#endif
};
int ecc_tests (void)
{
unsigned char buf[4][4096];
unsigned long x, y, z;
unsigned long x, y, z, s;
int stat, stat2;
ecc_key usera, userb, pubKey, privKey;
DO(ecc_test ());
/* make up two keys */
DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), 65, &usera));
DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), 65, &userb));
for (s = 0; s < (int)(sizeof(sizes)/sizeof(sizes[0])); s++) {
/* make up two keys */
DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), sizes[s], &usera));
DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), sizes[s], &userb));
/* make the shared secret */
x = 4096;
DO(ecc_shared_secret (&usera, &userb, buf[0], &x));
/* make the shared secret */
x = 4096;
DO(ecc_shared_secret (&usera, &userb, buf[0], &x));
y = 4096;
DO(ecc_shared_secret (&userb, &usera, buf[1], &y));
y = 4096;
DO(ecc_shared_secret (&userb, &usera, buf[1], &y));
if (y != x) {
printf ("ecc Shared keys are not same size.");
return 1;
if (y != x) {
fprintf(stderr, "ecc Shared keys are not same size.");
return 1;
}
if (memcmp (buf[0], buf[1], x)) {
fprintf(stderr, "ecc Shared keys not same contents.");
return 1;
}
/* now export userb */
y = 4096;
DO(ecc_export (buf[1], &y, PK_PUBLIC, &userb));
ecc_free (&userb);
/* import and make the shared secret again */
DO(ecc_import (buf[1], y, &userb));
z = 4096;
DO(ecc_shared_secret (&usera, &userb, buf[2], &z));
if (z != x) {
fprintf(stderr, "failed. Size don't match?");
return 1;
}
if (memcmp (buf[0], buf[2], x)) {
fprintf(stderr, "Failed. Content didn't match.");
return 1;
}
ecc_free (&usera);
ecc_free (&userb);
/* test encrypt_key */
DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), sizes[s], &usera));
/* export key */
x = sizeof(buf[0]);
DO(ecc_export(buf[0], &x, PK_PUBLIC, &usera));
DO(ecc_import(buf[0], x, &pubKey));
x = sizeof(buf[0]);
DO(ecc_export(buf[0], &x, PK_PRIVATE, &usera));
DO(ecc_import(buf[0], x, &privKey));
for (x = 0; x < 32; x++) {
buf[0][x] = x;
}
y = sizeof (buf[1]);
DO(ecc_encrypt_key (buf[0], 32, buf[1], &y, &yarrow_prng, find_prng ("yarrow"), find_hash ("sha256"), &pubKey));
zeromem (buf[0], sizeof (buf[0]));
x = sizeof (buf[0]);
DO(ecc_decrypt_key (buf[1], y, buf[0], &x, &privKey));
if (x != 32) {
fprintf(stderr, "Failed (length)");
return 1;
}
for (x = 0; x < 32; x++) {
if (buf[0][x] != x) {
fprintf(stderr, "Failed (contents)");
return 1;
}
}
/* test sign_hash */
for (x = 0; x < 16; x++) {
buf[0][x] = x;
}
x = sizeof (buf[1]);
DO(ecc_sign_hash (buf[0], 16, buf[1], &x, &yarrow_prng, find_prng ("yarrow"), &privKey));
DO(ecc_verify_hash (buf[1], x, buf[0], 16, &stat, &pubKey));
buf[0][0] ^= 1;
DO(ecc_verify_hash (buf[1], x, buf[0], 16, &stat2, &privKey));
if (!(stat == 1 && stat2 == 0)) {
fprintf(stderr, "ecc_verify_hash failed %d, %d, ", stat, stat2);
return 1;
}
ecc_free (&usera);
ecc_free (&pubKey);
ecc_free (&privKey);
}
if (memcmp (buf[0], buf[1], x)) {
printf ("ecc Shared keys not same contents.");
return 1;
}
/* now export userb */
y = 4096;
DO(ecc_export (buf[1], &y, PK_PUBLIC, &userb));
ecc_free (&userb);
/* import and make the shared secret again */
DO(ecc_import (buf[1], y, &userb));
z = 4096;
DO(ecc_shared_secret (&usera, &userb, buf[2], &z));
if (z != x) {
printf ("failed. Size don't match?");
return 1;
}
if (memcmp (buf[0], buf[2], x)) {
printf ("Failed. Content didn't match.");
return 1;
}
ecc_free (&usera);
ecc_free (&userb);
/* test encrypt_key */
DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), 65, &usera));
/* export key */
x = sizeof(buf[0]);
DO(ecc_export(buf[0], &x, PK_PUBLIC, &usera));
DO(ecc_import(buf[0], x, &pubKey));
x = sizeof(buf[0]);
DO(ecc_export(buf[0], &x, PK_PRIVATE, &usera));
DO(ecc_import(buf[0], x, &privKey));
for (x = 0; x < 32; x++) {
buf[0][x] = x;
}
y = sizeof (buf[1]);
DO(ecc_encrypt_key (buf[0], 32, buf[1], &y, &yarrow_prng, find_prng ("yarrow"), find_hash ("sha256"), &pubKey));
zeromem (buf[0], sizeof (buf[0]));
x = sizeof (buf[0]);
DO(ecc_decrypt_key (buf[1], y, buf[0], &x, &privKey));
if (x != 32) {
printf ("Failed (length)");
return 1;
}
for (x = 0; x < 32; x++)
if (buf[0][x] != x) {
printf ("Failed (contents)");
return 1;
}
/* test sign_hash */
for (x = 0; x < 16; x++) {
buf[0][x] = x;
}
x = sizeof (buf[1]);
DO(ecc_sign_hash (buf[0], 16, buf[1], &x, &yarrow_prng, find_prng ("yarrow"), &privKey));
DO(ecc_verify_hash (buf[1], x, buf[0], 16, &stat, &pubKey));
buf[0][0] ^= 1;
DO(ecc_verify_hash (buf[1], x, buf[0], 16, &stat2, &privKey));
if (!(stat == 1 && stat2 == 0)) {
printf("ecc_verify_hash failed %d, %d, ", stat, stat2);
return 1;
}
ecc_free (&usera);
ecc_free (&pubKey);
ecc_free (&privKey);
return 0;
}
@@ -105,8 +126,12 @@ int ecc_tests (void)
int ecc_tests(void)
{
printf("NOP");
fprintf(stderr, "NOP");
return 0;
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
+4
View File
@@ -29,3 +29,7 @@ int mac_test(void)
#endif
return 0;
}
/* $Source$ */
/* $Revision$ */
/* $Date$ */
+1 -1
View File
@@ -1,4 +1,4 @@
CFLAGS += -I../src/headers -I./ -O3 -xP -ip
CFLAGS += -I../src/headers -I./
CC=icc
OBJECTS = base64_test.o cipher_hash_test.o der_tests.o dh_tests.o \
+14 -10
View File
@@ -19,7 +19,7 @@ int modes_test(void)
/* get idx of AES handy */
cipher_idx = find_cipher("aes");
if (cipher_idx == -1) {
printf("test requires AES");
fprintf(stderr, "test requires AES");
return 1;
}
@@ -30,7 +30,7 @@ int modes_test(void)
l = sizeof(iv2);
DO(cbc_getiv(iv2, &l, &cbc));
if (l != 16 || memcmp(iv2, iv, 16)) {
printf("cbc_getiv failed");
fprintf(stderr, "cbc_getiv failed");
return 1;
}
DO(cbc_encrypt(pt, ct, 64, &cbc));
@@ -40,7 +40,7 @@ int modes_test(void)
zeromem(tmp, sizeof(tmp));
DO(cbc_decrypt(ct, tmp, 64, &cbc));
if (memcmp(tmp, pt, 64) != 0) {
printf("CBC failed");
fprintf(stderr, "CBC failed");
return 1;
}
#endif
@@ -53,7 +53,7 @@ int modes_test(void)
DO(cfb_getiv(iv2, &l, &cfb));
/* note we don't memcmp iv2/iv since cfb_start processes the IV for the first block */
if (l != 16) {
printf("cfb_getiv failed");
fprintf(stderr, "cfb_getiv failed");
return 1;
}
DO(cfb_encrypt(pt, ct, 64, &cfb));
@@ -63,7 +63,7 @@ int modes_test(void)
zeromem(tmp, sizeof(tmp));
DO(cfb_decrypt(ct, tmp, 64, &cfb));
if (memcmp(tmp, pt, 64) != 0) {
printf("CFB failed");
fprintf(stderr, "CFB failed");
return 1;
}
#endif
@@ -75,7 +75,7 @@ int modes_test(void)
l = sizeof(iv2);
DO(ofb_getiv(iv2, &l, &ofb));
if (l != 16 || memcmp(iv2, iv, 16)) {
printf("ofb_getiv failed");
fprintf(stderr, "ofb_getiv failed");
return 1;
}
DO(ofb_encrypt(pt, ct, 64, &ofb));
@@ -85,7 +85,7 @@ int modes_test(void)
zeromem(tmp, sizeof(tmp));
DO(ofb_decrypt(ct, tmp, 64, &ofb));
if (memcmp(tmp, pt, 64) != 0) {
printf("OFB failed");
fprintf(stderr, "OFB failed");
return 1;
}
#endif
@@ -93,11 +93,11 @@ int modes_test(void)
#ifdef CTR
/* test CTR mode */
/* encode the block */
DO(ctr_start(cipher_idx, iv, key, 16, 0, &ctr));
DO(ctr_start(cipher_idx, iv, key, 16, 0, CTR_COUNTER_LITTLE_ENDIAN, &ctr));
l = sizeof(iv2);
DO(ctr_getiv(iv2, &l, &ctr));
if (l != 16 || memcmp(iv2, iv, 16)) {
printf("ctr_getiv failed");
fprintf(stderr, "ctr_getiv failed");
return 1;
}
DO(ctr_encrypt(pt, ct, 57, &ctr));
@@ -107,10 +107,14 @@ int modes_test(void)
zeromem(tmp, sizeof(tmp));
DO(ctr_decrypt(ct, tmp, 57, &ctr));
if (memcmp(tmp, pt, 57) != 0) {
printf("CTR failed");
fprintf(stderr, "CTR failed");
return 1;
}
#endif
return 0;
}
/* $Source$ */
/* $Revision$ */
/* $Date$ */
+13 -33
View File
@@ -14,7 +14,7 @@ int pkcs_1_test(void)
prng_idx = find_prng("yarrow");
if (hash_idx == -1 || prng_idx == -1) {
printf("pkcs_1 tests require sha1/yarrow");
fprintf(stderr, "pkcs_1 tests require sha1/yarrow");
return 1;
}
@@ -29,30 +29,6 @@ int pkcs_1_test(void)
/* random modulus len (v1.5 must be multiple of 8 though arbitrary sizes seem to work) */
modlen = 800 + 8 * (abs(rand()) % 28);
/* PKCS v1.5 testing (encryption) */
l1 = sizeof(buf[1]);
DO(pkcs_1_v15_es_encode(buf[0], l3, modlen, &yarrow_prng, prng_idx, buf[1], &l1));
DO(pkcs_1_v15_es_decode(buf[1], l1, modlen, buf[2], l3, &res1));
if (res1 != 1 || memcmp(buf[0], buf[2], l3)) {
printf("pkcs v1.5 encrypt failed %d, %lu, %lu ", res1, l1, l3);
return 1;
}
/* PKCS v1.5 testing (signatures) */
l1 = sizeof(buf[1]);
DO(pkcs_1_v15_sa_encode(buf[0], l3, hash_idx, modlen, buf[1], &l1));
DO(pkcs_1_v15_sa_decode(buf[0], l3, buf[1], l1, hash_idx, modlen, &res1));
buf[0][i1 = abs(rand()) % l3] ^= 1;
DO(pkcs_1_v15_sa_decode(buf[0], l3, buf[1], l1, hash_idx, modlen, &res2));
buf[0][i1] ^= 1;
buf[1][i2 = abs(rand()) % l1] ^= 1;
DO(pkcs_1_v15_sa_decode(buf[0], l3, buf[1], l1, hash_idx, modlen, &res3));
if (!(res1 == 1 && res2 == 0 && res3 == 0)) {
printf("pkcs v1.5 sign failed %d %d %d ", res1, res2, res3);
return 1;
}
/* pick a random lparam len [0..16] */
lparamlen = abs(rand()) % 17;
@@ -71,16 +47,16 @@ int pkcs_1_test(void)
DO(pkcs_1_oaep_decode(buf[1], l1, lparam, lparamlen, modlen, hash_idx, buf[2], &l2, &res1));
if (res1 != 1 || l2 != l3 || memcmp(buf[2], buf[0], l3) != 0) {
printf("Outsize == %lu, should have been %lu, res1 = %d, lparamlen = %lu, msg contents follow.\n", l2, l3, res1, lparamlen);
printf("ORIGINAL:\n");
fprintf(stderr, "Outsize == %lu, should have been %lu, res1 = %d, lparamlen = %lu, msg contents follow.\n", l2, l3, res1, lparamlen);
fprintf(stderr, "ORIGINAL:\n");
for (x = 0; x < l3; x++) {
printf("%02x ", buf[0][x]);
fprintf(stderr, "%02x ", buf[0][x]);
}
printf("\nRESULT:\n");
fprintf(stderr, "\nRESULT:\n");
for (x = 0; x < l2; x++) {
printf("%02x ", buf[2][x]);
fprintf(stderr, "%02x ", buf[2][x]);
}
printf("\n\n");
fprintf(stderr, "\n\n");
return 1;
}
@@ -97,7 +73,7 @@ int pkcs_1_test(void)
DO(pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res3));
if (!(res1 == 1 && res2 == 0 && res3 == 0)) {
printf("PSS failed: %d, %d, %d, %lu, %lu\n", res1, res2, res3, l3, saltlen);
fprintf(stderr, "PSS failed: %d, %d, %d, %lu, %lu\n", res1, res2, res3, l3, saltlen);
return 1;
}
}
@@ -108,9 +84,13 @@ int pkcs_1_test(void)
int pkcs_1_test(void)
{
printf("NOP");
fprintf(stderr, "NOP");
return 0;
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
+145 -65
View File
@@ -4,18 +4,125 @@
#define RSA_MSGSIZE 78
/* These are test keys [see file test.key] that I use to test my import/export against */
static const unsigned char openssl_private_rsa[] = {
0x30, 0x82, 0x02, 0x5e, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xcf, 0x9a, 0xde, 0x64, 0x8a,
0xda, 0xc8, 0x33, 0x20, 0xa9, 0xd7, 0x83, 0x31, 0x19, 0x54, 0xb2, 0x9a, 0x85, 0xa7, 0xa1, 0xb7,
0x75, 0x33, 0xb6, 0xa9, 0xac, 0x84, 0x24, 0xb3, 0xde, 0xdb, 0x7d, 0x85, 0x2d, 0x96, 0x65, 0xe5,
0x3f, 0x72, 0x95, 0x24, 0x9f, 0x28, 0x68, 0xca, 0x4f, 0xdb, 0x44, 0x1c, 0x3e, 0x60, 0x12, 0x8a,
0xdd, 0x26, 0xa5, 0xeb, 0xff, 0x0b, 0x5e, 0xd4, 0x88, 0x38, 0x49, 0x2a, 0x6e, 0x5b, 0xbf, 0x12,
0x37, 0x47, 0xbd, 0x05, 0x6b, 0xbc, 0xdb, 0xf3, 0xee, 0xe4, 0x11, 0x8e, 0x41, 0x68, 0x7c, 0x61,
0x13, 0xd7, 0x42, 0xc8, 0x80, 0xbe, 0x36, 0x8f, 0xdc, 0x08, 0x8b, 0x4f, 0xac, 0xa4, 0xe2, 0x76,
0x0c, 0xc9, 0x63, 0x6c, 0x49, 0x58, 0x93, 0xed, 0xcc, 0xaa, 0xdc, 0x25, 0x3b, 0x0a, 0x60, 0x3f,
0x8b, 0x54, 0x3a, 0xc3, 0x4d, 0x31, 0xe7, 0x94, 0xa4, 0x44, 0xfd, 0x02, 0x03, 0x01, 0x00, 0x01,
0x02, 0x81, 0x81, 0x00, 0xc8, 0x62, 0xb9, 0xea, 0xde, 0x44, 0x53, 0x1d, 0x56, 0x97, 0xd9, 0x97,
0x9e, 0x1a, 0xcf, 0x30, 0x1e, 0x0a, 0x88, 0x45, 0x86, 0x29, 0x30, 0xa3, 0x4d, 0x9f, 0x61, 0x65,
0x73, 0xe0, 0xd6, 0x87, 0x8f, 0xb6, 0xf3, 0x06, 0xa3, 0x82, 0xdc, 0x7c, 0xac, 0xfe, 0x9b, 0x28,
0x9a, 0xae, 0xfd, 0xfb, 0xfe, 0x2f, 0x0e, 0xd8, 0x97, 0x04, 0xe3, 0xbb, 0x1f, 0xd1, 0xec, 0x0d,
0xba, 0xa3, 0x49, 0x7f, 0x47, 0xac, 0x8a, 0x44, 0x04, 0x7e, 0x86, 0xb7, 0x39, 0x42, 0x3f, 0xad,
0x1e, 0xb7, 0x0e, 0xa5, 0x51, 0xf4, 0x40, 0x63, 0x1e, 0xfd, 0xbd, 0xea, 0x9f, 0x41, 0x9f, 0xa8,
0x90, 0x1d, 0x6f, 0x0a, 0x5a, 0x95, 0x13, 0x11, 0x0d, 0x80, 0xaf, 0x5f, 0x64, 0x98, 0x8a, 0x2c,
0x78, 0x68, 0x65, 0xb0, 0x2b, 0x8b, 0xa2, 0x53, 0x87, 0xca, 0xf1, 0x64, 0x04, 0xab, 0xf2, 0x7b,
0xdb, 0x83, 0xc8, 0x81, 0x02, 0x41, 0x00, 0xf7, 0xbe, 0x5e, 0x23, 0xc3, 0x32, 0x3f, 0xbf, 0x8b,
0x8e, 0x3a, 0xee, 0xfc, 0xfc, 0xcb, 0xe5, 0xf7, 0xf1, 0x0b, 0xbc, 0x42, 0x82, 0xae, 0xd5, 0x7a,
0x3e, 0xca, 0xf7, 0xd5, 0x69, 0x3f, 0x64, 0x25, 0xa2, 0x1f, 0xb7, 0x75, 0x75, 0x05, 0x92, 0x42,
0xeb, 0xb8, 0xf1, 0xf3, 0x0a, 0x05, 0xe3, 0x94, 0xd1, 0x55, 0x78, 0x35, 0xa0, 0x36, 0xa0, 0x9b,
0x7c, 0x92, 0x84, 0x6c, 0xdd, 0xdc, 0x4d, 0x02, 0x41, 0x00, 0xd6, 0x86, 0x0e, 0x85, 0x42, 0x0b,
0x04, 0x08, 0x84, 0x21, 0x60, 0xf0, 0x0e, 0x0d, 0x88, 0xfd, 0x1e, 0x36, 0x10, 0x65, 0x4f, 0x1e,
0x53, 0xb4, 0x08, 0x72, 0x80, 0x5c, 0x3f, 0x59, 0x66, 0x17, 0xe6, 0x98, 0xf2, 0xe9, 0x6c, 0x7a,
0x06, 0x4c, 0xac, 0x76, 0x3d, 0xed, 0x8c, 0xa1, 0xce, 0xad, 0x1b, 0xbd, 0xb4, 0x7d, 0x28, 0xbc,
0xe3, 0x0e, 0x38, 0x8d, 0x99, 0xd8, 0x05, 0xb5, 0xa3, 0x71, 0x02, 0x40, 0x6d, 0xeb, 0xc3, 0x2d,
0x2e, 0xf0, 0x5e, 0xa4, 0x88, 0x31, 0x05, 0x29, 0x00, 0x8a, 0xd1, 0x95, 0x29, 0x9b, 0x83, 0xcf,
0x75, 0xdb, 0x31, 0xe3, 0x7a, 0x27, 0xde, 0x3a, 0x74, 0x30, 0x0c, 0x76, 0x4c, 0xd4, 0x50, 0x2a,
0x40, 0x2d, 0x39, 0xd9, 0x99, 0x63, 0xa9, 0x5d, 0x80, 0xae, 0x53, 0xca, 0x94, 0x3f, 0x05, 0x23,
0x1e, 0xf8, 0x05, 0x04, 0xe1, 0xb8, 0x35, 0xf2, 0x17, 0xb3, 0xa0, 0x89, 0x02, 0x41, 0x00, 0xab,
0x90, 0x88, 0xfa, 0x60, 0x08, 0x29, 0x50, 0x9a, 0x43, 0x8b, 0xa0, 0x50, 0xcc, 0xd8, 0x5a, 0xfe,
0x97, 0x64, 0x63, 0x71, 0x74, 0x22, 0xa3, 0x20, 0x02, 0x5a, 0xcf, 0xeb, 0xc6, 0x16, 0x95, 0x54,
0xd1, 0xcb, 0xab, 0x8d, 0x1a, 0xc6, 0x00, 0xfa, 0x08, 0x92, 0x9c, 0x71, 0xd5, 0x52, 0x52, 0x35,
0x96, 0x71, 0x4b, 0x8b, 0x92, 0x0c, 0xd0, 0xe9, 0xbf, 0xad, 0x63, 0x0b, 0xa5, 0xe9, 0xb1, 0x02,
0x41, 0x00, 0xdc, 0xcc, 0x27, 0xc8, 0xe4, 0xdc, 0x62, 0x48, 0xd5, 0x9b, 0xaf, 0xf5, 0xab, 0x60,
0xf6, 0x21, 0xfd, 0x53, 0xe2, 0xb7, 0x5d, 0x09, 0xc9, 0x1a, 0xa1, 0x04, 0xa9, 0xfc, 0x61, 0x2c,
0x5d, 0x04, 0x58, 0x3a, 0x5a, 0x39, 0xf1, 0x4a, 0x21, 0x56, 0x67, 0xfd, 0xcc, 0x20, 0xa3, 0x8f,
0x78, 0x18, 0x5a, 0x79, 0x3d, 0x2e, 0x8e, 0x7e, 0x86, 0x0a, 0xe6, 0xa8, 0x33, 0xc1, 0x04, 0x17,
0x4a, 0x9f, };
/*** NOTE: OpenSSL seems to have more to their public key format. I've stripped the extra headers... */
static const unsigned char openssl_public_rsa[] = {
0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xcf, 0x9a, 0xde,
0x64, 0x8a, 0xda, 0xc8, 0x33, 0x20, 0xa9, 0xd7, 0x83, 0x31, 0x19, 0x54, 0xb2, 0x9a, 0x85, 0xa7,
0xa1, 0xb7, 0x75, 0x33, 0xb6, 0xa9, 0xac, 0x84, 0x24, 0xb3, 0xde, 0xdb, 0x7d, 0x85, 0x2d, 0x96,
0x65, 0xe5, 0x3f, 0x72, 0x95, 0x24, 0x9f, 0x28, 0x68, 0xca, 0x4f, 0xdb, 0x44, 0x1c, 0x3e, 0x60,
0x12, 0x8a, 0xdd, 0x26, 0xa5, 0xeb, 0xff, 0x0b, 0x5e, 0xd4, 0x88, 0x38, 0x49, 0x2a, 0x6e, 0x5b,
0xbf, 0x12, 0x37, 0x47, 0xbd, 0x05, 0x6b, 0xbc, 0xdb, 0xf3, 0xee, 0xe4, 0x11, 0x8e, 0x41, 0x68,
0x7c, 0x61, 0x13, 0xd7, 0x42, 0xc8, 0x80, 0xbe, 0x36, 0x8f, 0xdc, 0x08, 0x8b, 0x4f, 0xac, 0xa4,
0xe2, 0x76, 0x0c, 0xc9, 0x63, 0x6c, 0x49, 0x58, 0x93, 0xed, 0xcc, 0xaa, 0xdc, 0x25, 0x3b, 0x0a,
0x60, 0x3f, 0x8b, 0x54, 0x3a, 0xc3, 0x4d, 0x31, 0xe7, 0x94, 0xa4, 0x44, 0xfd, 0x02, 0x03, 0x01,
0x00, 0x01, };
static int rsa_compat_test(void)
{
rsa_key key;
unsigned char buf[1024];
unsigned long len;
/* try reading the key */
DO(rsa_import(openssl_private_rsa, sizeof(openssl_private_rsa), &key));
/* now try to export private/public and compare */
len = sizeof(buf);
DO(rsa_export(buf, &len, PK_PRIVATE, &key));
if (len != sizeof(openssl_private_rsa) || memcmp(buf, openssl_private_rsa, len)) {
fprintf(stderr, "RSA private export failed to match OpenSSL output, %lu, %lu\n", len, sizeof(openssl_private_rsa));
{
int x;
printf("\n\n");
for (x = 0; x < len; ) { if (buf[x] == openssl_private_rsa[x]) printf("-- "); else printf("%02x ", buf[x]^openssl_private_rsa[x]); if (!(++x & 15)) printf("\n"); }
}
printf("\n\n");
return 1;
}
len = sizeof(buf);
DO(rsa_export(buf, &len, PK_PUBLIC, &key));
if (len != sizeof(openssl_public_rsa) || memcmp(buf, openssl_public_rsa, len)) {
fprintf(stderr, "RSA(private) public export failed to match OpenSSL output\n");
return 1;
}
rsa_free(&key);
/* try reading the public key */
DO(rsa_import(openssl_public_rsa, sizeof(openssl_public_rsa), &key));
len = sizeof(buf);
DO(rsa_export(buf, &len, PK_PUBLIC, &key));
if (len != sizeof(openssl_public_rsa) || memcmp(buf, openssl_public_rsa, len)) {
fprintf(stderr, "RSA(public) public export failed to match OpenSSL output\n");
return 1;
}
rsa_free(&key);
return 0;
}
int rsa_test(void)
{
unsigned char in[1024], out[1024], tmp[1024];
rsa_key key, privKey, pubKey;
int hash_idx, prng_idx, stat, stat2, cnt;
unsigned long rsa_msgsize, len, len2;
int hash_idx, prng_idx, stat, stat2;
unsigned long rsa_msgsize, len, len2, cnt;
static unsigned char lparam[] = { 0x01, 0x02, 0x03, 0x04 };
if (rsa_compat_test() != 0) {
return 1;
}
hash_idx = find_hash("sha1");
prng_idx = find_prng("yarrow");
if (hash_idx == -1 || prng_idx == -1) {
printf("rsa_test requires SHA1 and yarrow");
fprintf(stderr, "rsa_test requires SHA1 and yarrow");
return 1;
}
@@ -23,32 +130,32 @@ int rsa_test(void)
for (cnt = 0; cnt < 10; cnt++) {
DO(rsa_make_key(&yarrow_prng, prng_idx, 1024/8, 65537, &key));
if (mp_count_bits(&key.N) != 1024) {
printf("rsa_1024 key modulus has %d bits\n", mp_count_bits(&key.N));
fprintf(stderr, "rsa_1024 key modulus has %d bits\n", mp_count_bits(&key.N));
len = mp_unsigned_bin_size(&key.N);
mp_to_unsigned_bin(&key.N, tmp);
printf("N == \n");
fprintf(stderr, "N == \n");
for (cnt = 0; cnt < len; ) {
printf("%02x ", tmp[cnt]);
if (!(++cnt & 15)) printf("\n");
fprintf(stderr, "%02x ", tmp[cnt]);
if (!(++cnt & 15)) fprintf(stderr, "\n");
}
len = mp_unsigned_bin_size(&key.p);
mp_to_unsigned_bin(&key.p, tmp);
printf("p == \n");
fprintf(stderr, "p == \n");
for (cnt = 0; cnt < len; ) {
printf("%02x ", tmp[cnt]);
if (!(++cnt & 15)) printf("\n");
fprintf(stderr, "%02x ", tmp[cnt]);
if (!(++cnt & 15)) fprintf(stderr, "\n");
}
len = mp_unsigned_bin_size(&key.q);
mp_to_unsigned_bin(&key.q, tmp);
printf("\nq == \n");
fprintf(stderr, "\nq == \n");
for (cnt = 0; cnt < len; ) {
printf("%02x ", tmp[cnt]);
if (!(++cnt & 15)) printf("\n");
fprintf(stderr, "%02x ", tmp[cnt]);
if (!(++cnt & 15)) fprintf(stderr, "\n");
}
printf("\n");
fprintf(stderr, "\n");
return 1;
@@ -57,38 +164,7 @@ printf("\n");
rsa_free(&key);
}
}
/* test PKCS #1 v1.5 */
for (cnt = 0; cnt < 4; cnt++) {
for (rsa_msgsize = 1; rsa_msgsize <= 117; rsa_msgsize++) {
/* make a random key/msg */
yarrow_read(in, rsa_msgsize, &yarrow_prng);
len = sizeof(out);
len2 = rsa_msgsize;
/* encrypt */
DO(rsa_v15_encrypt_key(in, rsa_msgsize, out, &len, &yarrow_prng, prng_idx, &key));
DO(rsa_v15_decrypt_key(out, len, tmp, rsa_msgsize, &stat, &key));
if (stat != 1 || memcmp(tmp, in, rsa_msgsize)) {
printf("PKCS #1 v1.5 encrypt/decrypt failure (rsa_msgsize: %lu, stat: %d)\n", rsa_msgsize, stat);
return 1;
}
}
}
/* signature */
len = sizeof(out);
DO(rsa_v15_sign_hash(in, 20, out, &len, hash_idx, &key));
in[1] ^= 1;
DO(rsa_v15_verify_hash(out, len, in, 20, hash_idx, &stat, &key));
in[1] ^= 1;
DO(rsa_v15_verify_hash(out, len, in, 20, hash_idx, &stat2, &key));
if (!(stat == 0 && stat2 == 1)) {
printf("PKCS #1 v1.5 sign/verify failure (stat %d, stat2 %d)\n", stat, stat2);
return 1;
}
/* encrypt the key (without lparam) */
for (cnt = 0; cnt < 4; cnt++) {
for (rsa_msgsize = 1; rsa_msgsize <= 86; rsa_msgsize++) {
@@ -105,35 +181,35 @@ printf("\n");
/* change a byte back */
out[8] ^= 1;
if (len2 != rsa_msgsize) {
printf("\nrsa_decrypt_key mismatch len %lu (first decrypt)", len2);
fprintf(stderr, "\nrsa_decrypt_key mismatch len %lu (first decrypt)", len2);
return 1;
}
len2 = rsa_msgsize;
DO(rsa_decrypt_key(out, len, tmp, &len2, NULL, 0, hash_idx, &stat, &key));
if (!(stat == 1 && stat2 == 0)) {
printf("rsa_decrypt_key failed");
fprintf(stderr, "rsa_decrypt_key failed");
return 1;
}
if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) {
unsigned long x;
printf("\nrsa_decrypt_key mismatch, len %lu (second decrypt)\n", len2);
printf("Original contents: \n");
fprintf(stderr, "\nrsa_decrypt_key mismatch, len %lu (second decrypt)\n", len2);
fprintf(stderr, "Original contents: \n");
for (x = 0; x < rsa_msgsize; ) {
printf("%02x ", in[x]);
fprintf(stderr, "%02x ", in[x]);
if (!(++x % 16)) {
printf("\n");
fprintf(stderr, "\n");
}
}
printf("\n");
printf("Output contents: \n");
fprintf(stderr, "\n");
fprintf(stderr, "Output contents: \n");
for (x = 0; x < rsa_msgsize; ) {
printf("%02x ", out[x]);
fprintf(stderr, "%02x ", out[x]);
if (!(++x % 16)) {
printf("\n");
fprintf(stderr, "\n");
}
}
printf("\n");
fprintf(stderr, "\n");
return 1;
}
}
@@ -148,7 +224,7 @@ printf("\n");
out[8] ^= 1;
DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), hash_idx, &stat2, &key));
if (len2 != rsa_msgsize) {
printf("\nrsa_decrypt_key mismatch len %lu (first decrypt)", len2);
fprintf(stderr, "\nrsa_decrypt_key mismatch len %lu (first decrypt)", len2);
return 1;
}
/* change a byte back */
@@ -157,11 +233,11 @@ printf("\n");
len2 = rsa_msgsize;
DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), hash_idx, &stat, &key));
if (!(stat == 1 && stat2 == 0)) {
printf("rsa_decrypt_key failed");
fprintf(stderr, "rsa_decrypt_key failed");
return 1;
}
if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) {
printf("rsa_decrypt_key mismatch len %lu", len2);
fprintf(stderr, "rsa_decrypt_key mismatch len %lu", len2);
return 1;
}
}
@@ -185,7 +261,7 @@ printf("\n");
DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &key));
if (!(stat == 1 && stat2 == 0)) {
printf("rsa_verify_hash (unsalted, origKey) failed, %d, %d", stat, stat2);
fprintf(stderr, "rsa_verify_hash (unsalted, origKey) failed, %d, %d", stat, stat2);
rsa_free(&key);
rsa_free(&pubKey);
rsa_free(&privKey);
@@ -201,7 +277,7 @@ printf("\n");
DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &privKey));
if (!(stat == 1 && stat2 == 0)) {
printf("rsa_verify_hash (unsalted, privKey) failed, %d, %d", stat, stat2);
fprintf(stderr, "rsa_verify_hash (unsalted, privKey) failed, %d, %d", stat, stat2);
rsa_free(&key);
rsa_free(&pubKey);
rsa_free(&privKey);
@@ -217,7 +293,7 @@ printf("\n");
DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &pubKey));
if (!(stat == 1 && stat2 == 0)) {
printf("rsa_verify_hash (unsalted, pubkey) failed, %d, %d", stat, stat2);
fprintf(stderr, "rsa_verify_hash (unsalted, pubkey) failed, %d, %d", stat, stat2);
rsa_free(&key);
rsa_free(&pubKey);
rsa_free(&privKey);
@@ -233,7 +309,7 @@ printf("\n");
DO(rsa_verify_hash(out, len, in, 20, hash_idx, 8, &stat2, &pubKey));
if (!(stat == 1 && stat2 == 0)) {
printf("rsa_verify_hash (salted) failed, %d, %d", stat, stat2);
fprintf(stderr, "rsa_verify_hash (salted) failed, %d, %d", stat, stat2);
rsa_free(&key);
rsa_free(&pubKey);
rsa_free(&privKey);
@@ -251,8 +327,12 @@ printf("\n");
int rsa_test(void)
{
printf("NOP");
fprintf(stderr, "NOP");
return 0;
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
+37 -3
View File
@@ -3,13 +3,17 @@
/* Test store/load macros with offsets */
int store_test(void)
{
unsigned char buf[24];
unsigned char buf[256];
int y;
ulong32 L, L1;
ulong64 LL, LL1;
#ifdef LTC_FAST
int x, z;
#endif
L = 0x12345678UL;
for (y = 0; y < 4; y++) {
L = 0x12345678UL;
L1 = 0;
STORE32L(L, buf + y);
LOAD32L(L1, buf + y);
if (L1 != L) {
@@ -24,8 +28,9 @@ int store_test(void)
}
}
LL = CONST64 (0x01020304050607);
for (y = 0; y < 8; y++) {
LL = CONST64 (0x01020304050607);
LL1 = 0;
STORE64L(LL, buf + y);
LOAD64L(LL1, buf + y);
if (LL1 != LL) {
@@ -40,5 +45,34 @@ int store_test(void)
}
}
/* test LTC_FAST */
#ifdef LTC_FAST
y = 16;
for (z = 0; z < y; z++) {
/* fill y bytes with random */
yarrow_read(buf+z, y, &yarrow_prng);
yarrow_read(buf+z+y, y, &yarrow_prng);
/* now XOR it byte for byte */
for (x = 0; x < y; x++) {
buf[2*y+z+x] = buf[z+x] ^ buf[z+y+x];
}
/* now XOR it word for word */
for (x = 0; x < y; x += sizeof(LTC_FAST_TYPE)) {
*((LTC_FAST_TYPE*)(&buf[3*y+z+x])) = *((LTC_FAST_TYPE*)(&buf[z+x])) ^ *((LTC_FAST_TYPE*)(&buf[z+y+x]));
}
if (memcmp(&buf[2*y+z], &buf[3*y+z], y)) {
fprintf(stderr, "\nLTC_FAST failed at offset %d\n", z);
return 1;
}
}
#endif
return 0;
}
/* $Source$ */
/* $Revision$ */
/* $Date$ */
+4
View File
@@ -7,3 +7,7 @@ void run_cmd(int res, int line, char *file, char *cmd)
exit(EXIT_FAILURE);
}
}
/* $Source$ */
/* $Revision$ */
/* $Date$ */
+15
View File
@@ -0,0 +1,15 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQDPmt5kitrIMyCp14MxGVSymoWnobd1M7aprIQks97bfYUtlmXl
P3KVJJ8oaMpP20QcPmASit0mpev/C17UiDhJKm5bvxI3R70Fa7zb8+7kEY5BaHxh
E9dCyIC+No/cCItPrKTidgzJY2xJWJPtzKrcJTsKYD+LVDrDTTHnlKRE/QIDAQAB
AoGBAMhiuereRFMdVpfZl54azzAeCohFhikwo02fYWVz4NaHj7bzBqOC3Hys/pso
mq79+/4vDtiXBOO7H9HsDbqjSX9HrIpEBH6GtzlCP60etw6lUfRAYx79veqfQZ+o
kB1vClqVExENgK9fZJiKLHhoZbAri6JTh8rxZASr8nvbg8iBAkEA975eI8MyP7+L
jjru/PzL5ffxC7xCgq7Vej7K99VpP2Qloh+3dXUFkkLruPHzCgXjlNFVeDWgNqCb
fJKEbN3cTQJBANaGDoVCCwQIhCFg8A4NiP0eNhBlTx5TtAhygFw/WWYX5pjy6Wx6
Bkysdj3tjKHOrRu9tH0ovOMOOI2Z2AW1o3ECQG3rwy0u8F6kiDEFKQCK0ZUpm4PP
ddsx43on3jp0MAx2TNRQKkAtOdmZY6ldgK5TypQ/BSMe+AUE4bg18hezoIkCQQCr
kIj6YAgpUJpDi6BQzNha/pdkY3F0IqMgAlrP68YWlVTRy6uNGsYA+giSnHHVUlI1
lnFLi5IM0Om/rWMLpemxAkEA3MwnyOTcYkjVm6/1q2D2If1T4rddCckaoQSp/GEs
XQRYOlo58UohVmf9zCCjj3gYWnk9Lo5+hgrmqDPBBBdKnw==
-----END RSA PRIVATE KEY-----
+4
View File
@@ -71,3 +71,7 @@ void time_encmacs(void);
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
+57 -53
View File
@@ -21,10 +21,10 @@ void tally_results(int type)
// qsort the results
qsort(results, no_results, sizeof(struct list), &sorter);
printf("\n");
fprintf(stderr, "\n");
if (type == 0) {
for (x = 0; x < no_results; x++) {
printf("%-20s: Schedule at %6lu\n", cipher_descriptor[results[x].id].name, (unsigned long)results[x].spd1);
fprintf(stderr, "%-20s: Schedule at %6lu\n", cipher_descriptor[results[x].id].name, (unsigned long)results[x].spd1);
}
} else if (type == 1) {
for (x = 0; x < no_results; x++) {
@@ -42,7 +42,7 @@ void tally_results(int type)
/* RDTSC from Scott Duplichan */
ulong64 rdtsc (void)
{
#if defined __GNUC__
#if defined __GNUC__ && !defined(LTC_NO_ASM)
#ifdef INTEL_CC
ulong64 a;
asm ( " rdtsc ":"=A"(a));
@@ -62,11 +62,11 @@ ulong64 rdtsc (void)
#endif
// Microsoft and Intel Windows compilers
#elif defined _M_IX86
#elif defined _M_IX86 && !defined(LTC_NO_ASM)
__asm rdtsc
#elif defined _M_AMD64
#elif defined _M_AMD64 && !defined(LTC_NO_ASM)
return __rdtsc ();
#elif defined _M_IA64
#elif defined _M_IA64 && !defined(LTC_NO_ASM)
#if defined __INTEL_COMPILER
#include <ia64intrin.h>
#endif
@@ -104,7 +104,7 @@ void init_timer(void)
c2 = (t2 > c2) ? t2 : c2;
}
skew = c2 - c1;
printf("Clock Skew: %lu\n", (unsigned long)skew);
fprintf(stderr, "Clock Skew: %lu\n", (unsigned long)skew);
}
void reg_algs(void)
@@ -199,7 +199,7 @@ void reg_algs(void)
#ifdef CHC_HASH
register_hash(&chc_desc);
if ((err = chc_register(register_cipher(&aes_desc))) != CRYPT_OK) {
printf("chc_register error: %s\n", error_to_string(err));
fprintf(stderr, "chc_register error: %s\n", error_to_string(err));
exit(EXIT_FAILURE);
}
#endif
@@ -231,7 +231,7 @@ int time_keysched(void)
int (*func) (const unsigned char *, int , int , symmetric_key *);
unsigned char key[MAXBLOCKSIZE];
printf ("\n\nKey Schedule Time Trials for the Symmetric Ciphers:\n(Times are cycles per key)\n");
fprintf(stderr, "\n\nKey Schedule Time Trials for the Symmetric Ciphers:\n(Times are cycles per key)\n");
no_results = 0;
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
#define DO1(k) func(k, kl, 0, &skey);
@@ -249,7 +249,7 @@ int time_keysched(void)
t1 = c1 - skew;
results[no_results].spd1 = results[no_results].avg = t1;
results[no_results++].id = x;
printf("."); fflush(stdout);
fprintf(stderr, "."); fflush(stdout);
#undef DO1
}
@@ -266,7 +266,7 @@ int time_cipher(void)
unsigned char key[MAXBLOCKSIZE], pt[4096];
int err;
printf ("\n\nECB Time Trials for the Symmetric Ciphers:\n");
fprintf(stderr, "\n\nECB Time Trials for the Symmetric Ciphers:\n");
no_results = 0;
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
ecb_start(x, key, cipher_descriptor[x].min_key_length, 0, &ecb);
@@ -318,7 +318,7 @@ int time_cipher(void)
results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length);
results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2;
++no_results;
printf("."); fflush(stdout);
fprintf(stderr, "."); fflush(stdout);
#undef DO2
#undef DO1
@@ -337,7 +337,7 @@ int time_cipher2(void)
unsigned char key[MAXBLOCKSIZE], pt[4096];
int err;
printf ("\n\nCBC Time Trials for the Symmetric Ciphers:\n");
fprintf(stderr, "\n\nCBC Time Trials for the Symmetric Ciphers:\n");
no_results = 0;
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
cbc_start(x, pt, key, cipher_descriptor[x].min_key_length, 0, &cbc);
@@ -389,7 +389,7 @@ int time_cipher2(void)
results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length);
results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2;
++no_results;
printf("."); fflush(stdout);
fprintf(stderr, "."); fflush(stdout);
#undef DO2
#undef DO1
@@ -399,7 +399,7 @@ int time_cipher2(void)
return 0;
}
#else
int time_cipher2(void) { printf("NO CBC\n"); return 0; }
int time_cipher2(void) { fprintf(stderr, "NO CBC\n"); return 0; }
#endif
#ifdef CTR
@@ -411,10 +411,10 @@ int time_cipher3(void)
unsigned char key[MAXBLOCKSIZE], pt[4096];
int err;
printf ("\n\nCTR Time Trials for the Symmetric Ciphers:\n");
fprintf(stderr, "\n\nCTR Time Trials for the Symmetric Ciphers:\n");
no_results = 0;
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
ctr_start(x, pt, key, cipher_descriptor[x].min_key_length, 0, &ctr);
ctr_start(x, pt, key, cipher_descriptor[x].min_key_length, 0, CTR_COUNTER_LITTLE_ENDIAN, &ctr);
/* sanity check on cipher */
if ((err = cipher_descriptor[x].test()) != CRYPT_OK) {
@@ -463,7 +463,7 @@ int time_cipher3(void)
results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length);
results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2;
++no_results;
printf("."); fflush(stdout);
fprintf(stderr, "."); fflush(stdout);
#undef DO2
#undef DO1
@@ -473,7 +473,7 @@ int time_cipher3(void)
return 0;
}
#else
int time_cipher3(void) { printf("NO CTR\n"); return 0; }
int time_cipher3(void) { fprintf(stderr, "NO CTR\n"); return 0; }
#endif
int time_hash(void)
@@ -485,7 +485,7 @@ int time_hash(void)
unsigned char pt[MAXBLOCKSIZE];
printf ("\n\nHASH Time Trials for:\n");
fprintf(stderr, "\n\nHASH Time Trials for:\n");
no_results = 0;
for (x = 0; hash_descriptor[x].name != NULL; x++) {
@@ -518,7 +518,7 @@ int time_hash(void)
results[no_results].id = x;
results[no_results].spd1 = results[no_results].avg = t1;
++no_results;
printf("."); fflush(stdout);
fprintf(stderr, "."); fflush(stdout);
#undef DO2
#undef DO1
}
@@ -534,7 +534,7 @@ void time_mult(void)
unsigned long x, y;
mp_int a, b, c;
printf("Timing Multiplying:\n");
fprintf(stderr, "Timing Multiplying:\n");
mp_init_multi(&a,&b,&c,NULL);
for (x = 128/DIGIT_BIT; x <= 1536/DIGIT_BIT; x += 128/DIGIT_BIT) {
mp_rand(&a, x);
@@ -551,7 +551,7 @@ void time_mult(void)
t1 = (t_read() - t1)>>1;
if (t1 < t2) t2 = t1;
}
printf("%4lu bits: %9llu cycles\n", x*DIGIT_BIT, t2);
fprintf(stderr, "%4lu bits: %9llu cycles\n", x*DIGIT_BIT, t2);
}
mp_clear_multi(&a,&b,&c,NULL);
@@ -565,7 +565,7 @@ void time_sqr(void)
unsigned long x, y;
mp_int a, b;
printf("Timing Squaring:\n");
fprintf(stderr, "Timing Squaring:\n");
mp_init_multi(&a,&b,NULL);
for (x = 128/DIGIT_BIT; x <= 1536/DIGIT_BIT; x += 128/DIGIT_BIT) {
mp_rand(&a, x);
@@ -581,7 +581,7 @@ void time_sqr(void)
t1 = (t_read() - t1)>>1;
if (t1 < t2) t2 = t1;
}
printf("%4lu bits: %9llu cycles\n", x*DIGIT_BIT, t2);
fprintf(stderr, "%4lu bits: %9llu cycles\n", x*DIGIT_BIT, t2);
}
mp_clear_multi(&a,&b,NULL);
@@ -589,8 +589,8 @@ void time_sqr(void)
#undef DO2
}
#else
void time_mult(void) { printf("NO MULT\n"); }
void time_sqr(void) { printf("NO SQR\n"); }
void time_mult(void) { fprintf(stderr, "NO MULT\n"); }
void time_sqr(void) { fprintf(stderr, "NO SQR\n"); }
#endif
void time_prng(void)
@@ -601,7 +601,7 @@ void time_prng(void)
unsigned long x, y;
int err;
printf("Timing PRNGs (cycles/byte output, cycles add_entropy (32 bytes) :\n");
fprintf(stderr, "Timing PRNGs (cycles/byte output, cycles add_entropy (32 bytes) :\n");
for (x = 0; prng_descriptor[x].name != NULL; x++) {
/* sanity check on prng */
@@ -616,7 +616,7 @@ void time_prng(void)
prng_descriptor[x].ready(&tprng);
t2 = -1;
#define DO1 if (prng_descriptor[x].read(buf, 4096, &tprng) != 4096) { printf("\n\nERROR READ != 4096\n\n"); exit(EXIT_FAILURE); }
#define DO1 if (prng_descriptor[x].read(buf, 4096, &tprng) != 4096) { fprintf(stderr, "\n\nERROR READ != 4096\n\n"); exit(EXIT_FAILURE); }
#define DO2 DO1 DO1
for (y = 0; y < 10000; y++) {
t_start();
@@ -625,7 +625,7 @@ void time_prng(void)
t1 = (t_read() - t1)>>1;
if (t1 < t2) t2 = t1;
}
printf("%20s: %5llu ", prng_descriptor[x].name, t2>>12);
fprintf(stderr, "%20s: %5llu ", prng_descriptor[x].name, t2>>12);
#undef DO2
#undef DO1
@@ -638,7 +638,7 @@ void time_prng(void)
t1 = (t_read() - t1)>>1;
if (t1 < t2) t2 = t1;
}
printf("%5llu\n", t2);
fprintf(stderr, "%5llu\n", t2);
#undef DO2
#undef DO1
@@ -672,7 +672,7 @@ void time_rsa(void)
}
}
t2 >>= 4;
printf("RSA-%lu make_key took %15llu cycles\n", x, t2);
fprintf(stderr, "RSA-%lu make_key took %15llu cycles\n", x, t2);
t2 = 0;
for (y = 0; y < 16; y++) {
@@ -689,7 +689,7 @@ void time_rsa(void)
t2 += t1;
}
t2 >>= 4;
printf("RSA-%lu encrypt_key took %15llu cycles\n", x, t2);
fprintf(stderr, "RSA-%lu encrypt_key took %15llu cycles\n", x, t2);
t2 = 0;
for (y = 0; y < 16; y++) {
@@ -705,14 +705,14 @@ void time_rsa(void)
t2 += t1;
}
t2 >>= 4;
printf("RSA-%lu decrypt_key took %15llu cycles\n", x, t2);
fprintf(stderr, "RSA-%lu decrypt_key took %15llu cycles\n", x, t2);
rsa_free(&key);
}
}
#else
void time_rsa(void) { printf("NO RSA\n"); }
void time_rsa(void) { fprintf(stderr, "NO RSA\n"); }
#endif
#ifdef MECC
@@ -743,7 +743,7 @@ void time_ecc(void)
}
}
t2 >>= 4;
printf("ECC-%lu make_key took %15llu cycles\n", x*8, t2);
fprintf(stderr, "ECC-%lu make_key took %15llu cycles\n", x*8, t2);
t2 = 0;
for (y = 0; y < 16; y++) {
@@ -759,12 +759,12 @@ void time_ecc(void)
t2 += t1;
}
t2 >>= 4;
printf("ECC-%lu encrypt_key took %15llu cycles\n", x*8, t2);
fprintf(stderr, "ECC-%lu encrypt_key took %15llu cycles\n", x*8, t2);
ecc_free(&key);
}
}
#else
void time_ecc(void) { printf("NO ECC\n"); }
void time_ecc(void) { fprintf(stderr, "NO ECC\n"); }
#endif
#ifdef MDH
@@ -795,7 +795,7 @@ void time_dh(void)
}
}
t2 >>= 4;
printf("DH-%4lu make_key took %15llu cycles\n", x*8, t2);
fprintf(stderr, "DH-%4lu make_key took %15llu cycles\n", x*8, t2);
t2 = 0;
for (y = 0; y < 16; y++) {
@@ -811,12 +811,12 @@ void time_dh(void)
t2 += t1;
}
t2 >>= 4;
printf("DH-%4lu encrypt_key took %15llu cycles\n", x*8, t2);
fprintf(stderr, "DH-%4lu encrypt_key took %15llu cycles\n", x*8, t2);
dh_free(&key);
}
}
#else
void time_dh(void) { printf("NO DH\n"); }
void time_dh(void) { fprintf(stderr, "NO DH\n"); }
#endif
void time_macs_(unsigned long MAC_SIZE)
@@ -826,7 +826,7 @@ void time_macs_(unsigned long MAC_SIZE)
unsigned long x, z;
int err, cipher_idx, hash_idx;
printf("\nMAC Timings (cycles/byte on %dKB blocks):\n", MAC_SIZE);
fprintf(stderr, "\nMAC Timings (cycles/byte on %luKB blocks):\n", MAC_SIZE);
buf = XMALLOC(MAC_SIZE*1024);
if (buf == NULL) {
@@ -853,7 +853,7 @@ void time_macs_(unsigned long MAC_SIZE)
t1 = t_read() - t1;
if (t1 < t2) t2 = t1;
}
printf("OMAC-AES\t\t%9llu\n", t2/(MAC_SIZE*1024));
fprintf(stderr, "OMAC-AES\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
#endif
#ifdef PMAC
@@ -869,7 +869,7 @@ void time_macs_(unsigned long MAC_SIZE)
t1 = t_read() - t1;
if (t1 < t2) t2 = t1;
}
printf("PMAC-AES\t\t%9llu\n", t2/(MAC_SIZE*1024));
fprintf(stderr, "PMAC-AES\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
#endif
#ifdef PELICAN
@@ -885,7 +885,7 @@ void time_macs_(unsigned long MAC_SIZE)
t1 = t_read() - t1;
if (t1 < t2) t2 = t1;
}
printf("PELICAN \t\t%9llu\n", t2/(MAC_SIZE*1024));
fprintf(stderr, "PELICAN \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
#endif
#ifdef HMAC
@@ -901,7 +901,7 @@ void time_macs_(unsigned long MAC_SIZE)
t1 = t_read() - t1;
if (t1 < t2) t2 = t1;
}
printf("HMAC-MD5\t\t%9llu\n", t2/(MAC_SIZE*1024));
fprintf(stderr, "HMAC-MD5\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
#endif
XFREE(buf);
@@ -921,7 +921,7 @@ void time_encmacs_(unsigned long MAC_SIZE)
unsigned long x, z;
int err, cipher_idx;
printf("\nENC+MAC Timings (zero byte AAD, 16 byte IV, cycles/byte on %dKB blocks):\n", MAC_SIZE);
fprintf(stderr, "\nENC+MAC Timings (zero byte AAD, 16 byte IV, cycles/byte on %luKB blocks):\n", MAC_SIZE);
buf = XMALLOC(MAC_SIZE*1024);
if (buf == NULL) {
@@ -948,7 +948,7 @@ void time_encmacs_(unsigned long MAC_SIZE)
t1 = t_read() - t1;
if (t1 < t2) t2 = t1;
}
printf("EAX \t\t%9llu\n", t2/(MAC_SIZE*1024));
fprintf(stderr, "EAX \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
#endif
#ifdef OCB_MODE
@@ -964,7 +964,7 @@ void time_encmacs_(unsigned long MAC_SIZE)
t1 = t_read() - t1;
if (t1 < t2) t2 = t1;
}
printf("OCB \t\t%9llu\n", t2/(MAC_SIZE*1024));
fprintf(stderr, "OCB \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
#endif
#ifdef CCM_MODE
@@ -980,7 +980,7 @@ void time_encmacs_(unsigned long MAC_SIZE)
t1 = t_read() - t1;
if (t1 < t2) t2 = t1;
}
printf("CCM \t\t%9llu\n", t2/(MAC_SIZE*1024));
fprintf(stderr, "CCM \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
#endif
#ifdef GCM_MODE
@@ -996,12 +996,12 @@ void time_encmacs_(unsigned long MAC_SIZE)
t1 = t_read() - t1;
if (t1 < t2) t2 = t1;
}
printf("GCM (no-precomp)\t%9llu\n", t2/(MAC_SIZE*1024));
fprintf(stderr, "GCM (no-precomp)\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
{
gcm_state gcm;
if ((err = gcm_init(&gcm, cipher_idx, key, 16)) != CRYPT_OK) { printf("gcm_init: %s\n", error_to_string(err)); exit(EXIT_FAILURE); }
if ((err = gcm_init(&gcm, cipher_idx, key, 16)) != CRYPT_OK) { fprintf(stderr, "gcm_init: %s\n", error_to_string(err)); exit(EXIT_FAILURE); }
t2 = -1;
for (x = 0; x < 10000; x++) {
t_start();
@@ -1031,7 +1031,7 @@ void time_encmacs_(unsigned long MAC_SIZE)
t1 = t_read() - t1;
if (t1 < t2) t2 = t1;
}
printf("GCM (precomp)\t%9llu\n", t2/(MAC_SIZE*1024));
fprintf(stderr, "GCM (precomp)\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
}
#endif
@@ -1044,3 +1044,7 @@ void time_encmacs(void)
time_encmacs_(4);
time_encmacs_(32);
}
/* $Source$ */
/* $Revision$ */
/* $Date$ */