fips_test_suite.c 18 KB

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