summaryrefslogtreecommitdiffhomepage
path: root/testprof
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2007-01-11 02:39:21 +0000
committerMatt Johnston <matt@ucc.asn.au>2007-01-11 02:39:21 +0000
commit28ad393b008b34bc3cdbaa192440b8cc615329f0 (patch)
tree00fcfa9acba720e69b2665fd48d8744822f1f0fb /testprof
parent33defd1f9b6c4889fe5b075e6abb0b24c00f3a59 (diff)
parentf3b834d5366011e1e4b340c7acdbd582c7e50689 (diff)
propagate from branch 'au.asn.ucc.matt.ltc.orig' (head 52840647ac7f5c707c3bd158d119a15734a7ef28)
to branch 'au.asn.ucc.matt.ltc.dropbear' (head 20dccfc09627970a312d77fb41dc2970b62689c3) --HG-- branch : libtomcrypt-dropbear extra : convert_revision : 2af22fb4e878750b88f80f90d439b316d229796f
Diffstat (limited to 'testprof')
-rw-r--r--testprof/der_tests.c569
-rw-r--r--testprof/dh_tests.c103
-rw-r--r--testprof/dsa_test.c20
-rw-r--r--testprof/ecc_test.c131
-rw-r--r--testprof/katja_test.c231
-rw-r--r--testprof/mac_test.c16
-rw-r--r--testprof/makefile21
-rw-r--r--testprof/makefile.icc15
-rw-r--r--testprof/makefile.msvc6
-rw-r--r--testprof/makefile.shared27
-rw-r--r--testprof/modes_test.c47
-rw-r--r--testprof/pkcs_1_test.c15
-rw-r--r--testprof/rsa_test.c97
-rw-r--r--testprof/test.derbin0 -> 162 bytes
-rw-r--r--testprof/test_driver.c (renamed from testprof/test.c)10
-rw-r--r--testprof/tomcrypt_test.h18
-rw-r--r--testprof/x86_prof.c534
17 files changed, 1532 insertions, 328 deletions
diff --git a/testprof/der_tests.c b/testprof/der_tests.c
index 8119351..2881886 100644
--- a/testprof/der_tests.c
+++ b/testprof/der_tests.c
@@ -1,4 +1,7 @@
#include <tomcrypt_test.h>
+#if defined(GMP_DESC) || defined(USE_GMP)
+#include <gmp.h>
+#endif
#ifndef LTC_DER
@@ -10,12 +13,449 @@ int der_tests(void)
#else
+static void der_set_test(void)
+{
+ ltc_asn1_list list[10];
+ static const unsigned char oct_str[] = { 1, 2, 3, 4 };
+ static const unsigned char bin_str[] = { 1, 0, 0, 1 };
+ static const unsigned long int_val = 12345678UL;
+
+ unsigned char strs[10][10], outbuf[128];
+ unsigned long x, val, outlen;
+ int err;
+
+ /* make structure and encode it */
+ LTC_SET_ASN1(list, 0, LTC_ASN1_OCTET_STRING, oct_str, sizeof(oct_str));
+ LTC_SET_ASN1(list, 1, LTC_ASN1_BIT_STRING, bin_str, sizeof(bin_str));
+ LTC_SET_ASN1(list, 2, LTC_ASN1_SHORT_INTEGER, &int_val, 1);
+
+ /* encode it */
+ outlen = sizeof(outbuf);
+ if ((err = der_encode_set(list, 3, outbuf, &outlen)) != CRYPT_OK) {
+ fprintf(stderr, "error encoding set: %s\n", error_to_string(err));
+ exit(EXIT_FAILURE);
+ }
+
+
+ /* first let's test the set_decoder out of order to see what happens, we should get all the fields we expect even though they're in a diff order */
+ LTC_SET_ASN1(list, 0, LTC_ASN1_BIT_STRING, strs[1], sizeof(strs[1]));
+ LTC_SET_ASN1(list, 1, LTC_ASN1_SHORT_INTEGER, &val, 1);
+ LTC_SET_ASN1(list, 2, LTC_ASN1_OCTET_STRING, strs[0], sizeof(strs[0]));
+
+ if ((err = der_decode_set(outbuf, outlen, list, 3)) != CRYPT_OK) {
+ fprintf(stderr, "error decoding set using der_decode_set: %s\n", error_to_string(err));
+ exit(EXIT_FAILURE);
+ }
+
+ /* now compare the items */
+ if (memcmp(strs[0], oct_str, sizeof(oct_str))) {
+ fprintf(stderr, "error decoding set using der_decode_set (oct_str is wrong):\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (memcmp(strs[1], bin_str, sizeof(bin_str))) {
+ fprintf(stderr, "error decoding set using der_decode_set (bin_str is wrong):\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (val != int_val) {
+ fprintf(stderr, "error decoding set using der_decode_set (int_val is wrong):\n");
+ exit(EXIT_FAILURE);
+ }
+
+ strcpy((char*)strs[0], "one");
+ strcpy((char*)strs[1], "one2");
+ strcpy((char*)strs[2], "two");
+ strcpy((char*)strs[3], "aaa");
+ strcpy((char*)strs[4], "aaaa");
+ strcpy((char*)strs[5], "aab");
+ strcpy((char*)strs[6], "aaab");
+ strcpy((char*)strs[7], "bbb");
+ strcpy((char*)strs[8], "bbba");
+ strcpy((char*)strs[9], "bbbb");
+
+ for (x = 0; x < 10; x++) {
+ LTC_SET_ASN1(list, x, LTC_ASN1_PRINTABLE_STRING, strs[x], strlen((char*)strs[x]));
+ }
+
+ outlen = sizeof(outbuf);
+ if ((err = der_encode_setof(list, 10, outbuf, &outlen)) != CRYPT_OK) {
+ fprintf(stderr, "error encoding SET OF: %s\n", error_to_string(err));
+ exit(EXIT_FAILURE);
+ }
+
+ for (x = 0; x < 10; x++) {
+ LTC_SET_ASN1(list, x, LTC_ASN1_PRINTABLE_STRING, strs[x], sizeof(strs[x]) - 1);
+ }
+ XMEMSET(strs, 0, sizeof(strs));
+
+ if ((err = der_decode_set(outbuf, outlen, list, 10)) != CRYPT_OK) {
+ fprintf(stderr, "error decoding SET OF: %s\n", error_to_string(err));
+ exit(EXIT_FAILURE);
+ }
+
+ /* now compare */
+ for (x = 1; x < 10; x++) {
+ if (!(strlen((char*)strs[x-1]) <= strlen((char*)strs[x])) && strcmp((char*)strs[x-1], (char*)strs[x]) >= 0) {
+ fprintf(stderr, "error SET OF order at %lu is wrong\n", x);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+}
+
+
+/* we are encoding
+
+ SEQUENCE {
+ PRINTABLE "printable"
+ IA5 "ia5"
+ SEQUENCE {
+ INTEGER 12345678
+ UTCTIME { 91, 5, 6, 16, 45, 40, 1, 7, 0 }
+ SEQUENCE {
+ OCTET STRING { 1, 2, 3, 4 }
+ BIT STRING { 1, 0, 0, 1 }
+ SEQUENCE {
+ OID { 1, 2, 840, 113549 }
+ NULL
+ SET OF {
+ PRINTABLE "333" // WILL GET SORTED
+ PRINTABLE "222"
+ }
+ }
+ }
+ }
+
+*/
+
+static void der_flexi_test(void)
+{
+ static const char printable_str[] = "printable";
+ static const char set1_str[] = "333";
+ static const char set2_str[] = "222";
+ static const char ia5_str[] = "ia5";
+ static const unsigned long int_val = 12345678UL;
+ static const ltc_utctime utctime = { 91, 5, 6, 16, 45, 40, 1, 7, 0 };
+ static const unsigned char oct_str[] = { 1, 2, 3, 4 };
+ static const unsigned char bit_str[] = { 1, 0, 0, 1 };
+ static const unsigned long oid_str[] = { 1, 2, 840, 113549 };
+
+ unsigned char encode_buf[192];
+ unsigned long encode_buf_len, decode_len;
+ int err;
+
+ ltc_asn1_list static_list[5][3], *decoded_list, *l;
+
+ /* build list */
+ LTC_SET_ASN1(static_list[0], 0, LTC_ASN1_PRINTABLE_STRING, (void *)printable_str, strlen(printable_str));
+ LTC_SET_ASN1(static_list[0], 1, LTC_ASN1_IA5_STRING, (void *)ia5_str, strlen(ia5_str));
+ LTC_SET_ASN1(static_list[0], 2, LTC_ASN1_SEQUENCE, static_list[1], 3);
+
+ LTC_SET_ASN1(static_list[1], 0, LTC_ASN1_SHORT_INTEGER, (void *)&int_val, 1);
+ LTC_SET_ASN1(static_list[1], 1, LTC_ASN1_UTCTIME, (void *)&utctime, 1);
+ LTC_SET_ASN1(static_list[1], 2, LTC_ASN1_SEQUENCE, static_list[2], 3);
+
+ LTC_SET_ASN1(static_list[2], 0, LTC_ASN1_OCTET_STRING, (void *)oct_str, 4);
+ LTC_SET_ASN1(static_list[2], 1, LTC_ASN1_BIT_STRING, (void *)bit_str, 4);
+ LTC_SET_ASN1(static_list[2], 2, LTC_ASN1_SEQUENCE, static_list[3], 3);
+
+ LTC_SET_ASN1(static_list[3], 0, LTC_ASN1_OBJECT_IDENTIFIER,(void *)oid_str, 4);
+ LTC_SET_ASN1(static_list[3], 1, LTC_ASN1_NULL, NULL, 0);
+ LTC_SET_ASN1(static_list[3], 2, LTC_ASN1_SETOF, static_list[4], 2);
+
+ LTC_SET_ASN1(static_list[4], 0, LTC_ASN1_PRINTABLE_STRING, set1_str, strlen(set1_str));
+ LTC_SET_ASN1(static_list[4], 1, LTC_ASN1_PRINTABLE_STRING, set2_str, strlen(set2_str));
+
+ /* encode it */
+ encode_buf_len = sizeof(encode_buf);
+ if ((err = der_encode_sequence(&static_list[0][0], 3, encode_buf, &encode_buf_len)) != CRYPT_OK) {
+ fprintf(stderr, "Encoding static_list: %s\n", error_to_string(err));
+ exit(EXIT_FAILURE);
+ }
+
+#if 0
+ {
+ FILE *f;
+ f = fopen("t.bin", "wb");
+ fwrite(encode_buf, 1, encode_buf_len, f);
+ fclose(f);
+ }
+#endif
+
+ /* decode with flexi */
+ decode_len = encode_buf_len;
+ if ((err = der_decode_sequence_flexi(encode_buf, &decode_len, &decoded_list)) != CRYPT_OK) {
+ fprintf(stderr, "decoding static_list: %s\n", error_to_string(err));
+ exit(EXIT_FAILURE);
+ }
+
+ if (decode_len != encode_buf_len) {
+ fprintf(stderr, "Decode len of %lu does not match encode len of %lu \n", decode_len, encode_buf_len);
+ exit(EXIT_FAILURE);
+ }
+
+ /* we expect l->next to be NULL and l->child to not be */
+ l = decoded_list;
+ if (l->next != NULL || l->child == NULL) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ /* we expect a SEQUENCE */
+ if (l->type != LTC_ASN1_SEQUENCE) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+ l = l->child;
+
+ /* PRINTABLE STRING */
+ /* we expect printable_str */
+ if (l->next == NULL || l->child != NULL) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->type != LTC_ASN1_PRINTABLE_STRING) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->size != strlen(printable_str) || memcmp(printable_str, l->data, l->size)) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ /* move to next */
+ l = l->next;
+
+ /* IA5 STRING */
+ /* we expect ia5_str */
+ if (l->next == NULL || l->child != NULL) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->type != LTC_ASN1_IA5_STRING) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->size != strlen(ia5_str) || memcmp(ia5_str, l->data, l->size)) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ /* move to next */
+ l = l->next;
+
+ /* expect child anve move down */
+
+ if (l->next != NULL || l->child == NULL) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->type != LTC_ASN1_SEQUENCE) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+ l = l->child;
+
+
+ /* INTEGER */
+
+ if (l->next == NULL || l->child != NULL) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->type != LTC_ASN1_INTEGER) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (mp_cmp_d(l->data, 12345678UL) != LTC_MP_EQ) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ /* move to next */
+ l = l->next;
+
+ /* UTCTIME */
+
+ if (l->next == NULL || l->child != NULL) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->type != LTC_ASN1_UTCTIME) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (memcmp(l->data, &utctime, sizeof(utctime))) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ /* move to next */
+ l = l->next;
+
+ /* expect child anve move down */
+
+ if (l->next != NULL || l->child == NULL) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->type != LTC_ASN1_SEQUENCE) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+ l = l->child;
+
+
+ /* OCTET STRING */
+ /* we expect oct_str */
+ if (l->next == NULL || l->child != NULL) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->type != LTC_ASN1_OCTET_STRING) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->size != sizeof(oct_str) || memcmp(oct_str, l->data, l->size)) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ /* move to next */
+ l = l->next;
+
+ /* BIT STRING */
+ /* we expect oct_str */
+ if (l->next == NULL || l->child != NULL) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->type != LTC_ASN1_BIT_STRING) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->size != sizeof(bit_str) || memcmp(bit_str, l->data, l->size)) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ /* move to next */
+ l = l->next;
+
+ /* expect child anve move down */
+
+ if (l->next != NULL || l->child == NULL) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->type != LTC_ASN1_SEQUENCE) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+ l = l->child;
+
+
+ /* OID STRING */
+ /* we expect oid_str */
+ if (l->next == NULL || l->child != NULL) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->type != LTC_ASN1_OBJECT_IDENTIFIER) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->size != sizeof(oid_str)/sizeof(oid_str[0]) || memcmp(oid_str, l->data, l->size*sizeof(oid_str[0]))) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ /* move to next */
+ l = l->next;
+
+ /* NULL */
+ if (l->type != LTC_ASN1_NULL) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ /* move to next */
+ l = l->next;
+
+ /* expect child anve move down */
+ if (l->next != NULL || l->child == NULL) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->type != LTC_ASN1_SET) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+ l = l->child;
+
+ /* PRINTABLE STRING */
+ /* we expect printable_str */
+ if (l->next == NULL || l->child != NULL) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->type != LTC_ASN1_PRINTABLE_STRING) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+/* note we compare set2_str FIRST because the SET OF is sorted and "222" comes before "333" */
+ if (l->size != strlen(set2_str) || memcmp(set2_str, l->data, l->size)) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ /* move to next */
+ l = l->next;
+
+ /* PRINTABLE STRING */
+ /* we expect printable_str */
+ if (l->type != LTC_ASN1_PRINTABLE_STRING) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+ if (l->size != strlen(set1_str) || memcmp(set1_str, l->data, l->size)) {
+ fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
+ exit(EXIT_FAILURE);
+ }
+
+
+ der_sequence_free(l);
+
+}
+
static int der_choice_test(void)
{
ltc_asn1_list types[7], host[1];
unsigned char bitbuf[10], octetbuf[10], ia5buf[10], printbuf[10], outbuf[256];
unsigned long integer, oidbuf[10], outlen, inlen, x, y;
- mp_int mpinteger;
+ void *mpinteger;
ltc_utctime utctime = { 91, 5, 6, 16, 45, 40, 1, 7, 0 };
/* setup variables */
@@ -25,7 +465,7 @@ static int der_choice_test(void)
for (x = 0; x < sizeof(printbuf); x++) { printbuf[x] = 'a'; }
integer = 1;
for (x = 0; x < sizeof(oidbuf)/sizeof(oidbuf[0]); x++) { oidbuf[x] = x + 1; }
- DO(mpi_to_ltc_error(mp_init(&mpinteger)));
+ DO(mp_init(&mpinteger));
for (x = 0; x < 14; x++) {
/* setup list */
@@ -36,7 +476,7 @@ static int der_choice_test(void)
if (x > 7) {
LTC_SET_ASN1(types, 4, LTC_ASN1_SHORT_INTEGER, &integer, 1);
} else {
- LTC_SET_ASN1(types, 4, LTC_ASN1_INTEGER, &mpinteger, 1);
+ LTC_SET_ASN1(types, 4, LTC_ASN1_INTEGER, mpinteger, 1);
}
LTC_SET_ASN1(types, 5, LTC_ASN1_OBJECT_IDENTIFIER, oidbuf, sizeof(oidbuf)/sizeof(oidbuf[0]));
LTC_SET_ASN1(types, 6, LTC_ASN1_UTCTIME, &utctime, 1);
@@ -50,7 +490,7 @@ static int der_choice_test(void)
/* decode it */
inlen = outlen;
- DO(der_decode_sequence(outbuf, inlen, &host, 1));
+ DO(der_decode_sequence(outbuf, inlen, &host[0], 1));
for (y = 0; y < 7; y++) {
if (types[y].used && y != (x>6?x-7:x)) {
@@ -63,7 +503,7 @@ static int der_choice_test(void)
}
}
}
- mp_clear(&mpinteger);
+ mp_clear(mpinteger);
return 0;
}
@@ -72,7 +512,7 @@ int der_tests(void)
{
unsigned long x, y, z, zz, oid[2][32];
unsigned char buf[3][2048];
- mp_int a, b, c, d, e, f, g;
+ void *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 };
@@ -92,29 +532,36 @@ int der_tests(void)
static const unsigned char rsa_time1_der[] = { 0x17, 0x11, 0x39, 0x31, 0x30, 0x35, 0x30, 0x36, 0x31, 0x36, 0x34, 0x35, 0x34, 0x30, 0x2D, 0x30, 0x37, 0x30, 0x30 };
static const unsigned char rsa_time2_der[] = { 0x17, 0x0d, 0x39, 0x31, 0x30, 0x35, 0x30, 0x36, 0x32, 0x33, 0x34, 0x35, 0x34, 0x30, 0x5a };
- DO(mpi_to_ltc_error(mp_init_multi(&a, &b, &c, &d, &e, &f, &g, NULL)));
+ static const wchar_t utf8_1[] = { 0x0041, 0x2262, 0x0391, 0x002E };
+ static const unsigned char utf8_1_der[] = { 0x0C, 0x07, 0x41, 0xE2, 0x89, 0xA2, 0xCE, 0x91, 0x2E };
+ static const wchar_t utf8_2[] = { 0xD55C, 0xAD6D, 0xC5B4 };
+ static const unsigned char utf8_2_der[] = { 0x0C, 0x09, 0xED, 0x95, 0x9C, 0xEA, 0xB5, 0xAD, 0xEC, 0x96, 0xB4 };
+
+ unsigned char utf8_buf[32];
+ wchar_t utf8_out[32];
+
+ DO(mp_init_multi(&a, &b, &c, &d, &e, &f, &g, NULL));
for (zz = 0; zz < 16; zz++) {
+#ifdef USE_TFM
+ for (z = 0; z < 256; z++) {
+#else
for (z = 0; z < 1024; z++) {
+#endif
if (yarrow_read(buf[0], z, &yarrow_prng) != 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; }
+ DO(mp_read_unsigned_bin(a, buf[0], z));
+/* if (mp_iszero(a) == LTC_MP_NO) { a.sign = buf[0][0] & 1 ? LTC_MP_ZPOS : LTC_MP_NEG; } */
x = sizeof(buf[0]);
- DO(der_encode_integer(&a, buf[0], &x));
- DO(der_length_integer(&a, &y));
+ DO(der_encode_integer(a, buf[0], &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));
- if (y != x || mp_cmp(&a, &b) != MP_EQ) {
+ mp_set_int(b, 0);
+ DO(der_decode_integer(buf[0], y, b));
+ if (y != x || mp_cmp(a, b) != LTC_MP_EQ) {
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]);
- fprintf(stderr, "a == %s\nb == %s\n", buf[0], buf[1]);
-#endif
- mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
+ mp_clear_multi(a, b, c, d, e, f, g, NULL);
return 1;
}
}
@@ -128,33 +575,33 @@ int der_tests(void)
return 1;
}
/* encode with normal */
- DO(mpi_to_ltc_error(mp_read_unsigned_bin(&a, buf[0], z)));
+ DO(mp_read_unsigned_bin(a, buf[0], z));
x = sizeof(buf[0]);
- DO(der_encode_integer(&a, buf[0], &x));
+ 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));
+ 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);
+ 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);
+ 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);
+ mp_clear_multi(a, b, c, d, e, f, g, NULL);
/* Test bit string */
@@ -199,7 +646,7 @@ int der_tests(void)
/* test OID */
x = sizeof(buf[0]);
- DO(der_encode_object_identifier(rsa_oid, sizeof(rsa_oid)/sizeof(rsa_oid[0]), buf[0], &x));
+ DO(der_encode_object_identifier((unsigned long*)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]);
@@ -259,45 +706,45 @@ int der_tests(void)
/* IA5 string */
x = sizeof(buf[0]);
- DO(der_encode_ia5_string(rsa_ia5, strlen(rsa_ia5), buf[0], &x));
+ DO(der_encode_ia5_string(rsa_ia5, strlen((char*)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;
}
- DO(der_length_ia5_string(rsa_ia5, strlen(rsa_ia5), &y));
+ DO(der_length_ia5_string(rsa_ia5, strlen((char*)rsa_ia5), &y));
if (y != x) {
fprintf(stderr, "IA5 length failed to match: %lu, %lu\n", x, y);
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))) {
+ if (y != strlen((char*)rsa_ia5) || memcmp(buf[1], rsa_ia5, strlen((char*)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));
+ DO(der_encode_printable_string(rsa_printable, strlen((char*)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;
}
- DO(der_length_printable_string(rsa_printable, strlen(rsa_printable), &y));
+ DO(der_length_printable_string(rsa_printable, strlen((char*)rsa_printable), &y));
if (y != x) {
fprintf(stderr, "printable length failed to match: %lu, %lu\n", x, y);
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))) {
+ if (y != strlen((char*)rsa_printable) || memcmp(buf[1], rsa_printable, strlen((char*)rsa_printable))) {
fprintf(stderr, "DER printable failed test vector\n");
return 1;
}
/* Test UTC time */
x = sizeof(buf[0]);
- DO(der_encode_utctime(&rsa_time1, buf[0], &x));
+ DO(der_encode_utctime((ltc_utctime*)&rsa_time1, buf[0], &x));
if (x != sizeof(rsa_time1_der) || memcmp(buf[0], rsa_time1_der, x)) {
fprintf(stderr, "UTCTIME encode of rsa_time1 failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_time1_der));
fprintf(stderr, "\n\n");
@@ -305,7 +752,7 @@ for (y = 0; y < x; y++) fprintf(stderr, "%02x ", buf[0][y]); printf("\n");
return 1;
}
- DO(der_length_utctime(&rsa_time1, &y));
+ DO(der_length_utctime((ltc_utctime*)&rsa_time1, &y));
if (y != x) {
fprintf(stderr, "UTCTIME length failed to match for rsa_time1: %lu, %lu\n", x, y);
return 1;
@@ -327,7 +774,7 @@ tmp_time.off_hh);
}
x = sizeof(buf[0]);
- DO(der_encode_utctime(&rsa_time2, buf[0], &x));
+ DO(der_encode_utctime((ltc_utctime*)&rsa_time2, buf[0], &x));
if (x != sizeof(rsa_time2_der) || memcmp(buf[0], rsa_time2_der, x)) {
fprintf(stderr, "UTCTIME encode of rsa_time2 failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_time1_der));
fprintf(stderr, "\n\n");
@@ -335,7 +782,7 @@ for (y = 0; y < x; y++) fprintf(stderr, "%02x ", buf[0][y]); printf("\n");
return 1;
}
- DO(der_length_utctime(&rsa_time2, &y));
+ DO(der_length_utctime((ltc_utctime*)&rsa_time2, &y));
if (y != x) {
fprintf(stderr, "UTCTIME length failed to match for rsa_time2: %lu, %lu\n", x, y);
return 1;
@@ -358,13 +805,49 @@ tmp_time.off_hh);
return 1;
}
-
-
+ /* UTF 8 */
+ /* encode it */
+ x = sizeof(utf8_buf);
+ DO(der_encode_utf8_string(utf8_1, sizeof(utf8_1) / sizeof(utf8_1[0]), utf8_buf, &x));
+ if (x != sizeof(utf8_1_der) || memcmp(utf8_buf, utf8_1_der, x)) {
+ fprintf(stderr, "DER UTF8_1 encoded to %lu bytes\n", x);
+ for (y = 0; y < x; y++) fprintf(stderr, "%02x ", (unsigned)utf8_buf[y]); fprintf(stderr, "\n");
+ return 1;
+ }
+ /* decode it */
+ y = sizeof(utf8_out) / sizeof(utf8_out[0]);
+ DO(der_decode_utf8_string(utf8_buf, x, utf8_out, &y));
+ if (y != (sizeof(utf8_1) / sizeof(utf8_1[0])) || memcmp(utf8_1, utf8_out, y * sizeof(wchar_t))) {
+ fprintf(stderr, "DER UTF8_1 decoded to %lu wchar_t\n", y);
+ for (x = 0; x < y; x++) fprintf(stderr, "%04lx ", (unsigned long)utf8_out[x]); fprintf(stderr, "\n");
+ return 1;
+ }
+
+ /* encode it */
+ x = sizeof(utf8_buf);
+ DO(der_encode_utf8_string(utf8_2, sizeof(utf8_2) / sizeof(utf8_2[0]), utf8_buf, &x));
+ if (x != sizeof(utf8_2_der) || memcmp(utf8_buf, utf8_2_der, x)) {
+ fprintf(stderr, "DER UTF8_2 encoded to %lu bytes\n", x);
+ for (y = 0; y < x; y++) fprintf(stderr, "%02x ", (unsigned)utf8_buf[y]); fprintf(stderr, "\n");
+ return 1;
+ }
+ /* decode it */
+ y = sizeof(utf8_out) / sizeof(utf8_out[0]);
+ DO(der_decode_utf8_string(utf8_buf, x, utf8_out, &y));
+ if (y != (sizeof(utf8_2) / sizeof(utf8_2[0])) || memcmp(utf8_2, utf8_out, y * sizeof(wchar_t))) {
+ fprintf(stderr, "DER UTF8_2 decoded to %lu wchar_t\n", y);
+ for (x = 0; x < y; x++) fprintf(stderr, "%04lx ", (unsigned long)utf8_out[x]); fprintf(stderr, "\n");
+ return 1;
+ }
+
+
+ der_set_test();
+ der_flexi_test();
return der_choice_test();
}
#endif
/* $Source: /cvs/libtom/libtomcrypt/testprof/der_tests.c,v $ */
-/* $Revision: 1.25 $ */
-/* $Date: 2005/06/20 20:37:45 $ */
+/* $Revision: 1.49 $ */
+/* $Date: 2006/11/26 02:10:21 $ */
diff --git a/testprof/dh_tests.c b/testprof/dh_tests.c
deleted file mode 100644
index 3852e47..0000000
--- a/testprof/dh_tests.c
+++ /dev/null
@@ -1,103 +0,0 @@
-#include <tomcrypt_test.h>
-
-#ifdef MDH
-
-int dh_tests (void)
-{
- unsigned char buf[3][4096];
- unsigned long x, y, z;
- int stat, stat2;
- dh_key usera, userb;
-
- DO(dh_test());
-
- /* make up two keys */
- DO(dh_make_key (&yarrow_prng, find_prng ("yarrow"), 512, &usera));
- DO(dh_make_key (&yarrow_prng, find_prng ("yarrow"), 512, &userb));
-
- /* make the shared secret */
- x = 4096;
- DO(dh_shared_secret (&usera, &userb, buf[0], &x));
-
- y = 4096;
- DO(dh_shared_secret (&userb, &usera, buf[1], &y));
- if (y != x) {
- fprintf(stderr, "DH Shared keys are not same size.\n");
- return 1;
- }
- if (memcmp (buf[0], buf[1], x)) {
- fprintf(stderr, "DH Shared keys not same contents.\n");
- return 1;
- }
-
- /* now export userb */
- y = 4096;
- DO(dh_export (buf[1], &y, PK_PUBLIC, &userb));
- dh_free (&userb);
-
- /* import and make the shared secret again */
- DO(dh_import (buf[1], y, &userb));
- z = 4096;
- DO(dh_shared_secret (&usera, &userb, buf[2], &z));
-
- if (z != x) {
- fprintf(stderr, "failed. Size don't match?\n");
- return 1;
- }
- if (memcmp (buf[0], buf[2], x)) {
- fprintf(stderr, "Failed. Content didn't match.\n");
- return 1;
- }
- dh_free (&usera);
- dh_free (&userb);
-
-/* test encrypt_key */
- dh_make_key (&yarrow_prng, find_prng ("yarrow"), 512, &usera);
- for (x = 0; x < 16; x++) {
- buf[0][x] = x;
- }
- y = sizeof (buf[1]);
- DO(dh_encrypt_key (buf[0], 16, buf[1], &y, &yarrow_prng, find_prng ("yarrow"), find_hash ("md5"), &usera));
- zeromem (buf[0], sizeof (buf[0]));
- x = sizeof (buf[0]);
- DO(dh_decrypt_key (buf[1], y, buf[0], &x, &usera));
- if (x != 16) {
- fprintf(stderr, "Failed (length)\n");
- return 1;
- }
- for (x = 0; x < 16; x++)
- if (buf[0][x] != x) {
- fprintf(stderr, "Failed (contents)\n");
- return 1;
- }
-
-/* test sign_hash */
- for (x = 0; x < 16; x++) {
- buf[0][x] = x;
- }
- x = sizeof (buf[1]);
- DO(dh_sign_hash (buf[0], 16, buf[1], &x, &yarrow_prng , find_prng ("yarrow"), &usera));
- DO(dh_verify_hash (buf[1], x, buf[0], 16, &stat, &usera));
- buf[0][0] ^= 1;
- DO(dh_verify_hash (buf[1], x, buf[0], 16, &stat2, &usera));
- if (!(stat == 1 && stat2 == 0)) {
- fprintf(stderr, "dh_sign/verify_hash %d %d", stat, stat2);
- return 1;
- }
- dh_free (&usera);
- return 0;
-}
-
-#else
-
-int dh_tests(void)
-{
- fprintf(stderr, "NOP");
- return 0;
-}
-
-#endif
-
-/* $Source: /cvs/libtom/libtomcrypt/testprof/dh_tests.c,v $ */
-/* $Revision: 1.5 $ */
-/* $Date: 2005/05/21 12:51:25 $ */
diff --git a/testprof/dsa_test.c b/testprof/dsa_test.c
index aa4988c..f623092 100644
--- a/testprof/dsa_test.c
+++ b/testprof/dsa_test.c
@@ -5,7 +5,7 @@
int dsa_test(void)
{
unsigned char msg[16], out[1024], out2[1024];
- unsigned long x;
+ unsigned long x, y;
int stat1, stat2;
dsa_key key, key2;
@@ -15,6 +15,20 @@ int dsa_test(void)
/* verify it */
DO(dsa_verify_key(&key, &stat1));
if (stat1 == 0) { fprintf(stderr, "dsa_verify_key "); return 1; }
+
+ /* encrypt a message */
+ for (x = 0; x < 16; x++) { msg[x] = x; }
+ x = sizeof(out);
+ DO(dsa_encrypt_key(msg, 16, out, &x, &yarrow_prng, find_prng("yarrow"), find_hash("sha1"), &key));
+
+ /* decrypt */
+ y = sizeof(out2);
+ DO(dsa_decrypt_key(out, x, out2, &y, &key));
+
+ if (y != 16 || memcmp(out2, msg, 16)) {
+ fprintf(stderr, "dsa_decrypt failed, y == %lu\n", y);
+ return 1;
+ }
/* sign the message */
x = sizeof(out);
@@ -64,5 +78,5 @@ int dsa_test(void)
#endif
/* $Source: /cvs/libtom/libtomcrypt/testprof/dsa_test.c,v $ */
-/* $Revision: 1.8 $ */
-/* $Date: 2005/06/03 19:24:32 $ */
+/* $Revision: 1.9 $ */
+/* $Date: 2005/10/30 18:49:14 $ */
diff --git a/testprof/ecc_test.c b/testprof/ecc_test.c
index d5f88ab..ccfabe2 100644
--- a/testprof/ecc_test.c
+++ b/testprof/ecc_test.c
@@ -3,6 +3,15 @@
#ifdef MECC
static int sizes[] = {
+#ifdef ECC112
+14,
+#endif
+#ifdef ECC128
+16,
+#endif
+#ifdef ECC160
+20,
+#endif
#ifdef ECC192
24,
#endif
@@ -15,11 +24,87 @@ static int sizes[] = {
#ifdef ECC384
48,
#endif
-#ifdef ECC512
+#ifdef ECC521
65
#endif
};
+#ifdef LTC_ECC_SHAMIR
+int ecc_test_shamir(void)
+{
+ void *modulus, *mp, *kA, *kB, *rA, *rB;
+ ecc_point *G, *A, *B, *C1, *C2;
+ int x, y, z;
+ unsigned char buf[ECC_BUF_SIZE];
+
+ DO(mp_init_multi(&kA, &kB, &rA, &rB, &modulus, NULL));
+ LTC_ARGCHK((G = ltc_ecc_new_point()) != NULL);
+ LTC_ARGCHK((A = ltc_ecc_new_point()) != NULL);
+ LTC_ARGCHK((B = ltc_ecc_new_point()) != NULL);
+ LTC_ARGCHK((C1 = ltc_ecc_new_point()) != NULL);
+ LTC_ARGCHK((C2 = ltc_ecc_new_point()) != NULL);
+
+ for (x = 0; x < (int)(sizeof(sizes)/sizeof(sizes[0])); x++) {
+ /* get the base point */
+ for (z = 0; ltc_ecc_sets[z].name; z++) {
+ if (sizes[z] < ltc_ecc_sets[z].size) break;
+ }
+ LTC_ARGCHK(ltc_ecc_sets[z].name != NULL);
+
+ /* load it */
+ DO(mp_read_radix(G->x, ltc_ecc_sets[z].Gx, 16));
+ DO(mp_read_radix(G->y, ltc_ecc_sets[z].Gy, 16));
+ DO(mp_set(G->z, 1));
+ DO(mp_read_radix(modulus, ltc_ecc_sets[z].prime, 16));
+ DO(mp_montgomery_setup(modulus, &mp));
+
+ /* do 100 random tests */
+ for (y = 0; y < 100; y++) {
+ /* pick a random r1, r2 */
+ LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
+ DO(mp_read_unsigned_bin(rA, buf, sizes[x]));
+ LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
+ DO(mp_read_unsigned_bin(rB, buf, sizes[x]));
+
+ /* compute rA * G = A */
+ DO(ltc_mp.ecc_ptmul(rA, G, A, modulus, 1));
+
+ /* compute rB * G = B */
+ DO(ltc_mp.ecc_ptmul(rB, G, B, modulus, 1));
+
+ /* pick a random kA, kB */
+ LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
+ DO(mp_read_unsigned_bin(kA, buf, sizes[x]));
+ LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
+ DO(mp_read_unsigned_bin(kB, buf, sizes[x]));
+
+ /* now, compute kA*A + kB*B = C1 using the older method */
+ DO(ltc_mp.ecc_ptmul(kA, A, C1, modulus, 0));
+ DO(ltc_mp.ecc_ptmul(kB, B, C2, modulus, 0));
+ DO(ltc_mp.ecc_ptadd(C1, C2, C1, modulus, mp));
+ DO(ltc_mp.ecc_map(C1, modulus, mp));
+
+ /* now compute using mul2add */
+ DO(ltc_mp.ecc_mul2add(A, kA, B, kB, C2, modulus));
+
+ /* is they the sames? */
+ if ((mp_cmp(C1->x, C2->x) != LTC_MP_EQ) || (mp_cmp(C1->y, C2->y) != LTC_MP_EQ) || (mp_cmp(C1->z, C2->z) != LTC_MP_EQ)) {
+ fprintf(stderr, "ECC failed shamir test: size=%d, testno=%d\n", sizes[x], y);
+ return 1;
+ }
+ }
+ mp_montgomery_free(mp);
+ }
+ ltc_ecc_del_point(C2);
+ ltc_ecc_del_point(C1);
+ ltc_ecc_del_point(B);
+ ltc_ecc_del_point(A);
+ ltc_ecc_del_point(G);
+ mp_clear_multi(kA, kB, rA, rB, modulus, NULL);
+ return 0;
+}
+#endif
+
int ecc_tests (void)
{
unsigned char buf[4][4096];
@@ -28,17 +113,21 @@ int ecc_tests (void)
ecc_key usera, userb, pubKey, privKey;
DO(ecc_test ());
+ DO(ecc_test ());
+ DO(ecc_test ());
+ DO(ecc_test ());
+ DO(ecc_test ());
- for (s = 0; s < (int)(sizeof(sizes)/sizeof(sizes[0])); s++) {
+ for (s = 0; s < (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;
+ x = sizeof(buf[0]);
DO(ecc_shared_secret (&usera, &userb, buf[0], &x));
- y = 4096;
+ y = sizeof(buf[1]);
DO(ecc_shared_secret (&userb, &usera, buf[1], &y));
if (y != x) {
@@ -52,14 +141,14 @@ int ecc_tests (void)
}
/* now export userb */
- y = 4096;
+ y = sizeof(buf[0]);
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;
+ z = sizeof(buf[0]);
DO(ecc_shared_secret (&usera, &userb, buf[2], &z));
if (z != x) {
@@ -70,6 +159,28 @@ int ecc_tests (void)
fprintf(stderr, "Failed. Contents didn't match.");
return 1;
}
+
+ /* export with ANSI X9.63 */
+ y = sizeof(buf[1]);
+ DO(ecc_ansi_x963_export(&userb, buf[1], &y));
+ ecc_free (&userb);
+
+ /* now import the ANSI key */
+ DO(ecc_ansi_x963_import(buf[1], y, &userb));
+
+ /* shared secret */
+ z = sizeof(buf[0]);
+ 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. Contents didn't match.");
+ return 1;
+ }
+
ecc_free (&usera);
ecc_free (&userb);
@@ -119,7 +230,11 @@ int ecc_tests (void)
ecc_free (&pubKey);
ecc_free (&privKey);
}
+#ifdef LTC_ECC_SHAMIR
+ return ecc_test_shamir();
+#else
return 0;
+#endif
}
#else
@@ -133,5 +248,5 @@ int ecc_tests(void)
#endif
/* $Source: /cvs/libtom/libtomcrypt/testprof/ecc_test.c,v $ */
-/* $Revision: 1.9 $ */
-/* $Date: 2005/06/14 19:43:29 $ */
+/* $Revision: 1.21 $ */
+/* $Date: 2006/12/04 03:21:03 $ */
diff --git a/testprof/katja_test.c b/testprof/katja_test.c
new file mode 100644
index 0000000..47d01fe
--- /dev/null
+++ b/testprof/katja_test.c
@@ -0,0 +1,231 @@
+#include <tomcrypt_test.h>
+
+#ifdef MKAT
+
+int katja_test(void)
+{
+ unsigned char in[1024], out[1024], tmp[1024];
+ katja_key key, privKey, pubKey;
+ int hash_idx, prng_idx, stat, stat2, size;
+ unsigned long kat_msgsize, len, len2, cnt;
+ static unsigned char lparam[] = { 0x01, 0x02, 0x03, 0x04 };
+
+ hash_idx = find_hash("sha1");
+ prng_idx = find_prng("yarrow");
+ if (hash_idx == -1 || prng_idx == -1) {
+ fprintf(stderr, "katja_test requires SHA1 and yarrow");
+ return 1;
+ }
+
+for (size = 1024; size <= 2048; size += 256) {
+
+ /* make 10 random key */
+ for (cnt = 0; cnt < 10; cnt++) {
+ DO(katja_make_key(&yarrow_prng, prng_idx, size/8, &key));
+ if (mp_count_bits(key.N) < size - 7) {
+ fprintf(stderr, "katja_%d key modulus has %d bits\n", size, mp_count_bits(key.N));
+
+len = mp_unsigned_bin_size(key.N);
+mp_to_unsigned_bin(key.N, tmp);
+ fprintf(stderr, "N == \n");
+for (cnt = 0; cnt < len; ) {
+ 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);
+ fprintf(stderr, "p == \n");
+for (cnt = 0; cnt < len; ) {
+ 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);
+ fprintf(stderr, "\nq == \n");
+for (cnt = 0; cnt < len; ) {
+ fprintf(stderr, "%02x ", tmp[cnt]);
+ if (!(++cnt & 15)) fprintf(stderr, "\n");
+}
+ fprintf(stderr, "\n");
+
+
+ return 1;
+ }
+ if (cnt != 9) {
+ katja_free(&key);
+ }
+ }
+ /* encrypt the key (without lparam) */
+ for (cnt = 0; cnt < 4; cnt++) {
+ for (kat_msgsize = 1; kat_msgsize <= 42; kat_msgsize++) {
+ /* make a random key/msg */
+ yarrow_read(in, kat_msgsize, &yarrow_prng);
+
+ len = sizeof(out);
+ len2 = kat_msgsize;
+
+ DO(katja_encrypt_key(in, kat_msgsize, out, &len, NULL, 0, &yarrow_prng, prng_idx, hash_idx, &key));
+ /* change a byte */
+ out[8] ^= 1;
+ DO(katja_decrypt_key(out, len, tmp, &len2, NULL, 0, hash_idx, &stat2, &key));
+ /* change a byte back */
+ out[8] ^= 1;
+ if (len2 != kat_msgsize) {
+ fprintf(stderr, "\nkatja_decrypt_key mismatch len %lu (first decrypt)", len2);
+ return 1;
+ }
+
+ len2 = kat_msgsize;
+ DO(katja_decrypt_key(out, len, tmp, &len2, NULL, 0, hash_idx, &stat, &key));
+ if (!(stat == 1 && stat2 == 0)) {
+ fprintf(stderr, "katja_decrypt_key failed");
+ return 1;
+ }
+ if (len2 != kat_msgsize || memcmp(tmp, in, kat_msgsize)) {
+ unsigned long x;
+ fprintf(stderr, "\nkatja_decrypt_key mismatch, len %lu (second decrypt)\n", len2);
+ fprintf(stderr, "Original contents: \n");
+ for (x = 0; x < kat_msgsize; ) {
+ fprintf(stderr, "%02x ", in[x]);
+ if (!(++x % 16)) {
+ fprintf(stderr, "\n");
+ }
+ }
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Output contents: \n");
+ for (x = 0; x < kat_msgsize; ) {
+ fprintf(stderr, "%02x ", out[x]);
+ if (!(++x % 16)) {
+ fprintf(stderr, "\n");
+ }
+ }
+ fprintf(stderr, "\n");
+ return 1;
+ }
+ }
+ }
+
+ /* encrypt the key (with lparam) */
+ for (kat_msgsize = 1; kat_msgsize <= 42; kat_msgsize++) {
+ len = sizeof(out);
+ len2 = kat_msgsize;
+ DO(katja_encrypt_key(in, kat_msgsize, out, &len, lparam, sizeof(lparam), &yarrow_prng, prng_idx, hash_idx, &key));
+ /* change a byte */
+ out[8] ^= 1;
+ DO(katja_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), hash_idx, &stat2, &key));
+ if (len2 != kat_msgsize) {
+ fprintf(stderr, "\nkatja_decrypt_key mismatch len %lu (first decrypt)", len2);
+ return 1;
+ }
+ /* change a byte back */
+ out[8] ^= 1;
+
+ len2 = kat_msgsize;
+ DO(katja_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), hash_idx, &stat, &key));
+ if (!(stat == 1 && stat2 == 0)) {
+ fprintf(stderr, "katja_decrypt_key failed");
+ return 1;
+ }
+ if (len2 != kat_msgsize || memcmp(tmp, in, kat_msgsize)) {
+ fprintf(stderr, "katja_decrypt_key mismatch len %lu", len2);
+ return 1;
+ }
+ }
+
+#if 0
+
+ /* sign a message (unsalted, lower cholestorol and Atkins approved) now */
+ len = sizeof(out);
+ DO(katja_sign_hash(in, 20, out, &len, &yarrow_prng, prng_idx, hash_idx, 0, &key));
+
+/* export key and import as both private and public */
+ len2 = sizeof(tmp);
+ DO(katja_export(tmp, &len2, PK_PRIVATE, &key));
+ DO(katja_import(tmp, len2, &privKey));
+ len2 = sizeof(tmp);
+ DO(katja_export(tmp, &len2, PK_PUBLIC, &key));
+ DO(katja_import(tmp, len2, &pubKey));
+
+ /* verify with original */
+ DO(katja_verify_hash(out, len, in, 20, hash_idx, 0, &stat, &key));
+ /* change a byte */
+ in[0] ^= 1;
+ DO(katja_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &key));
+
+ if (!(stat == 1 && stat2 == 0)) {
+ fprintf(stderr, "katja_verify_hash (unsalted, origKey) failed, %d, %d", stat, stat2);
+ katja_free(&key);
+ katja_free(&pubKey);
+ katja_free(&privKey);
+ return 1;
+ }
+
+ /* verify with privKey */
+ /* change a byte */
+ in[0] ^= 1;
+ DO(katja_verify_hash(out, len, in, 20, hash_idx, 0, &stat, &privKey));
+ /* change a byte */
+ in[0] ^= 1;
+ DO(katja_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &privKey));
+
+ if (!(stat == 1 && stat2 == 0)) {
+ fprintf(stderr, "katja_verify_hash (unsalted, privKey) failed, %d, %d", stat, stat2);
+ katja_free(&key);
+ katja_free(&pubKey);
+ katja_free(&privKey);
+ return 1;
+ }
+
+ /* verify with pubKey */
+ /* change a byte */
+ in[0] ^= 1;
+ DO(katja_verify_hash(out, len, in, 20, hash_idx, 0, &stat, &pubKey));
+ /* change a byte */
+ in[0] ^= 1;
+ DO(katja_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &pubKey));
+
+ if (!(stat == 1 && stat2 == 0)) {
+ fprintf(stderr, "katja_verify_hash (unsalted, pubkey) failed, %d, %d", stat, stat2);
+ katja_free(&key);
+ katja_free(&pubKey);
+ katja_free(&privKey);
+ return 1;
+ }
+
+ /* sign a message (salted) now (use privKey to make, pubKey to verify) */
+ len = sizeof(out);
+ DO(katja_sign_hash(in, 20, out, &len, &yarrow_prng, prng_idx, hash_idx, 8, &privKey));
+ DO(katja_verify_hash(out, len, in, 20, hash_idx, 8, &stat, &pubKey));
+ /* change a byte */
+ in[0] ^= 1;
+ DO(katja_verify_hash(out, len, in, 20, hash_idx, 8, &stat2, &pubKey));
+
+ if (!(stat == 1 && stat2 == 0)) {
+ fprintf(stderr, "katja_verify_hash (salted) failed, %d, %d", stat, stat2);
+ katja_free(&key);
+ katja_free(&pubKey);
+ katja_free(&privKey);
+ return 1;
+ }
+#endif
+
+ katja_free(&key);
+ katja_free(&pubKey);
+ katja_free(&privKey);
+}
+
+ /* free the key and return */
+ return 0;
+}
+
+#else
+
+int katja_test(void)
+{
+ fprintf(stderr, "NOP");
+ return 0;
+}
+
+#endif
diff --git a/testprof/mac_test.c b/testprof/mac_test.c
index 3c9e902..410e4b5 100644
--- a/testprof/mac_test.c
+++ b/testprof/mac_test.c
@@ -3,15 +3,21 @@
int mac_test(void)
{
-#ifdef HMAC
+#ifdef LTC_HMAC
DO(hmac_test());
#endif
-#ifdef PMAC
+#ifdef LTC_PMAC
DO(pmac_test());
#endif
-#ifdef OMAC
+#ifdef LTC_OMAC
DO(omac_test());
#endif
+#ifdef LTC_XCBC
+ DO(xcbc_test());
+#endif
+#ifdef LTC_F9_MODE
+ DO(f9_test());
+#endif
#ifdef EAX_MODE
DO(eax_test());
#endif
@@ -31,5 +37,5 @@ int mac_test(void)
}
/* $Source: /cvs/libtom/libtomcrypt/testprof/mac_test.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2005/05/05 14:35:59 $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2006/11/08 21:57:04 $ */
diff --git a/testprof/makefile b/testprof/makefile
index f4be577..4cc70ff 100644
--- a/testprof/makefile
+++ b/testprof/makefile
@@ -1,14 +1,23 @@
CFLAGS += -I../src/headers -I./ -Wall -W
-OBJECTS = base64_test.o cipher_hash_test.o der_tests.o dh_tests.o \
+# ranlib tools
+ifndef RANLIB
+ RANLIB=ranlib
+endif
+
+OBJECTS = base64_test.o cipher_hash_test.o der_tests.o \
dsa_test.o ecc_test.o mac_test.o modes_test.o pkcs_1_test.o rsa_test.o \
-store_test.o test.o x86_prof.o
+store_test.o test_driver.o x86_prof.o katja_test.o
+
+ifndef LIBTEST_S
+ LIBTEST_S=libtomcrypt_prof.a
+endif
-default: libtomcrypt_prof.a
+default: $(LIBTEST_S)
-libtomcrypt_prof.a: $(OBJECTS)
- $(AR) $(ARFLAGS) libtomcrypt_prof.a $(OBJECTS)
- ranlib libtomcrypt_prof.a
+$(LIBTEST_S): $(OBJECTS)
+ $(AR) $(ARFLAGS) $@ $(OBJECTS)
+ $(RANLIB) $@
clean:
rm -f *.o *.a
diff --git a/testprof/makefile.icc b/testprof/makefile.icc
index ff87660..60628ce 100644
--- a/testprof/makefile.icc
+++ b/testprof/makefile.icc
@@ -1,14 +1,19 @@
CFLAGS += -I../src/headers -I./
CC=icc
-OBJECTS = base64_test.o cipher_hash_test.o der_tests.o dh_tests.o \
+OBJECTS = base64_test.o cipher_hash_test.o der_tests.o \
dsa_test.o ecc_test.o mac_test.o modes_test.o pkcs_1_test.o rsa_test.o \
-store_test.o test.o x86_prof.o
+store_test.o test_driver.o x86_prof.o katja_test.o
-default: libtomcrypt_prof.a
+ifndef LIBTEST_S
+ LIBTEST_S = libtomcrypt_prof.a
+endif
-libtomcrypt_prof.a: $(OBJECTS)
- $(AR) $(ARFLAGS) libtomcrypt_prof.a $(OBJECTS)
+default: $(LIBTEST_S)
+
+$(LIBTEST_S): $(OBJECTS)
+ $(AR) $(ARFLAGS) $@ $(OBJECTS)
+ ranlib $@
clean:
rm -f *.o *.a
diff --git a/testprof/makefile.msvc b/testprof/makefile.msvc
index 6e15ffb..d330f93 100644
--- a/testprof/makefile.msvc
+++ b/testprof/makefile.msvc
@@ -1,8 +1,8 @@
-CFLAGS = /I../src/headers/ /I./ /Ox /DWIN32 /W3 /Fo$@
+CFLAGS = /I../src/headers/ /I./ /Ox /DWIN32 /DLTC_SOURCE /W3 /Fo$@
-OBJECTS=base64_test.obj cipher_hash_test.obj der_tests.obj dh_tests.obj \
+OBJECTS=base64_test.obj cipher_hash_test.obj der_tests.obj \
dsa_test.obj ecc_test.obj mac_test.obj modes_test.obj pkcs_1_test.obj \
-rsa_test.obj store_test.obj test.obj x86_prof.obj
+rsa_test.obj store_test.obj test_driver.obj x86_prof.obj katja_test.obj
tomcrypt_prof.lib: $(OBJECTS)
lib /out:tomcrypt_prof.lib $(OBJECTS)
diff --git a/testprof/makefile.shared b/testprof/makefile.shared
index b4219f0..b3abba5 100644
--- a/testprof/makefile.shared
+++ b/testprof/makefile.shared
@@ -1,15 +1,24 @@
CC=libtool --mode=compile gcc
-CFLAGS += -I../src/headers -I./ -O3 -fomit-frame-pointer -funroll-loops -Wall -W
+CFLAGS += -I../src/headers -I./ -Wall -W
-OBJECTS = base64_test.o cipher_hash_test.o der_tests.o dh_tests.o \
+# ranlib tools
+ifndef RANLIB
+ RANLIB=ranlib
+endif
+
+OBJECTS = base64_test.o cipher_hash_test.o der_tests.o \
dsa_test.o ecc_test.o mac_test.o modes_test.o pkcs_1_test.o rsa_test.o \
-store_test.o test.o x86_prof.o
+store_test.o test_driver.o x86_prof.o katja_test.o
+
+ifndef LIBTEST
+ LIBTEST=libtomcrypt_prof.la
+endif
+
+default: $(LIBTEST)
-default: $(LIBNAME)
+$(LIBTEST): $(OBJECTS)
+ libtool --silent --mode=link gcc $(CFLAGS) `find . -type f | grep "[.]lo" | xargs` -o $@ -rpath $(LIBPATH) -version-info $(VERSION)
-$(LIBNAME): $(OBJECTS)
- libtool --silent --mode=link gcc $(CFLAGS) `find . -type f | grep "[.]lo" | xargs` -o libtomcrypt_prof.la -rpath $(LIBPATH) -version-info $(VERSION)
- libtool --silent --mode=link gcc $(CFLAGS) `find . -type f | grep "[.]o" | xargs` -o libtomcrypt_prof.a
- ranlib libtomcrypt_prof.a
- libtool --silent --mode=install install -c libtomcrypt_prof.la $(LIBPATH)/libtomcrypt_prof.la
+install: $(LIBTEST)
+ libtool --silent --mode=install install -c $(LIBTEST) $(DESTDIR)$(LIBPATH)/$(LIBTEST)
diff --git a/testprof/modes_test.c b/testprof/modes_test.c
index d394267..8999c0d 100644
--- a/testprof/modes_test.c
+++ b/testprof/modes_test.c
@@ -5,10 +5,15 @@ int modes_test(void)
{
unsigned char pt[64], ct[64], tmp[64], key[16], iv[16], iv2[16];
int cipher_idx;
+#ifdef LTC_CBC_MODE
symmetric_CBC cbc;
+#endif
+#ifdef LTC_CFB_MODE
symmetric_CFB cfb;
+#endif
+#ifdef LTC_OFB_MODE
symmetric_OFB ofb;
- symmetric_CTR ctr;
+#endif
unsigned long l;
/* make a random pt, key and iv */
@@ -23,7 +28,15 @@ int modes_test(void)
return 1;
}
-#ifdef CBC
+#ifdef LTC_F8_MODE
+ DO(f8_test_mode());
+#endif
+
+#ifdef LTC_LRW_MODE
+ DO(lrw_test());
+#endif
+
+#ifdef LTC_CBC_MODE
/* test CBC mode */
/* encode the block */
DO(cbc_start(cipher_idx, iv, key, 16, 0, &cbc));
@@ -45,7 +58,7 @@ int modes_test(void)
}
#endif
-#ifdef CFB
+#ifdef LTC_CFB_MODE
/* test CFB mode */
/* encode the block */
DO(cfb_start(cipher_idx, iv, key, 16, 0, &cfb));
@@ -68,7 +81,7 @@ int modes_test(void)
}
#endif
-#ifdef OFB
+#ifdef LTC_OFB_MODE
/* test OFB mode */
/* encode the block */
DO(ofb_start(cipher_idx, iv, key, 16, 0, &ofb));
@@ -90,31 +103,13 @@ int modes_test(void)
}
#endif
-#ifdef CTR
- /* test CTR mode */
- /* encode the block */
- 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)) {
- fprintf(stderr, "ctr_getiv failed");
- return 1;
- }
- DO(ctr_encrypt(pt, ct, 57, &ctr));
-
- /* decode the block */
- DO(ctr_setiv(iv2, l, &ctr));
- zeromem(tmp, sizeof(tmp));
- DO(ctr_decrypt(ct, tmp, 57, &ctr));
- if (memcmp(tmp, pt, 57) != 0) {
- fprintf(stderr, "CTR failed");
- return 1;
- }
+#ifdef LTC_CTR_MODE
+ DO(ctr_test());
#endif
return 0;
}
/* $Source: /cvs/libtom/libtomcrypt/testprof/modes_test.c,v $ */
-/* $Revision: 1.6 $ */
-/* $Date: 2005/05/21 12:51:25 $ */
+/* $Revision: 1.14 $ */
+/* $Date: 2006/11/13 11:55:25 $ */
diff --git a/testprof/pkcs_1_test.c b/testprof/pkcs_1_test.c
index 1a47d85..da725fc 100644
--- a/testprof/pkcs_1_test.c
+++ b/testprof/pkcs_1_test.c
@@ -5,7 +5,7 @@
int pkcs_1_test(void)
{
unsigned char buf[3][128];
- int res1, res2, res3, prng_idx, hash_idx;
+ int res1, res2, res3, prng_idx, hash_idx, err;
unsigned long x, y, l1, l2, l3, i1, i2, lparamlen, saltlen, modlen;
static const unsigned char lparam[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 };
@@ -18,6 +18,7 @@ int pkcs_1_test(void)
return 1;
}
+ srand(time(NULL));
/* do many tests */
for (x = 0; x < 100; x++) {
zeromem(buf, sizeof(buf));
@@ -26,9 +27,6 @@ int pkcs_1_test(void)
l3 = (rand() & 31) + 8;
for (y = 0; y < l3; y++) buf[0][y] = rand() & 255;
- /* random modulus len (v1.5 must be multiple of 8 though arbitrary sizes seem to work) */
- modlen = 800 + 8 * (abs(rand()) % 28);
-
/* pick a random lparam len [0..16] */
lparamlen = abs(rand()) % 17;
@@ -69,9 +67,8 @@ int pkcs_1_test(void)
DO(pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res2));
buf[0][i1] ^= 1;
- buf[1][i2 = abs(rand()) % l1] ^= 1;
- DO(pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res3));
-
+ buf[1][i2 = abs(rand()) % (l1 - 1)] ^= 1;
+ pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res3);
if (!(res1 == 1 && res2 == 0 && res3 == 0)) {
fprintf(stderr, "PSS failed: %d, %d, %d, %lu, %lu\n", res1, res2, res3, l3, saltlen);
return 1;
@@ -92,5 +89,5 @@ int pkcs_1_test(void)
/* $Source: /cvs/libtom/libtomcrypt/testprof/pkcs_1_test.c,v $ */
-/* $Revision: 1.6 $ */
-/* $Date: 2005/05/21 12:51:25 $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2006/11/30 03:30:45 $ */
diff --git a/testprof/rsa_test.c b/testprof/rsa_test.c
index 4facdcd..4868d6b 100644
--- a/testprof/rsa_test.c
+++ b/testprof/rsa_test.c
@@ -47,8 +47,22 @@ static const unsigned char openssl_private_rsa[] = {
0x4a, 0x9f, };
-/*** NOTE: OpenSSL seems to have more to their public key format. I've stripped the extra headers... */
+/*** openssl public RSA key in DER format */
static const unsigned char openssl_public_rsa[] = {
+ 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
+ 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 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, };
+
+/* same key but with extra headers stripped */
+static const unsigned char openssl_public_rsa_stripped[] = {
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,
@@ -73,33 +87,34 @@ static int rsa_compat_test(void)
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");
-
+ fprintf(stderr, "RSA private export failed to match OpenSSL output, %lu, %lu\n", len, (unsigned long)sizeof(openssl_private_rsa));
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)) {
+ if (len != sizeof(openssl_public_rsa_stripped) || memcmp(buf, openssl_public_rsa_stripped, 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_stripped, sizeof(openssl_public_rsa_stripped), &key));
+ len = sizeof(buf);
+ DO(rsa_export(buf, &len, PK_PUBLIC, &key));
+ if (len != sizeof(openssl_public_rsa_stripped) || memcmp(buf, openssl_public_rsa_stripped, len)) {
+ fprintf(stderr, "RSA(public) stripped public import 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");
+ if (len != sizeof(openssl_public_rsa_stripped) || memcmp(buf, openssl_public_rsa_stripped, len)) {
+ fprintf(stderr, "RSA(public) SSL public import failed to match OpenSSL output\n");
return 1;
}
rsa_free(&key);
@@ -129,27 +144,27 @@ int rsa_test(void)
/* make 10 random key */
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) {
- fprintf(stderr, "rsa_1024 key modulus has %d bits\n", mp_count_bits(&key.N));
+ if (mp_count_bits(key.N) != 1024) {
+ 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);
+len = mp_unsigned_bin_size(key.N);
+mp_to_unsigned_bin(key.N, tmp);
fprintf(stderr, "N == \n");
for (cnt = 0; cnt < len; ) {
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);
+len = mp_unsigned_bin_size(key.p);
+mp_to_unsigned_bin(key.p, tmp);
fprintf(stderr, "p == \n");
for (cnt = 0; cnt < len; ) {
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);
+len = mp_unsigned_bin_size(key.q);
+mp_to_unsigned_bin(key.q, tmp);
fprintf(stderr, "\nq == \n");
for (cnt = 0; cnt < len; ) {
fprintf(stderr, "%02x ", tmp[cnt]);
@@ -242,6 +257,24 @@ for (cnt = 0; cnt < len; ) {
}
}
+ /* encrypt the key PKCS #1 v1.5 (payload from 1 to 117 bytes) */
+ for (rsa_msgsize = 1; rsa_msgsize <= 117; rsa_msgsize++) {
+ len = sizeof(out);
+ len2 = rsa_msgsize;
+ DO(rsa_encrypt_key_ex(in, rsa_msgsize, out, &len, NULL, 0, &yarrow_prng, prng_idx, 0, LTC_PKCS_1_V1_5, &key));
+
+ len2 = rsa_msgsize;
+ DO(rsa_decrypt_key_ex(out, len, tmp, &len2, NULL, 0, 0, LTC_PKCS_1_V1_5, &stat, &key));
+ if (!(stat == 1 && stat2 == 0)) {
+ fprintf(stderr, "rsa_decrypt_key_ex failed, %d, %d", stat, stat2);
+ return 1;
+ }
+ if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) {
+ fprintf(stderr, "rsa_decrypt_key_ex mismatch len %lu", len2);
+ return 1;
+ }
+ }
+
/* sign a message (unsalted, lower cholestorol and Atkins approved) now */
len = sizeof(out);
DO(rsa_sign_hash(in, 20, out, &len, &yarrow_prng, prng_idx, hash_idx, 0, &key));
@@ -316,6 +349,22 @@ for (cnt = 0; cnt < len; ) {
return 1;
}
+ /* sign a message with PKCS #1 v1.5 */
+ len = sizeof(out);
+ DO(rsa_sign_hash_ex(in, 20, out, &len, LTC_PKCS_1_V1_5, &yarrow_prng, prng_idx, hash_idx, 8, &privKey));
+ DO(rsa_verify_hash_ex(out, len, in, 20, LTC_PKCS_1_V1_5, hash_idx, 8, &stat, &pubKey));
+ /* change a byte */
+ in[0] ^= 1;
+ DO(rsa_verify_hash_ex(out, len, in, 20, LTC_PKCS_1_V1_5, hash_idx, 8, &stat2, &pubKey));
+
+ if (!(stat == 1 && stat2 == 0)) {
+ fprintf(stderr, "rsa_verify_hash_ex failed, %d, %d", stat, stat2);
+ rsa_free(&key);
+ rsa_free(&pubKey);
+ rsa_free(&privKey);
+ return 1;
+ }
+
/* free the key and return */
rsa_free(&key);
rsa_free(&pubKey);
@@ -334,5 +383,5 @@ int rsa_test(void)
#endif
/* $Source: /cvs/libtom/libtomcrypt/testprof/rsa_test.c,v $ */
-/* $Revision: 1.10 $ */
-/* $Date: 2005/06/03 19:18:33 $ */
+/* $Revision: 1.18 $ */
+/* $Date: 2006/11/21 00:10:18 $ */
diff --git a/testprof/test.der b/testprof/test.der
new file mode 100644
index 0000000..d7041f9
--- /dev/null
+++ b/testprof/test.der
Binary files differ
diff --git a/testprof/test.c b/testprof/test_driver.c
index 5a38421..25740a0 100644
--- a/testprof/test.c
+++ b/testprof/test_driver.c
@@ -4,10 +4,12 @@ void run_cmd(int res, int line, char *file, char *cmd)
{
if (res != CRYPT_OK) {
fprintf(stderr, "%s (%d)\n%s:%d:%s\n", error_to_string(res), res, file, line, cmd);
- exit(EXIT_FAILURE);
+ if (res != CRYPT_NOP) {
+ exit(EXIT_FAILURE);
+ }
}
}
-/* $Source: /cvs/libtom/libtomcrypt/testprof/test.c,v $ */
-/* $Revision: 1.6 $ */
-/* $Date: 2005/05/05 14:35:59 $ */
+/* $Source: /cvs/libtom/libtomcrypt/testprof/test_driver.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2006/11/13 23:14:33 $ */
diff --git a/testprof/tomcrypt_test.h b/testprof/tomcrypt_test.h
index 2c66bad..b4396fb 100644
--- a/testprof/tomcrypt_test.h
+++ b/testprof/tomcrypt_test.h
@@ -5,7 +5,7 @@
#include <tomcrypt.h>
/* enable stack testing */
-// #define STACK_TEST
+/* #define STACK_TEST */
/* stack testing, define this if stack usage goes downwards [e.g. x86] */
#define STACK_DOWN
@@ -18,7 +18,12 @@ typedef struct {
extern prng_state yarrow_prng;
void run_cmd(int res, int line, char *file, char *cmd);
-#define DO(x) { run_cmd((x), __LINE__, __FILE__, #x); }
+
+#ifdef LTC_VERBOSE
+#define DO(x) do { fprintf(stderr, "%s:\n", #x); run_cmd((x), __LINE__, __FILE__, #x); } while (0);
+#else
+#define DO(x) do { run_cmd((x), __LINE__, __FILE__, #x); } while (0);
+#endif
/* TESTS */
int cipher_hash_test(void);
@@ -27,9 +32,9 @@ int mac_test(void);
int pkcs_1_test(void);
int store_test(void);
int rsa_test(void);
+int katja_test(void);
int ecc_tests(void);
int dsa_test(void);
-int dh_tests(void);
int der_tests(void);
/* timing */
@@ -62,8 +67,9 @@ void time_mult(void);
void time_sqr(void);
void time_prng(void);
void time_rsa(void);
+void time_dsa(void);
+void time_katja(void);
void time_ecc(void);
-void time_dh(void);
void time_macs_(unsigned long MAC_SIZE);
void time_macs(void);
void time_encmacs(void);
@@ -73,5 +79,5 @@ void time_encmacs(void);
#endif
/* $Source: /cvs/libtom/libtomcrypt/testprof/tomcrypt_test.h,v $ */
-/* $Revision: 1.8 $ */
-/* $Date: 2005/05/05 14:35:59 $ */
+/* $Revision: 1.14 $ */
+/* $Date: 2006/10/18 03:36:34 $ */
diff --git a/testprof/x86_prof.c b/testprof/x86_prof.c
index 997180c..96667a2 100644
--- a/testprof/x86_prof.c
+++ b/testprof/x86_prof.c
@@ -18,7 +18,7 @@ void tally_results(int type)
{
int x;
- // qsort the results
+ /* qsort the results */
qsort(results, no_results, sizeof(struct list), &sorter);
fprintf(stderr, "\n");
@@ -51,17 +51,31 @@ ulong64 rdtsc (void)
ulong64 a;
asm __volatile__ ("rdtsc\nmovl %%eax,(%0)\nmovl %%edx,4(%0)\n"::"r"(&a):"%eax","%edx");
return a;
+ #elif defined(LTC_PPC32) || defined(TFM_PPC32)
+ unsigned long a, b;
+ __asm__ __volatile__ ("mftbu %1 \nmftb %0\n":"=r"(a), "=r"(b));
+ return (((ulong64)b) << 32ULL) | ((ulong64)a);
#elif defined(__ia64__) /* gcc-IA64 version */
unsigned long result;
__asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
while (__builtin_expect ((int) result == -1, 0))
__asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
return result;
+ #elif defined(__sparc__)
+ #if defined(__arch64__)
+ ulong64 a;
+ asm volatile("rd %%tick,%0" : "=r" (a));
+ return a;
+ #else
+ register unsigned long x, y;
+ __asm__ __volatile__ ("rd %%tick, %0; clruw %0, %1; srlx %0, 32, %0" : "=r" (x), "=r" (y) : "0" (x), "1" (y));
+ return ((unsigned long long) x << 32) | y;
+ #endif
#else
return XCLOCK();
#endif
- // Microsoft and Intel Windows compilers
+ /* Microsoft and Intel Windows compilers */
#elif defined _M_IX86 && !defined(LTC_NO_ASM)
__asm rdtsc
#elif defined _M_AMD64 && !defined(LTC_NO_ASM)
@@ -159,6 +173,12 @@ void reg_algs(void)
#ifdef ANUBIS
register_cipher (&anubis_desc);
#endif
+#ifdef KSEED
+ register_cipher (&kseed_desc);
+#endif
+#ifdef LTC_KASUMI
+ register_cipher (&kasumi_desc);
+#endif
#ifdef TIGER
register_hash (&tiger_desc);
@@ -193,6 +213,12 @@ void reg_algs(void)
#ifdef RIPEMD160
register_hash (&rmd160_desc);
#endif
+#ifdef RIPEMD256
+ register_hash (&rmd256_desc);
+#endif
+#ifdef RIPEMD320
+ register_hash (&rmd320_desc);
+#endif
#ifdef WHIRLPOOL
register_hash (&whirlpool_desc);
#endif
@@ -219,7 +245,11 @@ register_prng(&rc4_desc);
register_prng(&sober128_desc);
#endif
-rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL);
+ if ((err = rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL)) != CRYPT_OK) {
+ fprintf(stderr, "rng_make_prng failed: %s\n", error_to_string(err));
+ exit(EXIT_FAILURE);
+ }
+
}
int time_keysched(void)
@@ -312,6 +342,7 @@ int time_cipher(void)
c2 = (t2 > c2 ? c2 : t2);
}
a2 = c2 - c1 - skew;
+ ecb_done(&ecb);
results[no_results].id = x;
results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length);
@@ -328,7 +359,7 @@ int time_cipher(void)
return 0;
}
-#ifdef CBC
+#ifdef LTC_CBC_MODE
int time_cipher2(void)
{
unsigned long x, y1;
@@ -383,6 +414,7 @@ int time_cipher2(void)
c2 = (t2 > c2 ? c2 : t2);
}
a2 = c2 - c1 - skew;
+ cbc_done(&cbc);
results[no_results].id = x;
results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length);
@@ -402,7 +434,7 @@ int time_cipher2(void)
int time_cipher2(void) { fprintf(stderr, "NO CBC\n"); return 0; }
#endif
-#ifdef CTR
+#ifdef LTC_CTR_MODE
int time_cipher3(void)
{
unsigned long x, y1;
@@ -457,6 +489,7 @@ int time_cipher3(void)
c2 = (t2 > c2 ? c2 : t2);
}
a2 = c2 - c1 - skew;
+ ctr_done(&ctr);
results[no_results].id = x;
results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length);
@@ -476,6 +509,84 @@ int time_cipher3(void)
int time_cipher3(void) { fprintf(stderr, "NO CTR\n"); return 0; }
#endif
+#ifdef LTC_LRW_MODE
+int time_cipher4(void)
+{
+ unsigned long x, y1;
+ ulong64 t1, t2, c1, c2, a1, a2;
+ symmetric_LRW lrw;
+ unsigned char key[MAXBLOCKSIZE], pt[4096];
+ int err;
+
+ fprintf(stderr, "\n\nLRW Time Trials for the Symmetric Ciphers:\n");
+ no_results = 0;
+ for (x = 0; cipher_descriptor[x].name != NULL; x++) {
+ if (cipher_descriptor[x].block_length != 16) continue;
+ lrw_start(x, pt, key, cipher_descriptor[x].min_key_length, key, 0, &lrw);
+
+ /* sanity check on cipher */
+ if ((err = cipher_descriptor[x].test()) != CRYPT_OK) {
+ fprintf(stderr, "\n\nERROR: Cipher %s failed self-test %s\n", cipher_descriptor[x].name, error_to_string(err));
+ exit(EXIT_FAILURE);
+ }
+
+#define DO1 lrw_encrypt(pt, pt, sizeof(pt), &lrw);
+#define DO2 DO1 DO1
+
+ c1 = c2 = (ulong64)-1;
+ for (y1 = 0; y1 < 100; y1++) {
+ t_start();
+ DO1;
+ t1 = t_read();
+ DO2;
+ t2 = t_read();
+ t2 -= t1;
+
+ c1 = (t1 > c1 ? c1 : t1);
+ c2 = (t2 > c2 ? c2 : t2);
+ }
+ a1 = c2 - c1 - skew;
+
+#undef DO1
+#undef DO2
+#define DO1 lrw_decrypt(pt, pt, sizeof(pt), &lrw);
+#define DO2 DO1 DO1
+
+ c1 = c2 = (ulong64)-1;
+ for (y1 = 0; y1 < 100; y1++) {
+ t_start();
+ DO1;
+ t1 = t_read();
+ DO2;
+ t2 = t_read();
+ t2 -= t1;
+
+ c1 = (t1 > c1 ? c1 : t1);
+ c2 = (t2 > c2 ? c2 : t2);
+ }
+ a2 = c2 - c1 - skew;
+
+ lrw_done(&lrw);
+
+ results[no_results].id = x;
+ results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length);
+ 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;
+ fprintf(stderr, "."); fflush(stdout);
+
+#undef DO2
+#undef DO1
+ }
+ tally_results(1);
+
+ return 0;
+}
+#else
+int time_cipher4(void) { fprintf(stderr, "NO LRW\n"); return 0; }
+#endif
+
+
int time_hash(void)
{
unsigned long x, y1, len;
@@ -527,12 +638,15 @@ int time_hash(void)
return 0;
}
+#undef MPI
+/*#warning you need an mp_rand!!!*/
+
#ifdef MPI
void time_mult(void)
{
ulong64 t1, t2;
unsigned long x, y;
- mp_int a, b, c;
+ void *a, *b, *c;
fprintf(stderr, "Timing Multiplying:\n");
mp_init_multi(&a,&b,&c,NULL);
@@ -645,19 +759,64 @@ void time_prng(void)
}
}
+#ifdef MDSA
+/* time various DSA operations */
+void time_dsa(void)
+{
+ dsa_key key;
+ ulong64 t1, t2;
+ unsigned long x, y;
+ int err;
+static const struct {
+ int group, modulus;
+} groups[] = {
+{ 20, 96 },
+{ 20, 128 },
+{ 24, 192 },
+{ 28, 256 },
+{ 32, 512 }
+};
+
+ for (x = 0; x < (sizeof(groups)/sizeof(groups[0])); x++) {
+ t2 = 0;
+ for (y = 0; y < 4; y++) {
+ t_start();
+ t1 = t_read();
+ if ((err = dsa_make_key(&yarrow_prng, find_prng("yarrow"), groups[x].group, groups[x].modulus, &key)) != CRYPT_OK) {
+ fprintf(stderr, "\n\ndsa_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+ exit(EXIT_FAILURE);
+ }
+ t1 = t_read() - t1;
+ t2 += t1;
+
+#ifdef LTC_PROFILE
+ t2 <<= 2;
+ break;
+#endif
+ if (y < 3) {
+ dsa_free(&key);
+ }
+ }
+ t2 >>= 2;
+ fprintf(stderr, "DSA-(%lu, %lu) make_key took %15llu cycles\n", (unsigned long)groups[x].group*8, (unsigned long)groups[x].modulus*8, t2);
+ }
+}
+#endif
+
+
#ifdef MRSA
/* time various RSA operations */
void time_rsa(void)
{
- rsa_key key;
- ulong64 t1, t2;
- unsigned char buf[2][4096];
+ rsa_key key;
+ ulong64 t1, t2;
+ unsigned char buf[2][2048];
unsigned long x, y, z, zzz;
- int err, zz;
+ int err, zz, stat;
- for (x = 1024; x <= 2048; x += 512) {
+ for (x = 1024; x <= 2048; x += 256) {
t2 = 0;
- for (y = 0; y < 16; y++) {
+ for (y = 0; y < 4; y++) {
t_start();
t1 = t_read();
if ((err = rsa_make_key(&yarrow_prng, find_prng("yarrow"), x/8, 65537, &key)) != CRYPT_OK) {
@@ -667,11 +826,16 @@ void time_rsa(void)
t1 = t_read() - t1;
t2 += t1;
- if (y < 15) {
+#ifdef LTC_PROFILE
+ t2 <<= 2;
+ break;
+#endif
+
+ if (y < 3) {
rsa_free(&key);
}
}
- t2 >>= 4;
+ t2 >>= 2;
fprintf(stderr, "RSA-%lu make_key took %15llu cycles\n", x, t2);
t2 = 0;
@@ -679,7 +843,7 @@ void time_rsa(void)
t_start();
t1 = t_read();
z = sizeof(buf[1]);
- if ((err = rsa_encrypt_key(buf[0], 32, buf[1], &z, "testprog", 8, &yarrow_prng,
+ if ((err = rsa_encrypt_key(buf[0], 32, buf[1], &z, (const unsigned char *)"testprog", 8, &yarrow_prng,
find_prng("yarrow"), find_hash("sha1"),
&key)) != CRYPT_OK) {
fprintf(stderr, "\n\nrsa_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
@@ -687,27 +851,76 @@ void time_rsa(void)
}
t1 = t_read() - t1;
t2 += t1;
+#ifdef LTC_PROFILE
+ t2 <<= 4;
+ break;
+#endif
}
t2 >>= 4;
fprintf(stderr, "RSA-%lu encrypt_key took %15llu cycles\n", x, t2);
t2 = 0;
- for (y = 0; y < 16; y++) {
+ for (y = 0; y < 2048; y++) {
t_start();
t1 = t_read();
zzz = sizeof(buf[0]);
- if ((err = rsa_decrypt_key(buf[1], z, buf[0], &zzz, "testprog", 8, find_hash("sha1"),
+ if ((err = rsa_decrypt_key(buf[1], z, buf[0], &zzz, (const unsigned char *)"testprog", 8, find_hash("sha1"),
&zz, &key)) != CRYPT_OK) {
fprintf(stderr, "\n\nrsa_decrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
exit(EXIT_FAILURE);
}
t1 = t_read() - t1;
t2 += t1;
+#ifdef LTC_PROFILE
+ t2 <<= 11;
+ break;
+#endif
}
- t2 >>= 4;
+ t2 >>= 11;
fprintf(stderr, "RSA-%lu decrypt_key took %15llu cycles\n", x, t2);
+ t2 = 0;
+ for (y = 0; y < 256; y++) {
+ t_start();
+ t1 = t_read();
+ z = sizeof(buf[1]);
+ if ((err = rsa_sign_hash(buf[0], 20, buf[1], &z, &yarrow_prng,
+ find_prng("yarrow"), find_hash("sha1"), 8, &key)) != CRYPT_OK) {
+ fprintf(stderr, "\n\nrsa_sign_hash says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+ exit(EXIT_FAILURE);
+ }
+ t1 = t_read() - t1;
+ t2 += t1;
+#ifdef LTC_PROFILE
+ t2 <<= 8;
+ break;
+#endif
+ }
+ t2 >>= 8;
+ fprintf(stderr, "RSA-%lu sign_hash took %15llu cycles\n", x, t2);
+ t2 = 0;
+ for (y = 0; y < 2048; y++) {
+ t_start();
+ t1 = t_read();
+ if ((err = rsa_verify_hash(buf[1], z, buf[0], 20, find_hash("sha1"), 8, &stat, &key)) != CRYPT_OK) {
+ fprintf(stderr, "\n\nrsa_verify_hash says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+ exit(EXIT_FAILURE);
+ }
+ if (stat == 0) {
+ fprintf(stderr, "\n\nrsa_verify_hash for RSA-%lu failed to verify signature(%lu)\n", x, y);
+ exit(EXIT_FAILURE);
+ }
+ t1 = t_read() - t1;
+ t2 += t1;
+#ifdef LTC_PROFILE
+ t2 <<= 11;
+ break;
+#endif
+ }
+ t2 >>= 11;
+ fprintf(stderr, "RSA-%lu verify_hash took %15llu cycles\n", x, t2);
+ fprintf(stderr, "\n\n");
rsa_free(&key);
}
}
@@ -715,108 +928,223 @@ void time_rsa(void)
void time_rsa(void) { fprintf(stderr, "NO RSA\n"); }
#endif
-#ifdef MECC
-/* time various ECC operations */
-void time_ecc(void)
+#ifdef MKAT
+/* time various KAT operations */
+void time_katja(void)
{
- ecc_key key;
+ katja_key key;
ulong64 t1, t2;
unsigned char buf[2][4096];
- unsigned long i, x, y, z;
- int err;
- static unsigned long sizes[] = {192/8, 256/8, 384/8, 521/8, 100000};
+ unsigned long x, y, z, zzz;
+ int err, zz;
- for (x = sizes[i=0]; x < 100000; x = sizes[++i]) {
+ for (x = 1024; x <= 2048; x += 256) {
t2 = 0;
- for (y = 0; y < 16; y++) {
+ for (y = 0; y < 4; y++) {
t_start();
t1 = t_read();
- if ((err = ecc_make_key(&yarrow_prng, find_prng("yarrow"), x, &key)) != CRYPT_OK) {
- fprintf(stderr, "\n\necc_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+ if ((err = katja_make_key(&yarrow_prng, find_prng("yarrow"), x/8, &key)) != CRYPT_OK) {
+ fprintf(stderr, "\n\nkatja_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
exit(EXIT_FAILURE);
}
t1 = t_read() - t1;
t2 += t1;
- if (y < 15) {
- ecc_free(&key);
+ if (y < 3) {
+ katja_free(&key);
}
}
- t2 >>= 4;
- fprintf(stderr, "ECC-%lu make_key took %15llu cycles\n", x*8, t2);
+ t2 >>= 2;
+ fprintf(stderr, "Katja-%lu make_key took %15llu cycles\n", x, t2);
t2 = 0;
for (y = 0; y < 16; y++) {
t_start();
t1 = t_read();
z = sizeof(buf[1]);
- if ((err = ecc_encrypt_key(buf[0], 20, buf[1], &z, &yarrow_prng, find_prng("yarrow"), find_hash("sha1"),
+ if ((err = katja_encrypt_key(buf[0], 32, buf[1], &z, "testprog", 8, &yarrow_prng,
+ find_prng("yarrow"), find_hash("sha1"),
&key)) != CRYPT_OK) {
- fprintf(stderr, "\n\necc_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+ fprintf(stderr, "\n\nkatja_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
exit(EXIT_FAILURE);
}
t1 = t_read() - t1;
t2 += t1;
}
t2 >>= 4;
- fprintf(stderr, "ECC-%lu encrypt_key took %15llu cycles\n", x*8, t2);
- ecc_free(&key);
+ fprintf(stderr, "Katja-%lu encrypt_key took %15llu cycles\n", x, t2);
+
+ t2 = 0;
+ for (y = 0; y < 2048; y++) {
+ t_start();
+ t1 = t_read();
+ zzz = sizeof(buf[0]);
+ if ((err = katja_decrypt_key(buf[1], z, buf[0], &zzz, "testprog", 8, find_hash("sha1"),
+ &zz, &key)) != CRYPT_OK) {
+ fprintf(stderr, "\n\nkatja_decrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+ exit(EXIT_FAILURE);
+ }
+ t1 = t_read() - t1;
+ t2 += t1;
+ }
+ t2 >>= 11;
+ fprintf(stderr, "Katja-%lu decrypt_key took %15llu cycles\n", x, t2);
+
+
+ katja_free(&key);
}
}
#else
-void time_ecc(void) { fprintf(stderr, "NO ECC\n"); }
+void time_katja(void) { fprintf(stderr, "NO Katja\n"); }
#endif
-#ifdef MDH
-/* time various DH operations */
-void time_dh(void)
+#ifdef MECC
+/* time various ECC operations */
+void time_ecc(void)
{
- dh_key key;
+ ecc_key key;
ulong64 t1, t2;
- unsigned char buf[2][4096];
- unsigned long i, x, y, z;
- int err;
- static unsigned long sizes[] = {768/8, 1024/8, 1536/8, 2048/8, 3072/8, 4096/8, 100000};
+ unsigned char buf[2][256];
+ unsigned long i, w, x, y, z;
+ int err, stat;
+ static unsigned long sizes[] = {
+#ifdef ECC112
+112/8,
+#endif
+#ifdef ECC128
+128/8,
+#endif
+#ifdef ECC160
+160/8,
+#endif
+#ifdef ECC192
+192/8,
+#endif
+#ifdef ECC224
+224/8,
+#endif
+#ifdef ECC256
+256/8,
+#endif
+#ifdef ECC384
+384/8,
+#endif
+#ifdef ECC521
+521/8,
+#endif
+100000};
for (x = sizes[i=0]; x < 100000; x = sizes[++i]) {
t2 = 0;
- for (y = 0; y < 16; y++) {
+ for (y = 0; y < 256; y++) {
t_start();
t1 = t_read();
- if ((err = dh_make_key(&yarrow_prng, find_prng("yarrow"), x, &key)) != CRYPT_OK) {
- fprintf(stderr, "\n\ndh_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+ if ((err = ecc_make_key(&yarrow_prng, find_prng("yarrow"), x, &key)) != CRYPT_OK) {
+ fprintf(stderr, "\n\necc_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
exit(EXIT_FAILURE);
}
t1 = t_read() - t1;
t2 += t1;
- if (y < 15) {
- dh_free(&key);
+#ifdef LTC_PROFILE
+ t2 <<= 8;
+ break;
+#endif
+
+ if (y < 255) {
+ ecc_free(&key);
}
}
- t2 >>= 4;
- fprintf(stderr, "DH-%4lu make_key took %15llu cycles\n", x*8, t2);
+ t2 >>= 8;
+ fprintf(stderr, "ECC-%lu make_key took %15llu cycles\n", x*8, t2);
t2 = 0;
- for (y = 0; y < 16; y++) {
+ for (y = 0; y < 256; y++) {
t_start();
t1 = t_read();
z = sizeof(buf[1]);
- if ((err = dh_encrypt_key(buf[0], 20, buf[1], &z, &yarrow_prng, find_prng("yarrow"), find_hash("sha1"),
+ if ((err = ecc_encrypt_key(buf[0], 20, buf[1], &z, &yarrow_prng, find_prng("yarrow"), find_hash("sha1"),
&key)) != CRYPT_OK) {
- fprintf(stderr, "\n\ndh_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+ fprintf(stderr, "\n\necc_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
exit(EXIT_FAILURE);
}
t1 = t_read() - t1;
t2 += t1;
+#ifdef LTC_PROFILE
+ t2 <<= 8;
+ break;
+#endif
}
- t2 >>= 4;
- fprintf(stderr, "DH-%4lu encrypt_key took %15llu cycles\n", x*8, t2);
- dh_free(&key);
+ t2 >>= 8;
+ fprintf(stderr, "ECC-%lu encrypt_key took %15llu cycles\n", x*8, t2);
+
+ t2 = 0;
+ for (y = 0; y < 256; y++) {
+ t_start();
+ t1 = t_read();
+ w = 20;
+ if ((err = ecc_decrypt_key(buf[1], z, buf[0], &w, &key)) != CRYPT_OK) {
+ fprintf(stderr, "\n\necc_decrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+ exit(EXIT_FAILURE);
+ }
+ t1 = t_read() - t1;
+ t2 += t1;
+#ifdef LTC_PROFILE
+ t2 <<= 8;
+ break;
+#endif
+ }
+ t2 >>= 8;
+ fprintf(stderr, "ECC-%lu decrypt_key took %15llu cycles\n", x*8, t2);
+
+ t2 = 0;
+ for (y = 0; y < 256; y++) {
+ t_start();
+ t1 = t_read();
+ z = sizeof(buf[1]);
+ if ((err = ecc_sign_hash(buf[0], 20, buf[1], &z, &yarrow_prng,
+ find_prng("yarrow"), &key)) != CRYPT_OK) {
+ fprintf(stderr, "\n\necc_sign_hash says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+ exit(EXIT_FAILURE);
+ }
+ t1 = t_read() - t1;
+ t2 += t1;
+#ifdef LTC_PROFILE
+ t2 <<= 8;
+ break;
+#endif
+ }
+ t2 >>= 8;
+ fprintf(stderr, "ECC-%lu sign_hash took %15llu cycles\n", x*8, t2);
+
+ t2 = 0;
+ for (y = 0; y < 256; y++) {
+ t_start();
+ t1 = t_read();
+ if ((err = ecc_verify_hash(buf[1], z, buf[0], 20, &stat, &key)) != CRYPT_OK) {
+ fprintf(stderr, "\n\necc_verify_hash says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+ exit(EXIT_FAILURE);
+ }
+ if (stat == 0) {
+ fprintf(stderr, "\n\necc_verify_hash for ECC-%lu failed to verify signature(%lu)\n", x*8, y);
+ exit(EXIT_FAILURE);
+ }
+ t1 = t_read() - t1;
+ t2 += t1;
+#ifdef LTC_PROFILE
+ t2 <<= 8;
+ break;
+#endif
+ }
+ t2 >>= 8;
+ fprintf(stderr, "ECC-%lu verify_hash took %15llu cycles\n", x*8, t2);
+
+ fprintf(stderr, "\n\n");
+ ecc_free(&key);
}
}
#else
-void time_dh(void) { fprintf(stderr, "NO DH\n"); }
+void time_ecc(void) { fprintf(stderr, "NO ECC\n"); }
#endif
void time_macs_(unsigned long MAC_SIZE)
@@ -835,12 +1163,17 @@ void time_macs_(unsigned long MAC_SIZE)
}
cipher_idx = find_cipher("aes");
- hash_idx = find_hash("md5");
+ hash_idx = find_hash("sha1");
+
+ if (cipher_idx == -1 || hash_idx == -1) {
+ fprintf(stderr, "Warning the MAC tests requires AES and SHA1 to operate... so sorry\n");
+ return;
+ }
yarrow_read(buf, MAC_SIZE*1024, &yarrow_prng);
yarrow_read(key, 16, &yarrow_prng);
-#ifdef OMAC
+#ifdef LTC_OMAC
t2 = -1;
for (x = 0; x < 10000; x++) {
t_start();
@@ -853,10 +1186,42 @@ void time_macs_(unsigned long MAC_SIZE)
t1 = t_read() - t1;
if (t1 < t2) t2 = t1;
}
- fprintf(stderr, "OMAC-AES\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+ fprintf(stderr, "OMAC-%s\t\t%9llu\n", cipher_descriptor[cipher_idx].name, t2/(ulong64)(MAC_SIZE*1024));
#endif
-#ifdef PMAC
+#ifdef LTC_XCBC
+ t2 = -1;
+ for (x = 0; x < 10000; x++) {
+ t_start();
+ t1 = t_read();
+ z = 16;
+ if ((err = xcbc_memory(cipher_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) {
+ fprintf(stderr, "\n\nxcbc error... %s\n", error_to_string(err));
+ exit(EXIT_FAILURE);
+ }
+ t1 = t_read() - t1;
+ if (t1 < t2) t2 = t1;
+ }
+ fprintf(stderr, "XCBC-%s\t\t%9llu\n", cipher_descriptor[cipher_idx].name, t2/(ulong64)(MAC_SIZE*1024));
+#endif
+
+#ifdef LTC_F9_MODE
+ t2 = -1;
+ for (x = 0; x < 10000; x++) {
+ t_start();
+ t1 = t_read();
+ z = 16;
+ if ((err = f9_memory(cipher_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) {
+ fprintf(stderr, "\n\nF9 error... %s\n", error_to_string(err));
+ exit(EXIT_FAILURE);
+ }
+ t1 = t_read() - t1;
+ if (t1 < t2) t2 = t1;
+ }
+ fprintf(stderr, "F9-%s\t\t\t%9llu\n", cipher_descriptor[cipher_idx].name, t2/(ulong64)(MAC_SIZE*1024));
+#endif
+
+#ifdef LTC_PMAC
t2 = -1;
for (x = 0; x < 10000; x++) {
t_start();
@@ -888,7 +1253,7 @@ void time_macs_(unsigned long MAC_SIZE)
fprintf(stderr, "PELICAN \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
#endif
-#ifdef HMAC
+#ifdef LTC_HMAC
t2 = -1;
for (x = 0; x < 10000; x++) {
t_start();
@@ -901,7 +1266,7 @@ void time_macs_(unsigned long MAC_SIZE)
t1 = t_read() - t1;
if (t1 < t2) t2 = t1;
}
- fprintf(stderr, "HMAC-MD5\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+ fprintf(stderr, "HMAC-%s\t\t%9llu\n", hash_descriptor[hash_idx].name, t2/(ulong64)(MAC_SIZE*1024));
#endif
XFREE(buf);
@@ -920,6 +1285,7 @@ void time_encmacs_(unsigned long MAC_SIZE)
ulong64 t1, t2;
unsigned long x, z;
int err, cipher_idx;
+ symmetric_key skey;
fprintf(stderr, "\nENC+MAC Timings (zero byte AAD, 16 byte IV, cycles/byte on %luKB blocks):\n", MAC_SIZE);
@@ -948,7 +1314,7 @@ void time_encmacs_(unsigned long MAC_SIZE)
t1 = t_read() - t1;
if (t1 < t2) t2 = t1;
}
- fprintf(stderr, "EAX \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+ fprintf(stderr, "EAX \t\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
#endif
#ifdef OCB_MODE
@@ -964,7 +1330,7 @@ void time_encmacs_(unsigned long MAC_SIZE)
t1 = t_read() - t1;
if (t1 < t2) t2 = t1;
}
- fprintf(stderr, "OCB \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+ fprintf(stderr, "OCB \t\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
#endif
#ifdef CCM_MODE
@@ -973,14 +1339,30 @@ void time_encmacs_(unsigned long MAC_SIZE)
t_start();
t1 = t_read();
z = 16;
- if ((err = ccm_memory(cipher_idx, key, 16, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z, CCM_ENCRYPT)) != CRYPT_OK) {
+ if ((err = ccm_memory(cipher_idx, key, 16, NULL, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z, CCM_ENCRYPT)) != CRYPT_OK) {
+ fprintf(stderr, "\nCCM error... %s\n", error_to_string(err));
+ exit(EXIT_FAILURE);
+ }
+ t1 = t_read() - t1;
+ if (t1 < t2) t2 = t1;
+ }
+ fprintf(stderr, "CCM (no-precomp) \t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+
+ cipher_descriptor[cipher_idx].setup(key, 16, 0, &skey);
+ t2 = -1;
+ for (x = 0; x < 10000; x++) {
+ t_start();
+ t1 = t_read();
+ z = 16;
+ if ((err = ccm_memory(cipher_idx, key, 16, &skey, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z, CCM_ENCRYPT)) != CRYPT_OK) {
fprintf(stderr, "\nCCM error... %s\n", error_to_string(err));
exit(EXIT_FAILURE);
}
t1 = t_read() - t1;
if (t1 < t2) t2 = t1;
}
- fprintf(stderr, "CCM \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+ fprintf(stderr, "CCM (precomp) \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+ cipher_descriptor[cipher_idx].done(&skey);
#endif
#ifdef GCM_MODE
@@ -999,7 +1381,11 @@ void time_encmacs_(unsigned long MAC_SIZE)
fprintf(stderr, "GCM (no-precomp)\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
{
- gcm_state gcm;
+ gcm_state gcm
+#ifdef GCM_TABLES_SSE2
+__attribute__ ((aligned (16)))
+#endif
+;
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;
@@ -1031,7 +1417,7 @@ void time_encmacs_(unsigned long MAC_SIZE)
t1 = t_read() - t1;
if (t1 < t2) t2 = t1;
}
- fprintf(stderr, "GCM (precomp)\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+ fprintf(stderr, "GCM (precomp)\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
}
#endif
@@ -1046,5 +1432,5 @@ void time_encmacs(void)
}
/* $Source: /cvs/libtom/libtomcrypt/testprof/x86_prof.c,v $ */
-/* $Revision: 1.16 $ */
-/* $Date: 2005/06/14 20:44:23 $ */
+/* $Revision: 1.51 $ */
+/* $Date: 2006/11/21 00:10:18 $ */