diff demos/test/test.c @ 143:5d99163f7e32 libtomcrypt-orig

import of libtomcrypt 0.99
author Matt Johnston <matt@ucc.asn.au>
date Sun, 19 Dec 2004 11:34:45 +0000
parents 6362d3854bb4
children
line wrap: on
line diff
--- a/demos/test/test.c	Tue Jun 15 14:07:21 2004 +0000
+++ b/demos/test/test.c	Sun Dec 19 11:34:45 2004 +0000
@@ -9,11 +9,13 @@
 {"cipher_hash_test",       "b",        "a",          cipher_hash_test     },
 {"modes_test",             "c",        "b",          modes_test           },
 {"mac_test",               "d",        "c",          mac_test             },
-{"pkcs_1_test",            "e",        "b",          pkcs_1_test          },
-{"rsa_test",               "f",        "e",          rsa_test             },
-{"ecc_test",               "g",        "a",          ecc_tests            },
-{"dsa_test",               "h",        "a",          dsa_test             },
-{"dh_test",                "i",        "a",          dh_tests             },
+{"der_test",               "e",         "",          der_tests            },
+
+{"pkcs_1_test",            "f",        "e",          pkcs_1_test          },
+{"rsa_test",               "g",        "e",          rsa_test             },
+{"ecc_test",               "h",        "a",          ecc_tests            },
+{"dsa_test",               "i",        "a",          dsa_test             },
+{"dh_test",                "j",        "a",          dh_tests             },
 
 {NULL, NULL, NULL, NULL} 
 };
@@ -31,6 +33,8 @@
 
 void register_algs(void)
 {
+  int err;
+
 #ifdef RIJNDAEL
   register_cipher (&aes_desc);
 #endif
@@ -110,16 +114,30 @@
 #ifdef WHIRLPOOL
   register_hash (&whirlpool_desc);
 #endif
+#ifdef CHC_HASH
+  register_hash(&chc_desc);
+  if ((err = chc_register(register_cipher(&aes_enc_desc))) != CRYPT_OK) {
+     printf("chc_register error: %s\n", error_to_string(err));
+     exit(EXIT_FAILURE);
+  }
+#endif
 
-   if (register_prng(&yarrow_desc) == -1) {
-      printf("Error registering yarrow PRNG\n");
-      exit(-1);
-   }
 
-   if (register_prng(&sprng_desc) == -1) {
-      printf("Error registering sprng PRNG\n");
-      exit(-1);
-   }
+#ifdef YARROW
+   register_prng(&yarrow_desc);
+#endif
+#ifdef FORTUNA
+   register_prng(&fortuna_desc);
+#endif
+#ifdef RC4
+   register_prng(&rc4_desc);
+#endif
+#ifdef SPRNG
+   register_prng(&sprng_desc);
+#endif
+#ifdef SOBER128
+   register_prng(&sober128_desc);
+#endif
 }
 
 /* sort tests based on their requirement/services.  Helps make sure dependencies are tested first */
@@ -153,20 +171,87 @@
       }
    } while (y == 1);
 }
-   
+
+#define STACKBLOCK       8
+#define STACK_EST_USAGE  32768
+
+unsigned char stack_mask[STACKBLOCK];
+unsigned long stack_cur=0;
+
+void stack_masker(void)
+{
+#ifdef STACK_TEST
+   volatile unsigned char M[STACK_EST_USAGE];
+   stack_cur   = 0;
+   for (stack_cur = 0; stack_cur < STACK_EST_USAGE/STACKBLOCK; stack_cur++) {
+       memcpy(M+(stack_cur*STACKBLOCK), stack_mask, STACKBLOCK);
+   }
+#endif
+}
+
+void stack_check(void)
+{
+#ifdef STACK_TEST
+   unsigned char M[STACK_EST_USAGE];
+   stack_cur   = 0;
+#ifdef STACK_DOWN
+   while (memcmp(M+(STACK_EST_USAGE-STACKBLOCK-stack_cur), stack_mask, STACKBLOCK) && 
+#else
+   while (memcmp(M+stack_cur, stack_mask, STACKBLOCK) &&
+#endif
+          stack_cur < (STACK_EST_USAGE - STACKBLOCK)) {
+      ++stack_cur;
+   }
+#endif
+}
+
 int main(void)
 {
+   int x;
+   unsigned char buf[16];
+
+   /* setup stack checker */
+   srand(time(NULL));
+   for (x = 0; x < STACKBLOCK; x++) {
+       stack_mask[x] = rand() & 255;
+   }
+   stack_masker();
+
    printf("Built with\n%s\n", crypt_build_settings);
 
-   srand(time(NULL));
    sort();
    register_algs();
       
    // start dummy yarrow for internal use 
    DO(yarrow_start(&test_yarrow));
-   DO(yarrow_add_entropy("test", 4, &test_yarrow));
+   sprng_read(buf, 16, NULL);
+   DO(yarrow_add_entropy(buf, 16, &test_yarrow));
    DO(yarrow_ready(&test_yarrow));
 
+   // output sizes 
+   printf("Sizes of objects (in bytes)\n");
+   printf("\tsymmetric_key\t=\t%5lu\n", sizeof(symmetric_key));
+   printf("\thash_state\t=\t%5lu\n", sizeof(hash_state));
+   printf("\thmac_state\t=\t%5lu\n", sizeof(hmac_state));
+   printf("\tomac_state\t=\t%5lu\n", sizeof(omac_state));
+   printf("\tpmac_state\t=\t%5lu\n", sizeof(pmac_state));
+   printf("\tocb_state\t=\t%5lu\n", sizeof(ocb_state));
+   printf("\teax_state\t=\t%5lu\n", sizeof(eax_state));
+   printf("\tmp_int\t\t=\t%5lu\n", sizeof(mp_int));
+#ifdef MRSA
+   printf("\trsa_key\t\t=\t%5lu\n", sizeof(rsa_key));
+#endif
+#ifdef MDSA
+   printf("\tdsa_key\t\t=\t%5lu\n", sizeof(dsa_key));
+#endif
+#ifdef MDH
+   printf("\tdh_key\t\t=\t%5lu\n", sizeof(dh_key));
+#endif
+#ifdef MECC
+   printf("\tecc_key\t\t=\t%5lu\n", sizeof(ecc_key));
+#endif
+
+   printf("\n\n");
    // do tests
    for (current_test = 0; tests[current_test].name != NULL; current_test++) {
        printf("[%-20s]: ", tests[current_test].name); fflush(stdout);