AES GCM selftests.
[openssl.git] / fips / fips_test_suite.c
1 /* ====================================================================
2  * Copyright (c) 2003 The OpenSSL Project.  All rights reserved.
3  *
4  *
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
10  *
11  * Contributed by Steve Marquess.
12  *
13  */
14
15 #define OPENSSL_FIPSAPI
16
17 #include <stdio.h>
18 #include <assert.h>
19 #include <ctype.h>
20 #include <string.h>
21 #include <stdlib.h>
22 #include <openssl/evp.h>
23 #include <openssl/hmac.h>
24 #include <openssl/sha.h>
25 #include <openssl/err.h>
26
27 #include <openssl/bn.h>
28 #include <openssl/rand.h>
29
30 #ifndef OPENSSL_FIPS
31 int main(int argc, char *argv[])
32     {
33     printf("No FIPS support\n");
34     return(0);
35     }
36 #else
37
38 #define ERR_clear_error() while(0)
39
40 #include <openssl/rsa.h>
41 #include <openssl/dsa.h>
42 #include <openssl/dh.h>
43
44 #include <openssl/fips.h>
45 #include "fips_utl.h"
46
47 /* AES: encrypt and decrypt known plaintext, verify result matches original plaintext
48 */
49 static int FIPS_aes_test(void)
50         {
51         int ret = 0;
52         unsigned char pltmp[16];
53         unsigned char citmp[16];
54         unsigned char key[16] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
55         unsigned char plaintext[16] = "etaonrishdlcu";
56         EVP_CIPHER_CTX ctx;
57         FIPS_cipher_ctx_init(&ctx);
58         if (FIPS_cipherinit(&ctx, EVP_aes_128_ecb(), key, NULL, 1) <= 0)
59                 goto err;
60         FIPS_cipher(&ctx, citmp, plaintext, 16);
61         if (FIPS_cipherinit(&ctx, EVP_aes_128_ecb(), key, NULL, 0) <= 0)
62                 goto err;
63         FIPS_cipher(&ctx, pltmp, citmp, 16);
64         if (memcmp(pltmp, plaintext, 16))
65                 goto err;
66         ret = 1;
67         err:
68         FIPS_cipher_ctx_cleanup(&ctx);
69         return ret;
70         }
71
72 static int FIPS_aes_gcm_test(void)
73         {
74         int ret = 0;
75         unsigned char pltmp[16];
76         unsigned char citmp[16];
77         unsigned char tagtmp[16];
78         unsigned char key[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
79         unsigned char iv[16] = {21,22,23,24,25,26,27,28,29,30,31,32};
80         unsigned char aad[] = "Some text AAD";
81         unsigned char plaintext[16] = "etaonrishdlcu";
82         EVP_CIPHER_CTX ctx;
83         FIPS_cipher_ctx_init(&ctx);
84         if (FIPS_cipherinit(&ctx, EVP_aes_128_gcm(), key, iv, 1) <= 0)
85                 goto err;
86         FIPS_cipher(&ctx, NULL, aad, sizeof(aad));
87         FIPS_cipher(&ctx, citmp, plaintext, 16);
88         FIPS_cipher(&ctx, NULL, NULL, 0);
89         if (!FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_GCM_GET_TAG, 16, tagtmp))
90                 goto err;
91
92         if (FIPS_cipherinit(&ctx, EVP_aes_128_gcm(), key, iv, 0) <= 0)
93                 goto err;
94         if (!FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_GCM_SET_TAG, 16, tagtmp))
95                 goto err;
96
97         FIPS_cipher(&ctx, NULL, aad, sizeof(aad));
98
99         FIPS_cipher(&ctx, pltmp, citmp, 16);
100
101         if (FIPS_cipher(&ctx, NULL, NULL, 0) < 0)
102                 goto err;
103
104         if (memcmp(pltmp, plaintext, 16))
105                 goto err;
106
107         ret = 1;
108         err:
109         FIPS_cipher_ctx_cleanup(&ctx);
110         return ret;
111         }
112
113 static int FIPS_des3_test(void)
114         {
115         int ret = 0;
116         unsigned char pltmp[8];
117         unsigned char citmp[8];
118         unsigned char key[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,
119                               19,20,21,22,23,24};
120         unsigned char plaintext[] = { 'e', 't', 'a', 'o', 'n', 'r', 'i', 's' };
121         EVP_CIPHER_CTX ctx;
122         FIPS_cipher_ctx_init(&ctx);
123         if (FIPS_cipherinit(&ctx, EVP_des_ede3_ecb(), key, NULL, 1) <= 0)
124                 goto err;
125         FIPS_cipher(&ctx, citmp, plaintext, 8);
126         if (FIPS_cipherinit(&ctx, EVP_des_ede3_ecb(), key, NULL, 0) <= 0)
127                 goto err;
128         FIPS_cipher(&ctx, pltmp, citmp, 8);
129         if (memcmp(pltmp, plaintext, 8))
130                 goto err;
131         ret = 1;
132         err:
133         FIPS_cipher_ctx_cleanup(&ctx);
134         return ret;
135         }
136
137 /*
138  * DSA: generate keys and sign, verify input plaintext.
139  */
140 static int FIPS_dsa_test(int bad)
141     {
142     DSA *dsa = NULL;
143     unsigned char dgst[] = "etaonrishdlc";
144     int r = 0;
145     EVP_MD_CTX mctx;
146     DSA_SIG *sig = NULL;
147
148     ERR_clear_error();
149     FIPS_md_ctx_init(&mctx);
150     dsa = FIPS_dsa_new();
151     if (!dsa)
152         goto end;
153     if (!DSA_generate_parameters_ex(dsa, 1024,NULL,0,NULL,NULL,NULL))
154         goto end;
155     if (!DSA_generate_key(dsa))
156         goto end;
157     if (bad)
158             BN_add_word(dsa->pub_key, 1);
159
160     if (!FIPS_digestinit(&mctx, EVP_sha256()))
161         goto end;
162     if (!FIPS_digestupdate(&mctx, dgst, sizeof(dgst) - 1))
163         goto end;
164     sig = FIPS_dsa_sign_ctx(dsa, &mctx);
165     if (!sig)
166         goto end;
167
168     if (!FIPS_digestinit(&mctx, EVP_sha256()))
169         goto end;
170     if (!FIPS_digestupdate(&mctx, dgst, sizeof(dgst) - 1))
171         goto end;
172     r = FIPS_dsa_verify_ctx(dsa, &mctx, sig);
173     end:
174     if (sig)
175         FIPS_dsa_sig_free(sig);
176     FIPS_md_ctx_cleanup(&mctx);
177     if (dsa)
178           FIPS_dsa_free(dsa);
179     if (r != 1)
180         return 0;
181     return 1;
182     }
183
184 /*
185  * RSA: generate keys and sign, verify input plaintext.
186  */
187 static int FIPS_rsa_test(int bad)
188     {
189     RSA *key;
190     unsigned char input_ptext[] = "etaonrishdlc";
191     unsigned char buf[256];
192     unsigned int slen;
193     BIGNUM *bn;
194     EVP_MD_CTX mctx;
195     int r = 0;
196
197     ERR_clear_error();
198     FIPS_md_ctx_init(&mctx);
199     key = FIPS_rsa_new();
200     bn = BN_new();
201     if (!key || !bn)
202         return 0;
203     BN_set_word(bn, 65537);
204     if (!RSA_generate_key_ex(key, 2048,bn,NULL))
205         return 0;
206     BN_free(bn);
207     if (bad)
208             BN_add_word(key->n, 1);
209
210     if (!FIPS_digestinit(&mctx, EVP_sha256()))
211         goto end;
212     if (!FIPS_digestupdate(&mctx, input_ptext, sizeof(input_ptext) - 1))
213         goto end;
214     if (!FIPS_rsa_sign_ctx(key, &mctx, RSA_PKCS1_PADDING, 0, NULL, buf, &slen))
215         goto end;
216
217     if (!FIPS_digestinit(&mctx, EVP_sha256()))
218         goto end;
219     if (!FIPS_digestupdate(&mctx, input_ptext, sizeof(input_ptext) - 1))
220         goto end;
221     r = FIPS_rsa_verify_ctx(key, &mctx, RSA_PKCS1_PADDING, 0, NULL, buf, slen);
222     end:
223     FIPS_md_ctx_cleanup(&mctx);
224     if (key)
225           FIPS_rsa_free(key);
226     if (r != 1)
227         return 0;
228     return 1;
229     }
230
231 /* SHA1: generate hash of known digest value and compare to known
232    precomputed correct hash
233 */
234 static int FIPS_sha1_test()
235     {
236     unsigned char digest[SHA_DIGEST_LENGTH] =
237         { 0x11, 0xf1, 0x9a, 0x3a, 0xec, 0x1a, 0x1e, 0x8e, 0x65, 0xd4, 0x9a, 0x38, 0x0c, 0x8b, 0x1e, 0x2c, 0xe8, 0xb3, 0xc5, 0x18 };
238     unsigned char str[] = "etaonrishd";
239
240     unsigned char md[SHA_DIGEST_LENGTH];
241
242     ERR_clear_error();
243     if (!FIPS_digest(str,sizeof(str) - 1,md, NULL, EVP_sha1())) return 0;
244     if (memcmp(md,digest,sizeof(md)))
245         return 0;
246     return 1;
247     }
248
249 /* SHA256: generate hash of known digest value and compare to known
250    precomputed correct hash
251 */
252 static int FIPS_sha256_test()
253     {
254     unsigned char digest[SHA256_DIGEST_LENGTH] =
255         {0xf5, 0x53, 0xcd, 0xb8, 0xcf, 0x1, 0xee, 0x17, 0x9b, 0x93, 0xc9, 0x68, 0xc0, 0xea, 0x40, 0x91,
256          0x6, 0xec, 0x8e, 0x11, 0x96, 0xc8, 0x5d, 0x1c, 0xaf, 0x64, 0x22, 0xe6, 0x50, 0x4f, 0x47, 0x57};
257     unsigned char str[] = "etaonrishd";
258
259     unsigned char md[SHA256_DIGEST_LENGTH];
260
261     ERR_clear_error();
262     if (!FIPS_digest(str,sizeof(str) - 1,md, NULL, EVP_sha256())) return 0;
263     if (memcmp(md,digest,sizeof(md)))
264         return 0;
265     return 1;
266     }
267
268 /* SHA512: generate hash of known digest value and compare to known
269    precomputed correct hash
270 */
271 static int FIPS_sha512_test()
272     {
273     unsigned char digest[SHA512_DIGEST_LENGTH] =
274         {0x99, 0xc9, 0xe9, 0x5b, 0x88, 0xd4, 0x78, 0x88, 0xdf, 0x88, 0x5f, 0x94, 0x71, 0x64, 0x28, 0xca,
275          0x16, 0x1f, 0x3d, 0xf4, 0x1f, 0xf3, 0x0f, 0xc5, 0x03, 0x99, 0xb2, 0xd0, 0xe7, 0x0b, 0x94, 0x4a,
276          0x45, 0xd2, 0x6c, 0x4f, 0x20, 0x06, 0xef, 0x71, 0xa9, 0x25, 0x7f, 0x24, 0xb1, 0xd9, 0x40, 0x22,
277          0x49, 0x54, 0x10, 0xc2, 0x22, 0x9d, 0x27, 0xfe, 0xbd, 0xd6, 0xd6, 0xeb, 0x2d, 0x42, 0x1d, 0xa3};
278     unsigned char str[] = "etaonrishd";
279
280     unsigned char md[SHA512_DIGEST_LENGTH];
281
282     ERR_clear_error();
283     if (!FIPS_digest(str,sizeof(str) - 1,md, NULL, EVP_sha512())) return 0;
284     if (memcmp(md,digest,sizeof(md)))
285         return 0;
286     return 1;
287     }
288
289 /* HMAC-SHA1: generate hash of known digest value and compare to known
290    precomputed correct hash
291 */
292 static int FIPS_hmac_sha1_test()
293     {
294     unsigned char key[] = "etaonrishd";
295     unsigned char iv[] = "Sample text";
296     unsigned char kaval[EVP_MAX_MD_SIZE] =
297         {0x73, 0xf7, 0xa0, 0x48, 0xf8, 0x94, 0xed, 0xdd, 0x0a, 0xea, 0xea, 0x56, 0x1b, 0x61, 0x2e, 0x70,
298          0xb2, 0xfb, 0xec, 0xc6};
299
300     unsigned char out[EVP_MAX_MD_SIZE];
301     unsigned int outlen;
302
303     ERR_clear_error();
304     if (!HMAC(EVP_sha1(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
305     if (memcmp(out,kaval,outlen))
306         return 0;
307     return 1;
308     }
309
310 /* HMAC-SHA224: generate hash of known digest value and compare to known
311    precomputed correct hash
312 */
313 static int FIPS_hmac_sha224_test()
314     {
315     unsigned char key[] = "etaonrishd";
316     unsigned char iv[] = "Sample text";
317     unsigned char kaval[EVP_MAX_MD_SIZE] =
318         {0x75, 0x58, 0xd5, 0xbd, 0x55, 0x6d, 0x87, 0x0f, 0x75, 0xff, 0xbe, 0x1c, 0xb2, 0xf0, 0x20, 0x35,
319          0xe5, 0x62, 0x49, 0xb6, 0x94, 0xb9, 0xfc, 0x65, 0x34, 0x33, 0x3a, 0x19};
320
321     unsigned char out[EVP_MAX_MD_SIZE];
322     unsigned int outlen;
323
324     ERR_clear_error();
325     if (!HMAC(EVP_sha224(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
326     if (memcmp(out,kaval,outlen))
327         return 0;
328     return 1;
329     }
330
331 /* HMAC-SHA256: generate hash of known digest value and compare to known
332    precomputed correct hash
333 */
334 static int FIPS_hmac_sha256_test()
335     {
336     unsigned char key[] = "etaonrishd";
337     unsigned char iv[] = "Sample text";
338     unsigned char kaval[EVP_MAX_MD_SIZE] =
339         {0xe9, 0x17, 0xc1, 0x7b, 0x4c, 0x6b, 0x77, 0xda, 0xd2, 0x30, 0x36, 0x02, 0xf5, 0x72, 0x33, 0x87,
340          0x9f, 0xc6, 0x6e, 0x7b, 0x7e, 0xa8, 0xea, 0xaa, 0x9f, 0xba, 0xee, 0x51, 0xff, 0xda, 0x24, 0xf4};
341
342     unsigned char out[EVP_MAX_MD_SIZE];
343     unsigned int outlen;
344
345     ERR_clear_error();
346     if (!HMAC(EVP_sha256(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
347     if (memcmp(out,kaval,outlen))
348         return 0;
349     return 1;
350     }
351
352 /* HMAC-SHA384: generate hash of known digest value and compare to known
353    precomputed correct hash
354 */
355 static int FIPS_hmac_sha384_test()
356     {
357     unsigned char key[] = "etaonrishd";
358     unsigned char iv[] = "Sample text";
359     unsigned char kaval[EVP_MAX_MD_SIZE] =
360         {0xb2, 0x9d, 0x40, 0x58, 0x32, 0xc4, 0xe3, 0x31, 0xb6, 0x63, 0x08, 0x26, 0x99, 0xef, 0x3b, 0x10,
361          0xe2, 0xdf, 0xf8, 0xff, 0xc6, 0xe1, 0x03, 0x29, 0x81, 0x2a, 0x1b, 0xac, 0xb0, 0x07, 0x39, 0x08,
362          0xf3, 0x91, 0x35, 0x11, 0x76, 0xd6, 0x4c, 0x20, 0xfb, 0x4d, 0xc3, 0xf3, 0xb8, 0x9b, 0x88, 0x1c};
363
364     unsigned char out[EVP_MAX_MD_SIZE];
365     unsigned int outlen;
366
367     ERR_clear_error();
368     if (!HMAC(EVP_sha384(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
369     if (memcmp(out,kaval,outlen))
370         return 0;
371     return 1;
372     }
373
374 /* HMAC-SHA512: generate hash of known digest value and compare to known
375    precomputed correct hash
376 */
377 static int FIPS_hmac_sha512_test()
378     {
379     unsigned char key[] = "etaonrishd";
380     unsigned char iv[] = "Sample text";
381     unsigned char kaval[EVP_MAX_MD_SIZE] =
382         {0xcd, 0x3e, 0xb9, 0x51, 0xb8, 0xbc, 0x7f, 0x9a, 0x23, 0xaf, 0xf3, 0x77, 0x59, 0x85, 0xa9, 0xe6,
383          0xf7, 0xd1, 0x51, 0x96, 0x17, 0xe0, 0x92, 0xd8, 0xa6, 0x3b, 0xc1, 0xad, 0x7e, 0x24, 0xca, 0xb1,
384          0xd7, 0x79, 0x0a, 0xa5, 0xea, 0x2c, 0x02, 0x58, 0x0b, 0xa6, 0x52, 0x6b, 0x61, 0x7f, 0xeb, 0x9c,
385          0x47, 0x86, 0x5d, 0x74, 0x2b, 0x88, 0xdf, 0xee, 0x46, 0x69, 0x96, 0x3d, 0xa6, 0xd9, 0x2a, 0x53};
386
387     unsigned char out[EVP_MAX_MD_SIZE];
388     unsigned int outlen;
389
390     ERR_clear_error();
391     if (!HMAC(EVP_sha512(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
392     if (memcmp(out,kaval,outlen))
393         return 0;
394     return 1;
395     }
396
397
398 /* DH: generate shared parameters
399 */
400 static int dh_test()
401     {
402     DH *dh;
403     ERR_clear_error();
404     dh = FIPS_dh_new();
405     if (!dh)
406         return 0;
407     if (!DH_generate_parameters_ex(dh, 1024, 2, NULL))
408         return 0;
409     FIPS_dh_free(dh);
410     return 1;
411     }
412
413 /* Zeroize
414 */
415 static int Zeroize()
416     {
417     RSA *key;
418     BIGNUM *bn;
419     unsigned char userkey[16] = 
420         { 0x48, 0x50, 0xf0, 0xa3, 0x3a, 0xed, 0xd3, 0xaf, 0x6e, 0x47, 0x7f, 0x83, 0x02, 0xb1, 0x09, 0x68 };
421     size_t i;
422     int n;
423
424     key = FIPS_rsa_new();
425     bn = BN_new();
426     if (!key || !bn)
427         return 0;
428     BN_set_word(bn, 65537);
429     if (!RSA_generate_key_ex(key, 1024,bn,NULL))
430         return 0;
431     BN_free(bn);
432     
433     n = BN_num_bytes(key->d);
434     printf(" Generated %d byte RSA private key\n", n);
435     printf("\tBN key before overwriting:\n");
436     do_bn_print(stdout, key->d);
437     BN_rand(key->d,n*8,-1,0);
438     printf("\tBN key after overwriting:\n");
439     do_bn_print(stdout, key->d);
440
441     printf("\tchar buffer key before overwriting: \n\t\t");
442     for(i = 0; i < sizeof(userkey); i++) printf("%02x", userkey[i]);
443         printf("\n");
444     RAND_bytes(userkey, sizeof userkey);
445     printf("\tchar buffer key after overwriting: \n\t\t");
446     for(i = 0; i < sizeof(userkey); i++) printf("%02x", userkey[i]);
447         printf("\n");
448
449     return 1;
450     }
451
452 static int Error;
453 static const char * Fail(const char *msg)
454     {
455     Error++;
456     return msg; 
457     }
458
459 static void test_msg(const char *msg, int result)
460         {
461         printf("%s...%s\n", msg, result ? "successful" : Fail("Failed!"));
462         }
463
464 int main(int argc,char **argv)
465     {
466
467     int do_corrupt_rsa_keygen = 0, do_corrupt_dsa_keygen = 0;
468     int bad_rsa = 0, bad_dsa = 0;
469     int do_rng_stick = 0;
470     int no_exit = 0;
471
472     fips_set_error_print();
473
474     printf("\tFIPS-mode test application\n\n");
475
476     /* Load entropy from external file, if any */
477     RAND_load_file(".rnd", 1024);
478
479     if (argv[1]) {
480         /* Corrupted KAT tests */
481         if (!strcmp(argv[1], "aes")) {
482             FIPS_corrupt_aes();
483             printf("AES encryption/decryption with corrupted KAT...\n");
484         } else if (!strcmp(argv[1], "aes-gcm")) {
485             FIPS_corrupt_aes_gcm();
486             printf("AES-GCM encryption/decryption with corrupted KAT...\n");
487         } else if (!strcmp(argv[1], "des")) {
488             FIPS_corrupt_des();
489             printf("DES3-ECB encryption/decryption with corrupted KAT...\n");
490         } else if (!strcmp(argv[1], "dsa")) {
491             FIPS_corrupt_dsa();
492             printf("DSA key generation and signature validation with corrupted KAT...\n");
493         } else if (!strcmp(argv[1], "rsa")) {
494             FIPS_corrupt_rsa();
495             printf("RSA key generation and signature validation with corrupted KAT...\n");
496         } else if (!strcmp(argv[1], "rsakey")) {
497             printf("RSA key generation and signature validation with corrupted key...\n");
498             bad_rsa = 1;
499             no_exit = 1;
500         } else if (!strcmp(argv[1], "rsakeygen")) {
501             do_corrupt_rsa_keygen = 1;
502             no_exit = 1;
503             printf("RSA key generation and signature validation with corrupted keygen...\n");
504         } else if (!strcmp(argv[1], "dsakey")) {
505             printf("DSA key generation and signature validation with corrupted key...\n");
506             bad_dsa = 1;
507             no_exit = 1;
508         } else if (!strcmp(argv[1], "dsakeygen")) {
509             do_corrupt_dsa_keygen = 1;
510             no_exit = 1;
511             printf("DSA key generation and signature validation with corrupted keygen...\n");
512         } else if (!strcmp(argv[1], "sha1")) {
513             FIPS_corrupt_sha1();
514             printf("SHA-1 hash with corrupted KAT...\n");
515         } else if (!strcmp(argv[1], "rng")) {
516             FIPS_corrupt_rng();
517         } else if (!strcmp(argv[1], "rngstick")) {
518             do_rng_stick = 1;
519             no_exit = 1;
520             printf("RNG test with stuck continuous test...\n");
521         } else {
522             printf("Bad argument \"%s\"\n", argv[1]);
523             exit(1);
524         }
525         if (!no_exit) {
526                 if (!FIPS_mode_set(1)) {
527                     printf("Power-up self test failed\n");
528                     exit(1);
529                 }
530                 printf("Power-up self test successful\n");
531                 exit(0);
532         }
533     }
534
535     /* Non-Approved cryptographic operation
536     */
537     printf("1. Non-Approved cryptographic operation test...\n");
538     test_msg("\ta. Included algorithm (D-H)...", dh_test());
539
540     /* Power-up self test
541     */
542     ERR_clear_error();
543     test_msg("2. Automatic power-up self test", FIPS_mode_set(1));
544     if (!FIPS_mode())
545         exit(1);
546     if (do_corrupt_dsa_keygen)
547             FIPS_corrupt_dsa_keygen();
548     if (do_corrupt_rsa_keygen)
549             FIPS_corrupt_rsa_keygen();
550     if (do_rng_stick)
551             FIPS_rng_stick();
552
553     /* AES encryption/decryption
554     */
555     test_msg("3a. AES encryption/decryption", FIPS_aes_test());
556     /* AES GCM encryption/decryption
557     */
558     test_msg("3b. AES-GCM encryption/decryption", FIPS_aes_gcm_test());
559
560     /* RSA key generation and encryption/decryption
561     */
562     test_msg("4. RSA key generation and encryption/decryption",
563                                                 FIPS_rsa_test(bad_rsa));
564
565     /* DES-CBC encryption/decryption
566     */
567     test_msg("5. DES-ECB encryption/decryption", FIPS_des3_test());
568
569     /* DSA key generation and signature validation
570     */
571     test_msg("6. DSA key generation and signature validation",
572                                                 FIPS_dsa_test(bad_dsa));
573
574     /* SHA-1 hash
575     */
576     test_msg("7a. SHA-1 hash", FIPS_sha1_test());
577
578     /* SHA-256 hash
579     */
580     test_msg("7b. SHA-256 hash", FIPS_sha256_test());
581
582     /* SHA-512 hash
583     */
584     test_msg("7c. SHA-512 hash", FIPS_sha512_test());
585
586     /* HMAC-SHA-1 hash
587     */
588     test_msg("7d. HMAC-SHA-1 hash", FIPS_hmac_sha1_test());
589
590     /* HMAC-SHA-224 hash
591     */
592     test_msg("7e. HMAC-SHA-224 hash", FIPS_hmac_sha224_test());
593
594     /* HMAC-SHA-256 hash
595     */
596     test_msg("7f. HMAC-SHA-256 hash", FIPS_hmac_sha256_test());
597
598     /* HMAC-SHA-384 hash
599     */
600     test_msg("7g. HMAC-SHA-384 hash", FIPS_hmac_sha384_test());
601
602     /* HMAC-SHA-512 hash
603     */
604     test_msg("7h. HMAC-SHA-512 hash", FIPS_hmac_sha512_test());
605
606     /* Non-Approved cryptographic operation
607     */
608     printf("8. Non-Approved cryptographic operation test...\n");
609     printf("\ta. Included algorithm (D-H)...%s\n",
610                 dh_test() ? "successful as expected"
611                                                 : Fail("failed INCORRECTLY!") );
612
613     /* Zeroization
614     */
615     printf("9. Zero-ization...\n\t%s\n",
616                 Zeroize() ? "successful as expected"
617                                         : Fail("failed INCORRECTLY!") );
618
619     printf("\nAll tests completed with %d errors\n", Error);
620     return Error ? 1 : 0;
621     }
622
623 #endif