Exemple #1
0
int
main(int argc, char **argv)
{
	/* try test vectors from RFC 2104 */

	u_char key1[16] = {
	    0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb,
	    0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb };
	u_char *data1 = "Hi There";
	u_char dig1[16] = {
	    0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c,
	    0x13, 0xf4, 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d };

	u_char *key2 = "Jefe";
	u_char *data2 = "what do ya want for nothing?";
	u_char dig2[16] = {
	    0x75, 0x0c, 0x78, 0x3e, 0x6a, 0xb0, 0xb5, 0x03,
	    0xea, 0xa8, 0x6e, 0x31, 0x0a, 0x5d, 0xb7, 0x38 };

	u_char key3[16];
	u_char data3[50];
	u_char dig3[16] = {
	    0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14, 0x4c, 0x88,
	    0xdb, 0xb8, 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6 };
	memset(key3, 0xaa, sizeof(key3));
	memset(data3, 0xdd, sizeof(data3));

	hmac_test(key1, sizeof(key1), data1, strlen(data1), dig1, sizeof(dig1));
	hmac_test(key2, strlen(key2), data2, strlen(data2), dig2, sizeof(dig2));
	hmac_test(key3, sizeof(key3), data3, sizeof(data3), dig3, sizeof(dig3));

	return 0;
}
Exemple #2
0
int mac_test(void)
{
#ifdef LTC_HMAC
   DO(hmac_test()); 
#endif
#ifdef LTC_PMAC
   DO(pmac_test()); 
#endif
#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
#ifdef OCB_MODE
   DO(ocb_test());  
#endif
#ifdef CCM_MODE
   DO(ccm_test());
#endif
#ifdef GCM_MODE
   DO(gcm_test());
#endif
#ifdef PELICAN
   DO(pelican_test());
#endif
   return 0;
}
Exemple #3
0
int main(int argc, char **argv)
{
	int fail = 0;
	hmac_test("hmac-sha1", 1);
	//hmac_test("hmac-sha256", 2);
	//hmac_test("hmac-sha512", 3);

	printf("=== %s: %d/%d failures ===\n", argv[0], fail, 3);
	return fail;
}
Exemple #4
0
int main(int argc, char **argv)
	{
	FILE *in = NULL, *out = NULL;

	int ret = 1;

	if(!FIPS_mode_set(1))
		{
		do_print_errors();
		goto end;
		}

	if (argc == 1)
		in = stdin;
	else
		in = fopen(argv[1], "r");

	if (argc < 2)
		out = stdout;
	else
		out = fopen(argv[2], "w");

	if (!in)
		{
		fprintf(stderr, "FATAL input initialization error\n");
		goto end;
		}

	if (!out)
		{
		fprintf(stderr, "FATAL output initialization error\n");
		goto end;
		}

	if (!hmac_test(EVP_sha1(), out, in))
		{
		fprintf(stderr, "FATAL hmac file processing error\n");
		goto end;
		}
	else
		ret = 0;

	end:

	if (ret)
		do_print_errors();

	if (in && (in != stdin))
		fclose(in);
	if (out && (out != stdout))
		fclose(out);

	return ret;

	}
Exemple #5
0
void ctaocrypt_test(void* args)
{
    int ret = 0;

    ((func_args*)args)->return_code = -1; /* error state */
    
    if ( (ret = md5_test()) ) 
        err_sys("MD5      test failed!\n", ret);
    else
        printf( "MD5      test passed!\n");

#ifndef NO_MD4
    if ( (ret = md4_test()) ) 
        err_sys("MD4      test failed!\n", ret);
    else
        printf( "MD4      test passed!\n");
#endif

    if ( (ret = sha_test()) ) 
        err_sys("SHA      test failed!\n", ret);
    else
        printf( "SHA      test passed!\n");

#ifndef NO_SHA256
    if ( (ret = sha256_test()) ) 
        err_sys("SHA-256  test failed!\n", ret);
    else
        printf( "SHA-256  test passed!\n");
#endif

#ifndef NO_HMAC
    if ( (ret = hmac_test()) ) 
        err_sys("HMAC     test failed!\n", ret);
    else
        printf( "HMAC     test passed!\n");
#endif

    if ( (ret = arc4_test()) )
        err_sys("ARC4     test failed!\n", ret);
    else
        printf( "ARC4     test passed!\n");

#ifndef NO_HC128
    if ( (ret = hc128_test()) )
        err_sys("HC-128   test failed!\n", ret);
    else
        printf( "HC-128   test passed!\n");
#endif

#ifndef NO_RABBIT
    if ( (ret = rabbit_test()) )
        err_sys("Rabbit   test failed!\n", ret);
    else
        printf( "Rabbit   test passed!\n");
#endif

#ifndef NO_DES
    if ( (ret = des_test()) )
        err_sys("DES      test failed!\n", ret);
    else
        printf( "DES      test passed!\n");
#endif

#ifndef NO_DES3
    if ( (ret = des3_test()) )
        err_sys("DES3     test failed!\n", ret);
    else
        printf( "DES3     test passed!\n");
#endif

#ifndef NO_AES
    if ( (ret = aes_test()) )
        err_sys("AES      test failed!\n", ret);
    else
        printf( "AES      test passed!\n");
#endif

    if ( (ret = random_test()) )
        err_sys("RANDOM   test failed!\n", ret);
    else
        printf( "RANDOM   test passed!\n");

    if ( (ret = rsa_test()) ) 
        err_sys("RSA      test failed!\n", ret);
    else
        printf( "RSA      test passed!\n");

#ifndef NO_DH
    if ( (ret = dh_test()) ) 
        err_sys("DH       test failed!\n", ret);
    else
        printf( "DH       test passed!\n");
#endif

#ifndef NO_DSA
    if ( (ret = dsa_test()) ) 
        err_sys("DSA      test failed!\n", ret);
    else
        printf( "DSA      test passed!\n");
#endif
    
#ifdef OPENSSL_EXTRA
    if ( (ret = openssl_test()) ) 
        err_sys("OPENSSL  test failed!\n", ret);
    else
        printf( "OPENSSL  test passed!\n");
#endif

    ((func_args*)args)->return_code = ret;
}
Exemple #6
0
int main(int argc, char** argv)
{ 
  hmac_test();
}
Exemple #7
0
int main ()
{
  char r4 [] = { 0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba,
                 0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31,
                 0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2,
                 0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a,
                 0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8,
                 0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd,
                 0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e,
                 0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f };
  run_test ("abc", 3, r4);

  char r1 [] = { 0xcf, 0x83, 0xe1, 0x35, 0x7e, 0xef, 0xb8, 0xbd,
                 0xf1, 0x54, 0x28, 0x50, 0xd6, 0x6d, 0x80, 0x07,
                 0xd6, 0x20, 0xe4, 0x05, 0x0b, 0x57, 0x15, 0xdc,
                 0x83, 0xf4, 0xa9, 0x21, 0xd3, 0x6c, 0xe9, 0xce,
                 0x47, 0xd0, 0xd1, 0x3c, 0x5d, 0x85, 0xf2, 0xb0,
                 0xff, 0x83, 0x18, 0xd2, 0x87, 0x7e, 0xec, 0x2f,
                 0x63, 0xb9, 0x31, 0xbd, 0x47, 0x41, 0x7a, 0x81,
                 0xa5, 0x38, 0x32, 0x7a, 0xf9, 0x27, 0xda, 0x3e};
  run_test ("", 0, r1);

  char r2 [] = { 0x07, 0xe5, 0x47, 0xd9, 0x58, 0x6f, 0x6a, 0x73,
                 0xf7, 0x3f, 0xba, 0xc0, 0x43, 0x5e, 0xd7, 0x69,
                 0x51, 0x21, 0x8f, 0xb7, 0xd0, 0xc8, 0xd7, 0x88,
                 0xa3, 0x09, 0xd7, 0x85, 0x43, 0x6b, 0xbb, 0x64,
                 0x2e, 0x93, 0xa2, 0x52, 0xa9, 0x54, 0xf2, 0x39,
                 0x12, 0x54, 0x7d, 0x1e, 0x8a, 0x3b, 0x5e, 0xd6,
                 0xe1, 0xbf, 0xd7, 0x09, 0x78, 0x21, 0x23, 0x3f,
                 0xa0, 0x53, 0x8f, 0x3d, 0xb8, 0x54, 0xfe, 0xe6 };
  run_test ("The quick brown fox jumps over the lazy dog", 43, r2);

  char r3 [] = { 0x91, 0xea, 0x12, 0x45, 0xf2, 0x0d, 0x46, 0xae,
                 0x9a, 0x03, 0x7a, 0x98, 0x9f, 0x54, 0xf1, 0xf7,
                 0x90, 0xf0, 0xa4, 0x76, 0x07, 0xee, 0xb8, 0xa1,
                 0x4d, 0x12, 0x89, 0x0c, 0xea, 0x77, 0xa1, 0xbb,
                 0xc6, 0xc7, 0xed, 0x9c, 0xf2, 0x05, 0xe6, 0x7b,
                 0x7f, 0x2b, 0x8f, 0xd4, 0xc7, 0xdf, 0xd3, 0xa7,
                 0xa8, 0x61, 0x7e, 0x45, 0xf3, 0xc4, 0x63, 0xd4,
                 0x81, 0xc7, 0xe5, 0x86, 0xc3, 0x9a, 0xc1, 0xed };
  run_test ("The quick brown fox jumps over the lazy dog.", 44, r3);

  char r5 [] = { 0x8e, 0x95, 0x9b, 0x75, 0xda, 0xe3, 0x13, 0xda,
                 0x8c, 0xf4, 0xf7, 0x28, 0x14, 0xfc, 0x14, 0x3f,
                 0x8f, 0x77, 0x79, 0xc6, 0xeb, 0x9f, 0x7f, 0xa1,
                 0x72, 0x99, 0xae, 0xad, 0xb6, 0x88, 0x90, 0x18,
                 0x50, 0x1d, 0x28, 0x9e, 0x49, 0x00, 0xf7, 0xe4,
                 0x33, 0x1b, 0x99, 0xde, 0xc4, 0xb5, 0x43, 0x3a,
                 0xc7, 0xd3, 0x29, 0xee, 0xb6, 0xdd, 0x26, 0x54,
                 0x5e, 0x96, 0xe5, 0x5b, 0x87, 0x4b, 0xe9, 0x09 };
  run_test ("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", 112, r5);

  char r6 [] = { 0x70, 0x7c, 0xc5, 0x13, 0xaa, 0x52, 0xbd, 0xaa,
                 0xe8, 0xd3, 0xef, 0xd4, 0xf1, 0x75, 0xcf, 0x94,
                 0x27, 0x5e, 0x4e, 0xaf, 0xde, 0xf0, 0x47, 0x17,
                 0x1d, 0x4c, 0x1b, 0x3f, 0x1e, 0xc4, 0x35, 0x62,
                 0x0a, 0x1a, 0xe9, 0xc3, 0x85, 0x91, 0xb1, 0xcb,
                 0xaa, 0xe2, 0x4a, 0x2e, 0x2b, 0x04, 0xf4, 0x0f,
                 0x70, 0x2f, 0xf8, 0x58, 0xe0, 0x89, 0x26, 0x38,
                 0x20, 0xa2, 0x84, 0x1b, 0xdf, 0x84, 0x15, 0xf1 };

  run_test ("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstuabcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstuabcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstuabcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstuabcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoi", 513, r6);

  hmac_test (511);
  hmac_test (512);
  hmac_test (513);
  hmac_test (514);
  hmac_test (515);

  char sha1_r1 [] = { 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A,
                      0xBA, 0x3E, 0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C,
                      0x9C, 0xD0, 0xD8, 0x9D };

  run_test_sha1 ("abc", 3, sha1_r1);

  char sha1_r2 [] = { 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d,
                      0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90,
                      0xaf, 0xd8, 0x07, 0x09 };
  run_test_sha1 ("", 0, sha1_r2);

  char sha1_r3 [] = { 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E,
                      0xBA, 0xAE, 0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5,
                      0xE5, 0x46, 0x70, 0xF1 };
  run_test_sha1 ("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
                 56, sha1_r3);

  /* test patterns from RFC 3174, skipping the first two which are r1, r3 */
  /* note that the results shown in RFC 3174 do not match sha1sum nor
   * http://www.hashemall.com/, which match each other */
/* :s/\(..\)/, 0x\1/g */

  char sha1_r4 [] = {
      0x86, 0xf7, 0xe4, 0x37, 0xfa, 0xa5, 0xa7, 0xfc, 0xe1, 0x5d,
      0x1d, 0xdc, 0xb9, 0xea, 0xea, 0xea, 0x37, 0x76, 0x67, 0xb8 };
  run_test_sha1 ("a", 1, sha1_r4);

  char sha1_r5 [] = {
      0xe0, 0xc0, 0x94, 0xe8, 0x67, 0xef, 0x46, 0xc3, 0x50, 0xef,
      0x54, 0xa7, 0xf5, 0x9d, 0xd6, 0x0b, 0xed, 0x92, 0xae, 0x83 };
  run_test_sha1 ("0123456701234567012345670123456701234567012345670123456701234567", 64, sha1_r5);

  char sha1_r6 [] = {
      0xec, 0x2d, 0x31, 0xe3, 0x62, 0x57, 0x43, 0x69, 0x67, 0xeb,
      0xa4, 0xc0, 0x14, 0xfb, 0xe7, 0x19, 0xa1, 0x30, 0x1a, 0x38 };
/* openssl gets ec.2d.31.e3.62.57.43.69.67.eb.a4.c0.14.fb.e7.19.a1.30.1a.38 */
/* length should be 495 */
  char sha1_t6 [] = { 0x98, 0xfe, 0x89, 0xb4, 0x4b, 0xc4, 0x9c, 0x08,
                      0xba, 0x67, 0x86, 0x4a, 0xf8, 0xef, 0x27, 0x20,
                      0xa3, 0x0f, 0x65, 0xe6, 0xf2, 0x4e, 0x64, 0x1a,
                      0x32, 0xe1, 0x06, 0x56, 0x9a, 0x5d, 0x75, 0x53,
                      0xea, 0x8d, 0xb1, 0x4d, 0x41, 0xaa, 0xeb, 0x0a,
                      0x7d, 0x9f, 0xc4, 0x4a, 0x50, 0x56, 0x47, 0x56,
                      0xd9, 0x3f, 0x70, 0xc0, 0xf0, 0xe2, 0x4e, 0xba,
                      0xb5, 0xb2, 0x4d, 0x75, 0xe0, 0x1a, 0x90, 0x83,
                      0x17, 0x0b, 0x1e, 0xf8, 0xdb, 0xa3, 0x2d, 0x3c,
                      0xf1, 0x1c, 0xe8, 0xa1, 0x22, 0x5f, 0x84, 0x0b,
                      0x6b, 0x98, 0x39, 0x02, 0x11, 0x3a, 0xaa, 0xca,
                      0x82, 0x5c, 0x36, 0xba, 0x28, 0x8b, 0xe6, 0xa7,
                      0x2c, 0x42, 0x99, 0x9b, 0x01, 0xe0, 0x78, 0x16,
                      0x68, 0xb8, 0xe2, 0x9d, 0xcc, 0x75, 0xbb, 0x2e,
                      0x7b, 0x46, 0x3e, 0x98, 0x7d, 0x91, 0x48, 0xc9,
                      0x3c, 0x85, 0xd3, 0xea, 0x3b, 0x38, 0x2a, 0x50,
                      0x2f, 0x6c, 0x44, 0x21, 0x79, 0x60, 0xa9, 0x9a,
                      0x0f, 0xd2, 0x3a, 0xe4, 0xb9, 0xe4, 0x4d, 0xb1,
                      0xbb, 0x5a, 0xbd, 0x3c, 0x02, 0x9a, 0xf2, 0x14,
                      0x71, 0xbe, 0x93, 0x31, 0xd6, 0xc7, 0xe5, 0x3d,
                      0xdf, 0x11, 0xd5, 0x71, 0xb8, 0x64, 0xe9, 0x2a,
                      0x5d, 0x19, 0x17, 0x0f, 0xac, 0x74, 0x7e, 0x87,
                      0x72, 0x8d, 0x2c, 0x6e, 0xba, 0x2b, 0x48, 0xb1,
                      0x21, 0xbc, 0xbc, 0x22, 0xd4, 0x06, 0x8f, 0x91,
                      0x35, 0x45, 0x87, 0xe2, 0xaa, 0x4b, 0xa6, 0xae,
                      0xf0, 0x75, 0xee, 0xea, 0xdb, 0xd9, 0x19, 0x57,
                      0xf4, 0x22, 0x56, 0x1c, 0x56, 0xf2, 0x94, 0x15,
                      0x69, 0x73, 0xe1, 0xb0, 0xec, 0x0a, 0xbd, 0x25,
                      0x04, 0xfb, 0xa0, 0xae, 0x63, 0xd7, 0x3d, 0x16,
                      0x67, 0xbf, 0xcc, 0x4a, 0xf6, 0x19, 0x86, 0xb5,
                      0xe0, 0x1b, 0xf3, 0xd5, 0xcf, 0xdb, 0x3c, 0x97,
                      0x7d, 0x6d, 0x4a, 0xff, 0x05, 0x0d, 0x81, 0x01,
                      0x2b, 0xcd, 0xe4, 0xf4, 0xea, 0x76, 0xbc, 0xb0,
                      0x84, 0x1e, 0x17, 0x59, 0x8f, 0xa3, 0x40, 0x6c,
                      0x90, 0xcc, 0x43, 0x30, 0xe7, 0xbd, 0xb5, 0xb2,
                      0x07, 0x83, 0x6f, 0xce, 0x27, 0x6e, 0xc7, 0x46,
                      0xef, 0x6a, 0x39, 0x58, 0xac, 0x4e, 0xcd, 0xb7,
                      0xfe, 0x32, 0x84, 0xe9, 0x52, 0xfe, 0x48, 0x73,
                      0xde, 0xfd, 0x14, 0x13, 0x98, 0x20, 0x52, 0x09,
                      0xa4, 0x34, 0xf1, 0x82, 0xb8, 0xc2, 0xc8, 0x67,
                      0xca, 0x62, 0x63, 0x5a, 0x97, 0xe2, 0x20, 0xd5,
                      0x03, 0xf8, 0x07, 0x3c, 0x42, 0xdf, 0xca, 0x4c,
                      0xa7, 0xd4, 0xc1, 0xe0, 0x30, 0xb5, 0x1e, 0x6c, 
                      0x5d, 0xf1, 0x60, 0x5a, 0xa6, 0xee, 0xca, 0xcf, 
                      0xc1, 0x01, 0x54, 0x99, 0xaf, 0x2a, 0xd8, 0x80,
                      0xe4, 0x75, 0xc9, 0xc5, 0xa9, 0x93, 0xad, 0xae,
                      0xb3, 0x3b, 0x05, 0x55, 0xa7, 0xcf, 0x88, 0x05,
                      0x1c, 0x34, 0xa7, 0xcf, 0xee, 0xf5, 0x64, 0x28,
                      0x8b, 0x65, 0xf6, 0x16, 0x7c, 0x94, 0x7a, 0x2a,
                      0xc2, 0x1d, 0x6c, 0xc8, 0xf8, 0x32, 0xba, 0x7c,
                      0x58, 0xd6, 0xbf, 0xb9, 0x39, 0x13, 0x1f, 0xdd,
                      0x9b, 0xac, 0xd3, 0x99, 0x68, 0x45, 0x79, 0x83,
                      0xb9, 0xca, 0xf8, 0xae, 0xc8, 0x6c, 0xf7, 0x77,
                      0x70, 0xaa, 0x25, 0xe2, 0xb5, 0x7c, 0x7e, 0x49,
                      0x78, 0x74, 0xa7, 0x51, 0x97, 0x19, 0x20, 0x40,
                      0x7a, 0xcb, 0xc3, 0x65, 0xa2, 0x0b, 0x3d, 0x80,
                      0x4c, 0x34, 0x80, 0x64, 0x4b, 0xd8, 0xe5, 0xcc,
                      0x49, 0x7c, 0x98, 0x0f, 0xf2, 0x19, 0x3d, 0xb0,
                      0x0d, 0xda, 0x4f, 0x8a, 0xc6, 0x12, 0x69, 0x36,
                      0x0c, 0xb6, 0xc4, 0x48, 0x39, 0x7c, 0xaa, 0x75,
                      0x77, 0x8e, 0x93, 0xcc, 0x4c, 0xed, 0x5b, 0xa1,
                      0xad, 0xbc, 0xde, 0x00, 0x00, 0x00, 0x00 };
  if (sizeof (sha1_t6) != 495)
    printf ("size of sha1_t6 is %zd, should be 495\n", sizeof (sha1_t6));
  run_test_sha1 (sha1_t6, 495, sha1_r6);

  return 0;
}