1 /* ====================================================================
2 * Copyright (c) 2003 The OpenSSL Project. All rights reserved.
5 * This command is intended as a test driver for the FIPS-140 testing
6 * lab performing FIPS-140 validation. It demonstrates the use of the
7 * OpenSSL library ito perform a variety of common cryptographic
8 * functions. A power-up self test is demonstrated by deliberately
9 * pointing to an invalid executable hash
11 * Contributed by Steve Marquess.
15 #define OPENSSL_FIPSAPI
22 #include <openssl/evp.h>
23 #include <openssl/hmac.h>
24 #include <openssl/cmac.h>
25 #include <openssl/sha.h>
26 #include <openssl/err.h>
28 #include <openssl/bn.h>
29 #include <openssl/rand.h>
32 int main(int argc, char *argv[])
34 printf("No FIPS support\n");
39 #define ERR_clear_error() while(0)
41 #include <openssl/rsa.h>
42 #include <openssl/dsa.h>
43 #include <openssl/dh.h>
45 #include <openssl/fips.h>
48 /* AES: encrypt and decrypt known plaintext, verify result matches original plaintext
50 static int FIPS_aes_test(void)
53 unsigned char pltmp[16];
54 unsigned char citmp[16];
55 unsigned char key[16] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
56 unsigned char plaintext[16] = "etaonrishdlcu";
58 FIPS_cipher_ctx_init(&ctx);
59 if (FIPS_cipherinit(&ctx, EVP_aes_128_ecb(), key, NULL, 1) <= 0)
61 FIPS_cipher(&ctx, citmp, plaintext, 16);
62 if (FIPS_cipherinit(&ctx, EVP_aes_128_ecb(), key, NULL, 0) <= 0)
64 FIPS_cipher(&ctx, pltmp, citmp, 16);
65 if (memcmp(pltmp, plaintext, 16))
69 FIPS_cipher_ctx_cleanup(&ctx);
73 static int FIPS_aes_gcm_test(void)
76 unsigned char pltmp[16];
77 unsigned char citmp[16];
78 unsigned char tagtmp[16];
79 unsigned char key[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
80 unsigned char iv[16] = {21,22,23,24,25,26,27,28,29,30,31,32};
81 unsigned char aad[] = "Some text AAD";
82 unsigned char plaintext[16] = "etaonrishdlcu";
84 FIPS_cipher_ctx_init(&ctx);
85 if (FIPS_cipherinit(&ctx, EVP_aes_128_gcm(), key, iv, 1) <= 0)
87 FIPS_cipher(&ctx, NULL, aad, sizeof(aad));
88 FIPS_cipher(&ctx, citmp, plaintext, 16);
89 FIPS_cipher(&ctx, NULL, NULL, 0);
90 if (!FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_GCM_GET_TAG, 16, tagtmp))
93 if (FIPS_cipherinit(&ctx, EVP_aes_128_gcm(), key, iv, 0) <= 0)
95 if (!FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_GCM_SET_TAG, 16, tagtmp))
98 FIPS_cipher(&ctx, NULL, aad, sizeof(aad));
100 FIPS_cipher(&ctx, pltmp, citmp, 16);
102 if (FIPS_cipher(&ctx, NULL, NULL, 0) < 0)
105 if (memcmp(pltmp, plaintext, 16))
110 FIPS_cipher_ctx_cleanup(&ctx);
114 static int FIPS_des3_test(void)
117 unsigned char pltmp[8];
118 unsigned char citmp[8];
119 unsigned char key[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,
121 unsigned char plaintext[] = { 'e', 't', 'a', 'o', 'n', 'r', 'i', 's' };
123 FIPS_cipher_ctx_init(&ctx);
124 if (FIPS_cipherinit(&ctx, EVP_des_ede3_ecb(), key, NULL, 1) <= 0)
126 FIPS_cipher(&ctx, citmp, plaintext, 8);
127 if (FIPS_cipherinit(&ctx, EVP_des_ede3_ecb(), key, NULL, 0) <= 0)
129 FIPS_cipher(&ctx, pltmp, citmp, 8);
130 if (memcmp(pltmp, plaintext, 8))
134 FIPS_cipher_ctx_cleanup(&ctx);
139 * DSA: generate keys and sign, verify input plaintext.
141 static int FIPS_dsa_test(int bad)
144 unsigned char dgst[] = "etaonrishdlc";
150 FIPS_md_ctx_init(&mctx);
151 dsa = FIPS_dsa_new();
154 if (!DSA_generate_parameters_ex(dsa, 1024,NULL,0,NULL,NULL,NULL))
156 if (!DSA_generate_key(dsa))
159 BN_add_word(dsa->pub_key, 1);
161 if (!FIPS_digestinit(&mctx, EVP_sha256()))
163 if (!FIPS_digestupdate(&mctx, dgst, sizeof(dgst) - 1))
165 sig = FIPS_dsa_sign_ctx(dsa, &mctx);
169 if (!FIPS_digestinit(&mctx, EVP_sha256()))
171 if (!FIPS_digestupdate(&mctx, dgst, sizeof(dgst) - 1))
173 r = FIPS_dsa_verify_ctx(dsa, &mctx, sig);
176 FIPS_dsa_sig_free(sig);
177 FIPS_md_ctx_cleanup(&mctx);
186 * RSA: generate keys and sign, verify input plaintext.
188 static int FIPS_rsa_test(int bad)
191 unsigned char input_ptext[] = "etaonrishdlc";
192 unsigned char buf[256];
199 FIPS_md_ctx_init(&mctx);
200 key = FIPS_rsa_new();
204 BN_set_word(bn, 65537);
205 if (!RSA_generate_key_ex(key, 2048,bn,NULL))
209 BN_add_word(key->n, 1);
211 if (!FIPS_digestinit(&mctx, EVP_sha256()))
213 if (!FIPS_digestupdate(&mctx, input_ptext, sizeof(input_ptext) - 1))
215 if (!FIPS_rsa_sign_ctx(key, &mctx, RSA_PKCS1_PADDING, 0, NULL, buf, &slen))
218 if (!FIPS_digestinit(&mctx, EVP_sha256()))
220 if (!FIPS_digestupdate(&mctx, input_ptext, sizeof(input_ptext) - 1))
222 r = FIPS_rsa_verify_ctx(key, &mctx, RSA_PKCS1_PADDING, 0, NULL, buf, slen);
224 FIPS_md_ctx_cleanup(&mctx);
232 /* SHA1: generate hash of known digest value and compare to known
233 precomputed correct hash
235 static int FIPS_sha1_test()
237 unsigned char digest[SHA_DIGEST_LENGTH] =
238 { 0x11, 0xf1, 0x9a, 0x3a, 0xec, 0x1a, 0x1e, 0x8e, 0x65, 0xd4, 0x9a, 0x38, 0x0c, 0x8b, 0x1e, 0x2c, 0xe8, 0xb3, 0xc5, 0x18 };
239 unsigned char str[] = "etaonrishd";
241 unsigned char md[SHA_DIGEST_LENGTH];
244 if (!FIPS_digest(str,sizeof(str) - 1,md, NULL, EVP_sha1())) return 0;
245 if (memcmp(md,digest,sizeof(md)))
250 /* SHA256: generate hash of known digest value and compare to known
251 precomputed correct hash
253 static int FIPS_sha256_test()
255 unsigned char digest[SHA256_DIGEST_LENGTH] =
256 {0xf5, 0x53, 0xcd, 0xb8, 0xcf, 0x1, 0xee, 0x17, 0x9b, 0x93, 0xc9, 0x68, 0xc0, 0xea, 0x40, 0x91,
257 0x6, 0xec, 0x8e, 0x11, 0x96, 0xc8, 0x5d, 0x1c, 0xaf, 0x64, 0x22, 0xe6, 0x50, 0x4f, 0x47, 0x57};
258 unsigned char str[] = "etaonrishd";
260 unsigned char md[SHA256_DIGEST_LENGTH];
263 if (!FIPS_digest(str,sizeof(str) - 1,md, NULL, EVP_sha256())) return 0;
264 if (memcmp(md,digest,sizeof(md)))
269 /* SHA512: generate hash of known digest value and compare to known
270 precomputed correct hash
272 static int FIPS_sha512_test()
274 unsigned char digest[SHA512_DIGEST_LENGTH] =
275 {0x99, 0xc9, 0xe9, 0x5b, 0x88, 0xd4, 0x78, 0x88, 0xdf, 0x88, 0x5f, 0x94, 0x71, 0x64, 0x28, 0xca,
276 0x16, 0x1f, 0x3d, 0xf4, 0x1f, 0xf3, 0x0f, 0xc5, 0x03, 0x99, 0xb2, 0xd0, 0xe7, 0x0b, 0x94, 0x4a,
277 0x45, 0xd2, 0x6c, 0x4f, 0x20, 0x06, 0xef, 0x71, 0xa9, 0x25, 0x7f, 0x24, 0xb1, 0xd9, 0x40, 0x22,
278 0x49, 0x54, 0x10, 0xc2, 0x22, 0x9d, 0x27, 0xfe, 0xbd, 0xd6, 0xd6, 0xeb, 0x2d, 0x42, 0x1d, 0xa3};
279 unsigned char str[] = "etaonrishd";
281 unsigned char md[SHA512_DIGEST_LENGTH];
284 if (!FIPS_digest(str,sizeof(str) - 1,md, NULL, EVP_sha512())) return 0;
285 if (memcmp(md,digest,sizeof(md)))
290 /* HMAC-SHA1: generate hash of known digest value and compare to known
291 precomputed correct hash
293 static int FIPS_hmac_sha1_test()
295 unsigned char key[] = "etaonrishd";
296 unsigned char iv[] = "Sample text";
297 unsigned char kaval[EVP_MAX_MD_SIZE] =
298 {0x73, 0xf7, 0xa0, 0x48, 0xf8, 0x94, 0xed, 0xdd, 0x0a, 0xea, 0xea, 0x56, 0x1b, 0x61, 0x2e, 0x70,
299 0xb2, 0xfb, 0xec, 0xc6};
301 unsigned char out[EVP_MAX_MD_SIZE];
305 if (!HMAC(EVP_sha1(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
306 if (memcmp(out,kaval,outlen))
311 /* HMAC-SHA224: generate hash of known digest value and compare to known
312 precomputed correct hash
314 static int FIPS_hmac_sha224_test()
316 unsigned char key[] = "etaonrishd";
317 unsigned char iv[] = "Sample text";
318 unsigned char kaval[EVP_MAX_MD_SIZE] =
319 {0x75, 0x58, 0xd5, 0xbd, 0x55, 0x6d, 0x87, 0x0f, 0x75, 0xff, 0xbe, 0x1c, 0xb2, 0xf0, 0x20, 0x35,
320 0xe5, 0x62, 0x49, 0xb6, 0x94, 0xb9, 0xfc, 0x65, 0x34, 0x33, 0x3a, 0x19};
322 unsigned char out[EVP_MAX_MD_SIZE];
326 if (!HMAC(EVP_sha224(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
327 if (memcmp(out,kaval,outlen))
332 /* HMAC-SHA256: generate hash of known digest value and compare to known
333 precomputed correct hash
335 static int FIPS_hmac_sha256_test()
337 unsigned char key[] = "etaonrishd";
338 unsigned char iv[] = "Sample text";
339 unsigned char kaval[EVP_MAX_MD_SIZE] =
340 {0xe9, 0x17, 0xc1, 0x7b, 0x4c, 0x6b, 0x77, 0xda, 0xd2, 0x30, 0x36, 0x02, 0xf5, 0x72, 0x33, 0x87,
341 0x9f, 0xc6, 0x6e, 0x7b, 0x7e, 0xa8, 0xea, 0xaa, 0x9f, 0xba, 0xee, 0x51, 0xff, 0xda, 0x24, 0xf4};
343 unsigned char out[EVP_MAX_MD_SIZE];
347 if (!HMAC(EVP_sha256(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
348 if (memcmp(out,kaval,outlen))
353 /* HMAC-SHA384: generate hash of known digest value and compare to known
354 precomputed correct hash
356 static int FIPS_hmac_sha384_test()
358 unsigned char key[] = "etaonrishd";
359 unsigned char iv[] = "Sample text";
360 unsigned char kaval[EVP_MAX_MD_SIZE] =
361 {0xb2, 0x9d, 0x40, 0x58, 0x32, 0xc4, 0xe3, 0x31, 0xb6, 0x63, 0x08, 0x26, 0x99, 0xef, 0x3b, 0x10,
362 0xe2, 0xdf, 0xf8, 0xff, 0xc6, 0xe1, 0x03, 0x29, 0x81, 0x2a, 0x1b, 0xac, 0xb0, 0x07, 0x39, 0x08,
363 0xf3, 0x91, 0x35, 0x11, 0x76, 0xd6, 0x4c, 0x20, 0xfb, 0x4d, 0xc3, 0xf3, 0xb8, 0x9b, 0x88, 0x1c};
365 unsigned char out[EVP_MAX_MD_SIZE];
369 if (!HMAC(EVP_sha384(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
370 if (memcmp(out,kaval,outlen))
375 /* HMAC-SHA512: generate hash of known digest value and compare to known
376 precomputed correct hash
378 static int FIPS_hmac_sha512_test()
380 unsigned char key[] = "etaonrishd";
381 unsigned char iv[] = "Sample text";
382 unsigned char kaval[EVP_MAX_MD_SIZE] =
383 {0xcd, 0x3e, 0xb9, 0x51, 0xb8, 0xbc, 0x7f, 0x9a, 0x23, 0xaf, 0xf3, 0x77, 0x59, 0x85, 0xa9, 0xe6,
384 0xf7, 0xd1, 0x51, 0x96, 0x17, 0xe0, 0x92, 0xd8, 0xa6, 0x3b, 0xc1, 0xad, 0x7e, 0x24, 0xca, 0xb1,
385 0xd7, 0x79, 0x0a, 0xa5, 0xea, 0x2c, 0x02, 0x58, 0x0b, 0xa6, 0x52, 0x6b, 0x61, 0x7f, 0xeb, 0x9c,
386 0x47, 0x86, 0x5d, 0x74, 0x2b, 0x88, 0xdf, 0xee, 0x46, 0x69, 0x96, 0x3d, 0xa6, 0xd9, 0x2a, 0x53};
388 unsigned char out[EVP_MAX_MD_SIZE];
392 if (!HMAC(EVP_sha512(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
393 if (memcmp(out,kaval,outlen))
398 /* CMAC-AES128: generate hash of known digest value and compare to known
399 precomputed correct hash
401 static int FIPS_cmac_aes128_test()
403 unsigned char key[16] = { 0x2b,0x7e,0x15,0x16, 0x28,0xae,0xd2,0xa6,
404 0xab,0xf7,0x15,0x88, 0x09,0xcf,0x4f,0x3c, };
405 unsigned char data[] = "Sample text";
406 unsigned char kaval[EVP_MAX_MD_SIZE] =
407 { 0x16,0x83,0xfe,0xac, 0x52,0x9b,0xae,0x23,
408 0xd7,0xd5,0x66,0xf5, 0xd2,0x8d,0xbd,0x2a, };
410 unsigned char *out = NULL;
412 CMAC_CTX *ctx = CMAC_CTX_new();
419 if (!CMAC_Init(ctx,key,sizeof(key),EVP_aes_128_cbc(),NULL))
421 if (!CMAC_Update(ctx,data,sizeof(data)-1))
423 /* This should return 1. If not, there's a programming error... */
424 if (!CMAC_Final(ctx, out, &outlen))
426 out = OPENSSL_malloc(outlen);
427 if (!CMAC_Final(ctx, out, &outlen))
431 char *hexout = OPENSSL_malloc(outlen * 2 + 1);
432 bin2hex(out, outlen, hexout);
433 printf("CMAC-AES128: res = %s\n", hexout);
434 OPENSSL_free(hexout);
438 if (!memcmp(out,kaval,outlen))
448 /* CMAC-AES192: generate hash of known digest value and compare to known
449 precomputed correct hash
451 static int FIPS_cmac_aes192_test()
453 unsigned char key[] = { 0x8e,0x73,0xb0,0xf7, 0xda,0x0e,0x64,0x52,
454 0xc8,0x10,0xf3,0x2b, 0x80,0x90,0x79,0xe5,
455 0x62,0xf8,0xea,0xd2, 0x52,0x2c,0x6b,0x7b, };
456 unsigned char data[] = "Sample text";
457 unsigned char kaval[] =
458 { 0xd6,0x99,0x19,0x25, 0xe5,0x1d,0x95,0x48,
459 0xb1,0x4a,0x0b,0xf2, 0xc6,0x3c,0x47,0x1f, };
461 unsigned char *out = NULL;
463 CMAC_CTX *ctx = CMAC_CTX_new();
470 if (!CMAC_Init(ctx,key,sizeof(key),EVP_aes_192_cbc(),NULL))
472 if (!CMAC_Update(ctx,data,sizeof(data)-1))
474 /* This should return 1. If not, there's a programming error... */
475 if (!CMAC_Final(ctx, out, &outlen))
477 out = OPENSSL_malloc(outlen);
478 if (!CMAC_Final(ctx, out, &outlen))
482 char *hexout = OPENSSL_malloc(outlen * 2 + 1);
483 bin2hex(out, outlen, hexout);
484 printf("CMAC-AES192: res = %s\n", hexout);
485 OPENSSL_free(hexout);
489 if (!memcmp(out,kaval,outlen))
499 /* CMAC-AES256: generate hash of known digest value and compare to known
500 precomputed correct hash
502 static int FIPS_cmac_aes256_test()
504 unsigned char key[] = { 0x60,0x3d,0xeb,0x10, 0x15,0xca,0x71,0xbe,
505 0x2b,0x73,0xae,0xf0, 0x85,0x7d,0x77,0x81,
506 0x1f,0x35,0x2c,0x07, 0x3b,0x61,0x08,0xd7,
507 0x2d,0x98,0x10,0xa3, 0x09,0x14,0xdf,0xf4, };
508 unsigned char data[] = "Sample text";
509 unsigned char kaval[] =
510 { 0xec,0xc2,0xcf,0x63, 0xc7,0xce,0xfc,0xa4,
511 0xb0,0x86,0x37,0x5f, 0x15,0x60,0xba,0x1f, };
513 unsigned char *out = NULL;
515 CMAC_CTX *ctx = CMAC_CTX_new();
522 if (!CMAC_Init(ctx,key,sizeof(key),EVP_aes_256_cbc(),NULL))
524 if (!CMAC_Update(ctx,data,sizeof(data)-1))
526 /* This should return 1. If not, there's a programming error... */
527 if (!CMAC_Final(ctx, out, &outlen))
529 out = OPENSSL_malloc(outlen);
530 if (!CMAC_Final(ctx, out, &outlen))
534 char *hexout = OPENSSL_malloc(outlen * 2 + 1);
535 bin2hex(out, outlen, hexout);
536 printf("CMAC-AES256: res = %s\n", hexout);
537 OPENSSL_free(hexout);
541 if (!memcmp(out,kaval,outlen))
551 /* CMAC-TDEA2: generate hash of known digest value and compare to known
552 precomputed correct hash
554 static int FIPS_cmac_tdea2_test()
556 unsigned char key[] = { 0x4c,0xf1,0x51,0x34, 0xa2,0x85,0x0d,0xd5,
557 0x8a,0x3d,0x10,0xba, 0x80,0x57,0x0d,0x38, };
558 unsigned char data[] = "Sample text";
559 unsigned char kaval[] =
560 {0x73, 0xf7, 0xa0, 0x48, 0xf8, 0x94, 0xed, 0xdd, 0x0a, 0xea, 0xea, 0x56, 0x1b, 0x61, 0x2e, 0x70,
561 0xb2, 0xfb, 0xec, 0xc6};
563 unsigned char *out = NULL;
565 CMAC_CTX *ctx = CMAC_CTX_new();
572 if (!CMAC_Init(ctx,key,sizeof(key),EVP_des_ede_cbc(),NULL))
574 if (!CMAC_Update(ctx,data,sizeof(data)-1))
576 /* This should return 1. If not, there's a programming error... */
577 if (!CMAC_Final(ctx, out, &outlen))
579 out = OPENSSL_malloc(outlen);
580 if (!CMAC_Final(ctx, out, &outlen))
584 char *hexout = OPENSSL_malloc(outlen * 2 + 1);
585 bin2hex(out, outlen, hexout);
586 printf("CMAC-TDEA2: res = %s\n", hexout);
587 OPENSSL_free(hexout);
591 if (!memcmp(out,kaval,outlen))
601 /* CMAC-TDEA3: generate hash of known digest value and compare to known
602 precomputed correct hash
604 static int FIPS_cmac_tdea3_test()
606 unsigned char key[] = { 0x8a,0xa8,0x3b,0xf8, 0xcb,0xda,0x10,0x62,
607 0x0b,0xc1,0xbf,0x19, 0xfb,0xb6,0xcd,0x58,
608 0xbc,0x31,0x3d,0x4a, 0x37,0x1c,0xa8,0xb5, };
609 unsigned char data[] = "Sample text";
610 unsigned char kaval[EVP_MAX_MD_SIZE] =
611 { 0xb4,0x06,0x4e,0xbf, 0x59,0x89,0xba,0x68, };
613 unsigned char *out = NULL;
615 CMAC_CTX *ctx = CMAC_CTX_new();
622 if (!CMAC_Init(ctx,key,sizeof(key),EVP_des_ede3_cbc(),NULL))
624 if (!CMAC_Update(ctx,data,sizeof(data)-1))
626 /* This should return 1. If not, there's a programming error... */
627 if (!CMAC_Final(ctx, out, &outlen))
629 out = OPENSSL_malloc(outlen);
630 if (!CMAC_Final(ctx, out, &outlen))
634 char *hexout = OPENSSL_malloc(outlen * 2 + 1);
635 bin2hex(out, outlen, hexout);
636 printf("CMAC-TDEA3: res = %s\n", hexout);
637 OPENSSL_free(hexout);
641 if (!memcmp(out,kaval,outlen))
652 /* DH: generate shared parameters
661 if (!DH_generate_parameters_ex(dh, 1024, 2, NULL))
673 unsigned char userkey[16] =
674 { 0x48, 0x50, 0xf0, 0xa3, 0x3a, 0xed, 0xd3, 0xaf, 0x6e, 0x47, 0x7f, 0x83, 0x02, 0xb1, 0x09, 0x68 };
678 key = FIPS_rsa_new();
682 BN_set_word(bn, 65537);
683 if (!RSA_generate_key_ex(key, 1024,bn,NULL))
687 n = BN_num_bytes(key->d);
688 printf(" Generated %d byte RSA private key\n", n);
689 printf("\tBN key before overwriting:\n");
690 do_bn_print(stdout, key->d);
691 BN_rand(key->d,n*8,-1,0);
692 printf("\tBN key after overwriting:\n");
693 do_bn_print(stdout, key->d);
695 printf("\tchar buffer key before overwriting: \n\t\t");
696 for(i = 0; i < sizeof(userkey); i++) printf("%02x", userkey[i]);
698 RAND_bytes(userkey, sizeof userkey);
699 printf("\tchar buffer key after overwriting: \n\t\t");
700 for(i = 0; i < sizeof(userkey); i++) printf("%02x", userkey[i]);
707 static const char * Fail(const char *msg)
713 static void test_msg(const char *msg, int result)
715 printf("%s...%s\n", msg, result ? "successful" : Fail("Failed!"));
718 int main(int argc,char **argv)
721 int do_corrupt_rsa_keygen = 0, do_corrupt_dsa_keygen = 0;
722 int bad_rsa = 0, bad_dsa = 0;
723 int do_rng_stick = 0;
726 fips_set_error_print();
728 printf("\tFIPS-mode test application\n\n");
730 /* Load entropy from external file, if any */
731 RAND_load_file(".rnd", 1024);
734 /* Corrupted KAT tests */
735 if (!strcmp(argv[1], "aes")) {
737 printf("AES encryption/decryption with corrupted KAT...\n");
738 } else if (!strcmp(argv[1], "aes-gcm")) {
739 FIPS_corrupt_aes_gcm();
740 printf("AES-GCM encryption/decryption with corrupted KAT...\n");
741 } else if (!strcmp(argv[1], "des")) {
743 printf("DES3-ECB encryption/decryption with corrupted KAT...\n");
744 } else if (!strcmp(argv[1], "dsa")) {
746 printf("DSA key generation and signature validation with corrupted KAT...\n");
747 } else if (!strcmp(argv[1], "ecdsa")) {
748 FIPS_corrupt_ecdsa();
749 printf("ECDSA key generation and signature validation with corrupted KAT...\n");
750 } else if (!strcmp(argv[1], "rsa")) {
752 printf("RSA key generation and signature validation with corrupted KAT...\n");
753 } else if (!strcmp(argv[1], "rsakey")) {
754 printf("RSA key generation and signature validation with corrupted key...\n");
757 } else if (!strcmp(argv[1], "rsakeygen")) {
758 do_corrupt_rsa_keygen = 1;
760 printf("RSA key generation and signature validation with corrupted keygen...\n");
761 } else if (!strcmp(argv[1], "dsakey")) {
762 printf("DSA key generation and signature validation with corrupted key...\n");
765 } else if (!strcmp(argv[1], "dsakeygen")) {
766 do_corrupt_dsa_keygen = 1;
768 printf("DSA key generation and signature validation with corrupted keygen...\n");
769 } else if (!strcmp(argv[1], "sha1")) {
771 printf("SHA-1 hash with corrupted KAT...\n");
772 } else if (!strcmp(argv[1], "drbg")) {
774 } else if (!strcmp(argv[1], "rng")) {
776 } else if (!strcmp(argv[1], "rngstick")) {
779 printf("RNG test with stuck continuous test...\n");
781 printf("Bad argument \"%s\"\n", argv[1]);
785 if (!FIPS_mode_set(1)) {
786 printf("Power-up self test failed\n");
789 printf("Power-up self test successful\n");
794 /* Non-Approved cryptographic operation
796 printf("1. Non-Approved cryptographic operation test...\n");
797 test_msg("\ta. Included algorithm (D-H)...", dh_test());
799 /* Power-up self test
802 test_msg("2. Automatic power-up self test", FIPS_mode_set(1));
805 if (do_corrupt_dsa_keygen)
806 FIPS_corrupt_dsa_keygen();
807 if (do_corrupt_rsa_keygen)
808 FIPS_corrupt_rsa_keygen();
812 /* AES encryption/decryption
814 test_msg("3a. AES encryption/decryption", FIPS_aes_test());
815 /* AES GCM encryption/decryption
817 test_msg("3b. AES-GCM encryption/decryption", FIPS_aes_gcm_test());
819 /* RSA key generation and encryption/decryption
821 test_msg("4. RSA key generation and encryption/decryption",
822 FIPS_rsa_test(bad_rsa));
824 /* DES-CBC encryption/decryption
826 test_msg("5. DES-ECB encryption/decryption", FIPS_des3_test());
828 /* DSA key generation and signature validation
830 test_msg("6. DSA key generation and signature validation",
831 FIPS_dsa_test(bad_dsa));
835 test_msg("7a. SHA-1 hash", FIPS_sha1_test());
839 test_msg("7b. SHA-256 hash", FIPS_sha256_test());
843 test_msg("7c. SHA-512 hash", FIPS_sha512_test());
847 test_msg("7d. HMAC-SHA-1 hash", FIPS_hmac_sha1_test());
851 test_msg("7e. HMAC-SHA-224 hash", FIPS_hmac_sha224_test());
855 test_msg("7f. HMAC-SHA-256 hash", FIPS_hmac_sha256_test());
859 test_msg("7g. HMAC-SHA-384 hash", FIPS_hmac_sha384_test());
863 test_msg("7h. HMAC-SHA-512 hash", FIPS_hmac_sha512_test());
867 test_msg("8a. CMAC-AES-128 hash", FIPS_cmac_aes128_test());
871 test_msg("8b. CMAC-AES-192 hash", FIPS_cmac_aes192_test());
875 test_msg("8c. CMAC-AES-256 hash", FIPS_cmac_aes256_test());
877 # if 0 /* Not a FIPS algorithm */
880 test_msg("8d. CMAC-TDEA-2 hash", FIPS_cmac_tdea2_test());
885 test_msg("8e. CMAC-TDEA-3 hash", FIPS_cmac_tdea3_test());
887 /* Non-Approved cryptographic operation
889 printf("9. Non-Approved cryptographic operation test...\n");
890 printf("\ta. Included algorithm (D-H)...%s\n",
891 dh_test() ? "successful as expected"
892 : Fail("failed INCORRECTLY!") );
896 printf("10. Zero-ization...\n\t%s\n",
897 Zeroize() ? "successful as expected"
898 : Fail("failed INCORRECTLY!") );
900 printf("\nAll tests completed with %d errors\n", Error);
901 return Error ? 1 : 0;