param_build_test.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. /*
  2. * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
  4. *
  5. * Licensed under the Apache License 2.0 (the "License"). You may not use
  6. * this file except in compliance with the License. You can obtain a copy
  7. * in the file LICENSE in the source distribution or at
  8. * https://www.openssl.org/source/license.html
  9. */
  10. #include <string.h>
  11. #include <openssl/params.h>
  12. #include "openssl/param_build.h"
  13. #include "internal/nelem.h"
  14. #include "testutil.h"
  15. static const OSSL_PARAM params_empty[] = { OSSL_PARAM_END };
  16. static int template_public_test(int tstid)
  17. {
  18. OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
  19. OSSL_PARAM *params = NULL, *params_blt = NULL, *p1 = NULL, *p;
  20. BIGNUM *bn = NULL, *bn_res = NULL;
  21. int i;
  22. long int l;
  23. int32_t i32;
  24. int64_t i64;
  25. double d;
  26. time_t t;
  27. char *utf = NULL;
  28. const char *cutf;
  29. int res = 0;
  30. if (!TEST_ptr(bld)
  31. || !TEST_true(OSSL_PARAM_BLD_push_long(bld, "l", 42))
  32. || !TEST_true(OSSL_PARAM_BLD_push_int32(bld, "i32", 1532))
  33. || !TEST_true(OSSL_PARAM_BLD_push_int64(bld, "i64", -9999999))
  34. || !TEST_true(OSSL_PARAM_BLD_push_time_t(bld, "t", 11224))
  35. || !TEST_true(OSSL_PARAM_BLD_push_double(bld, "d", 1.61803398875))
  36. || !TEST_ptr(bn = BN_new())
  37. || !TEST_true(BN_set_word(bn, 1729))
  38. || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, "bignumber", bn))
  39. || !TEST_true(OSSL_PARAM_BLD_push_utf8_string(bld, "utf8_s", "foo",
  40. sizeof("foo")))
  41. || !TEST_true(OSSL_PARAM_BLD_push_utf8_ptr(bld, "utf8_p", "bar-boom",
  42. 0))
  43. || !TEST_true(OSSL_PARAM_BLD_push_int(bld, "i", -6))
  44. || !TEST_ptr(params_blt = OSSL_PARAM_BLD_to_param(bld)))
  45. goto err;
  46. switch(tstid) {
  47. case 0:
  48. params = params_blt;
  49. break;
  50. case 1:
  51. params = OSSL_PARAM_merge(params_blt, params_empty);
  52. break;
  53. case 2:
  54. params = OSSL_PARAM_dup(params_blt);
  55. break;
  56. case 3:
  57. p1 = OSSL_PARAM_merge(params_blt, params_empty);
  58. params = OSSL_PARAM_dup(p1);
  59. break;
  60. default:
  61. p1 = OSSL_PARAM_dup(params_blt);
  62. params = OSSL_PARAM_merge(p1, params_empty);
  63. break;
  64. }
  65. /* Check int */
  66. if (!TEST_ptr(p = OSSL_PARAM_locate(params, "i"))
  67. || !TEST_true(OSSL_PARAM_get_int(p, &i))
  68. || !TEST_str_eq(p->key, "i")
  69. || !TEST_uint_eq(p->data_type, OSSL_PARAM_INTEGER)
  70. || !TEST_size_t_eq(p->data_size, sizeof(int))
  71. || !TEST_int_eq(i, -6)
  72. /* Check int32 */
  73. || !TEST_ptr(p = OSSL_PARAM_locate(params, "i32"))
  74. || !TEST_true(OSSL_PARAM_get_int32(p, &i32))
  75. || !TEST_str_eq(p->key, "i32")
  76. || !TEST_uint_eq(p->data_type, OSSL_PARAM_INTEGER)
  77. || !TEST_size_t_eq(p->data_size, sizeof(int32_t))
  78. || !TEST_int_eq((int)i32, 1532)
  79. /* Check int64 */
  80. || !TEST_ptr(p = OSSL_PARAM_locate(params, "i64"))
  81. || !TEST_str_eq(p->key, "i64")
  82. || !TEST_uint_eq(p->data_type, OSSL_PARAM_INTEGER)
  83. || !TEST_size_t_eq(p->data_size, sizeof(int64_t))
  84. || !TEST_true(OSSL_PARAM_get_int64(p, &i64))
  85. || !TEST_long_eq((long)i64, -9999999)
  86. /* Check long */
  87. || !TEST_ptr(p = OSSL_PARAM_locate(params, "l"))
  88. || !TEST_str_eq(p->key, "l")
  89. || !TEST_uint_eq(p->data_type, OSSL_PARAM_INTEGER)
  90. || !TEST_size_t_eq(p->data_size, sizeof(long int))
  91. || !TEST_true(OSSL_PARAM_get_long(p, &l))
  92. || !TEST_long_eq(l, 42)
  93. /* Check time_t */
  94. || !TEST_ptr(p = OSSL_PARAM_locate(params, "t"))
  95. || !TEST_str_eq(p->key, "t")
  96. || !TEST_uint_eq(p->data_type, OSSL_PARAM_INTEGER)
  97. || !TEST_size_t_eq(p->data_size, sizeof(time_t))
  98. || !TEST_true(OSSL_PARAM_get_time_t(p, &t))
  99. || !TEST_time_t_eq(t, 11224)
  100. /* Check double */
  101. || !TEST_ptr(p = OSSL_PARAM_locate(params, "d"))
  102. || !TEST_true(OSSL_PARAM_get_double(p, &d))
  103. || !TEST_str_eq(p->key, "d")
  104. || !TEST_uint_eq(p->data_type, OSSL_PARAM_REAL)
  105. || !TEST_size_t_eq(p->data_size, sizeof(double))
  106. || !TEST_double_eq(d, 1.61803398875)
  107. /* Check UTF8 string */
  108. || !TEST_ptr(p = OSSL_PARAM_locate(params, "utf8_s"))
  109. || !TEST_str_eq(p->data, "foo")
  110. || !TEST_true(OSSL_PARAM_get_utf8_string(p, &utf, 0))
  111. || !TEST_str_eq(utf, "foo")
  112. /* Check UTF8 pointer */
  113. || !TEST_ptr(p = OSSL_PARAM_locate(params, "utf8_p"))
  114. || !TEST_true(OSSL_PARAM_get_utf8_ptr(p, &cutf))
  115. || !TEST_str_eq(cutf, "bar-boom")
  116. /* Check BN */
  117. || !TEST_ptr(p = OSSL_PARAM_locate(params, "bignumber"))
  118. || !TEST_str_eq(p->key, "bignumber")
  119. || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
  120. || !TEST_true(OSSL_PARAM_get_BN(p, &bn_res))
  121. || !TEST_int_eq(BN_cmp(bn_res, bn), 0))
  122. goto err;
  123. res = 1;
  124. err:
  125. OPENSSL_free(p1);
  126. if (params != params_blt)
  127. OPENSSL_free(params);
  128. OSSL_PARAM_free(params_blt);
  129. OSSL_PARAM_BLD_free(bld);
  130. OPENSSL_free(utf);
  131. BN_free(bn);
  132. BN_free(bn_res);
  133. return res;
  134. }
  135. static int template_private_test(int tstid)
  136. {
  137. int *data1 = NULL, *data2 = NULL, j;
  138. const int data1_num = 12;
  139. const int data1_size = data1_num * sizeof(int);
  140. const int data2_num = 5;
  141. const int data2_size = data2_num * sizeof(int);
  142. OSSL_PARAM_BLD *bld = NULL;
  143. OSSL_PARAM *params = NULL, *params_blt = NULL, *p1 = NULL, *p;
  144. unsigned int i;
  145. unsigned long int l;
  146. uint32_t i32;
  147. uint64_t i64;
  148. size_t st;
  149. BIGNUM *bn = NULL, *bn_res = NULL;
  150. int res = 0;
  151. if (!TEST_ptr(data1 = OPENSSL_secure_malloc(data1_size))
  152. || !TEST_ptr(data2 = OPENSSL_secure_malloc(data2_size))
  153. || !TEST_ptr(bld = OSSL_PARAM_BLD_new()))
  154. goto err;
  155. for (j = 0; j < data1_num; j++)
  156. data1[j] = -16 * j;
  157. for (j = 0; j < data2_num; j++)
  158. data2[j] = 2 * j;
  159. if (!TEST_true(OSSL_PARAM_BLD_push_uint(bld, "i", 6))
  160. || !TEST_true(OSSL_PARAM_BLD_push_ulong(bld, "l", 42))
  161. || !TEST_true(OSSL_PARAM_BLD_push_uint32(bld, "i32", 1532))
  162. || !TEST_true(OSSL_PARAM_BLD_push_uint64(bld, "i64", 9999999))
  163. || !TEST_true(OSSL_PARAM_BLD_push_size_t(bld, "st", 65537))
  164. || !TEST_ptr(bn = BN_secure_new())
  165. || !TEST_true(BN_set_word(bn, 1729))
  166. || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, "bignumber", bn))
  167. || !TEST_true(OSSL_PARAM_BLD_push_octet_string(bld, "oct_s", data1,
  168. data1_size))
  169. || !TEST_true(OSSL_PARAM_BLD_push_octet_ptr(bld, "oct_p", data2,
  170. data2_size))
  171. || !TEST_ptr(params_blt = OSSL_PARAM_BLD_to_param(bld)))
  172. goto err;
  173. switch(tstid) {
  174. case 0:
  175. params = params_blt;
  176. break;
  177. case 1:
  178. params = OSSL_PARAM_merge(params_blt, params_empty);
  179. break;
  180. case 2:
  181. params = OSSL_PARAM_dup(params_blt);
  182. break;
  183. case 3:
  184. p1 = OSSL_PARAM_merge(params_blt, params_empty);
  185. params = OSSL_PARAM_dup(p1);
  186. break;
  187. default:
  188. p1 = OSSL_PARAM_dup(params_blt);
  189. params = OSSL_PARAM_merge(p1, params_empty);
  190. break;
  191. }
  192. /* Check unsigned int */
  193. if (!TEST_ptr(p = OSSL_PARAM_locate(params, "i"))
  194. || !TEST_false(CRYPTO_secure_allocated(p->data))
  195. || !TEST_true(OSSL_PARAM_get_uint(p, &i))
  196. || !TEST_str_eq(p->key, "i")
  197. || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
  198. || !TEST_size_t_eq(p->data_size, sizeof(int))
  199. || !TEST_uint_eq(i, 6)
  200. /* Check unsigned int32 */
  201. || !TEST_ptr(p = OSSL_PARAM_locate(params, "i32"))
  202. || !TEST_false(CRYPTO_secure_allocated(p->data))
  203. || !TEST_true(OSSL_PARAM_get_uint32(p, &i32))
  204. || !TEST_str_eq(p->key, "i32")
  205. || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
  206. || !TEST_size_t_eq(p->data_size, sizeof(int32_t))
  207. || !TEST_uint_eq((unsigned int)i32, 1532)
  208. /* Check unsigned int64 */
  209. || !TEST_ptr(p = OSSL_PARAM_locate(params, "i64"))
  210. || !TEST_false(CRYPTO_secure_allocated(p->data))
  211. || !TEST_str_eq(p->key, "i64")
  212. || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
  213. || !TEST_size_t_eq(p->data_size, sizeof(int64_t))
  214. || !TEST_true(OSSL_PARAM_get_uint64(p, &i64))
  215. || !TEST_ulong_eq((unsigned long)i64, 9999999)
  216. /* Check unsigned long int */
  217. || !TEST_ptr(p = OSSL_PARAM_locate(params, "l"))
  218. || !TEST_false(CRYPTO_secure_allocated(p->data))
  219. || !TEST_str_eq(p->key, "l")
  220. || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
  221. || !TEST_size_t_eq(p->data_size, sizeof(unsigned long int))
  222. || !TEST_true(OSSL_PARAM_get_ulong(p, &l))
  223. || !TEST_ulong_eq(l, 42)
  224. /* Check size_t */
  225. || !TEST_ptr(p = OSSL_PARAM_locate(params, "st"))
  226. || !TEST_false(CRYPTO_secure_allocated(p->data))
  227. || !TEST_str_eq(p->key, "st")
  228. || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
  229. || !TEST_size_t_eq(p->data_size, sizeof(size_t))
  230. || !TEST_true(OSSL_PARAM_get_size_t(p, &st))
  231. || !TEST_size_t_eq(st, 65537)
  232. /* Check octet string */
  233. || !TEST_ptr(p = OSSL_PARAM_locate(params, "oct_s"))
  234. || !TEST_true(CRYPTO_secure_allocated(p->data))
  235. || !TEST_str_eq(p->key, "oct_s")
  236. || !TEST_uint_eq(p->data_type, OSSL_PARAM_OCTET_STRING)
  237. || !TEST_mem_eq(p->data, p->data_size, data1, data1_size)
  238. /* Check octet pointer */
  239. || !TEST_ptr(p = OSSL_PARAM_locate(params, "oct_p"))
  240. || !TEST_false(CRYPTO_secure_allocated(p->data))
  241. || !TEST_true(CRYPTO_secure_allocated(*(void **)p->data))
  242. || !TEST_str_eq(p->key, "oct_p")
  243. || !TEST_uint_eq(p->data_type, OSSL_PARAM_OCTET_PTR)
  244. || !TEST_mem_eq(*(void **)p->data, p->data_size, data2, data2_size)
  245. /* Check BN */
  246. || !TEST_ptr(p = OSSL_PARAM_locate(params, "bignumber"))
  247. || !TEST_true(CRYPTO_secure_allocated(p->data))
  248. || !TEST_str_eq(p->key, "bignumber")
  249. || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
  250. || !TEST_true(OSSL_PARAM_get_BN(p, &bn_res))
  251. || !TEST_int_eq(BN_get_flags(bn, BN_FLG_SECURE), BN_FLG_SECURE)
  252. || !TEST_int_eq(BN_cmp(bn_res, bn), 0))
  253. goto err;
  254. res = 1;
  255. err:
  256. OSSL_PARAM_free(p1);
  257. if (params != params_blt)
  258. OSSL_PARAM_free(params);
  259. OSSL_PARAM_free(params_blt);
  260. OSSL_PARAM_BLD_free(bld);
  261. OPENSSL_secure_free(data1);
  262. OPENSSL_secure_free(data2);
  263. BN_free(bn);
  264. BN_free(bn_res);
  265. return res;
  266. }
  267. static int builder_limit_test(void)
  268. {
  269. const int n = 100;
  270. char names[100][3];
  271. OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
  272. OSSL_PARAM *params = NULL;
  273. int i, res = 0;
  274. if (!TEST_ptr(bld))
  275. goto err;
  276. for (i = 0; i < n; i++) {
  277. names[i][0] = 'A' + (i / 26) - 1;
  278. names[i][1] = 'a' + (i % 26) - 1;
  279. names[i][2] = '\0';
  280. if (!TEST_true(OSSL_PARAM_BLD_push_int(bld, names[i], 3 * i + 1)))
  281. goto err;
  282. }
  283. if (!TEST_ptr(params = OSSL_PARAM_BLD_to_param(bld)))
  284. goto err;
  285. /* Count the elements in the params arrary, expecting n */
  286. for (i = 0; params[i].key != NULL; i++);
  287. if (!TEST_int_eq(i, n))
  288. goto err;
  289. /* Verify that the build, cleared the builder structure */
  290. OSSL_PARAM_free(params);
  291. params = NULL;
  292. if (!TEST_true(OSSL_PARAM_BLD_push_int(bld, "g", 2))
  293. || !TEST_ptr(params = OSSL_PARAM_BLD_to_param(bld)))
  294. goto err;
  295. /* Count the elements in the params arrary, expecting 1 */
  296. for (i = 0; params[i].key != NULL; i++);
  297. if (!TEST_int_eq(i, 1))
  298. goto err;
  299. res = 1;
  300. err:
  301. OSSL_PARAM_free(params);
  302. OSSL_PARAM_BLD_free(bld);
  303. return res;
  304. }
  305. static int builder_merge_test(void)
  306. {
  307. static int data1[] = { 2, 3, 5, 7, 11, 15, 17 };
  308. static unsigned char data2[] = { 2, 4, 6, 8, 10 };
  309. OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
  310. OSSL_PARAM_BLD *bld2 = OSSL_PARAM_BLD_new();
  311. OSSL_PARAM *params = NULL, *params_blt = NULL, *params2_blt = NULL, *p;
  312. unsigned int i;
  313. unsigned long int l;
  314. uint32_t i32;
  315. uint64_t i64;
  316. size_t st;
  317. BIGNUM *bn_priv = NULL, *bn_priv_res = NULL;
  318. BIGNUM *bn_pub = NULL, *bn_pub_res = NULL;
  319. int res = 0;
  320. if (!TEST_ptr(bld)
  321. || !TEST_true(OSSL_PARAM_BLD_push_uint(bld, "i", 6))
  322. || !TEST_true(OSSL_PARAM_BLD_push_ulong(bld, "l", 42))
  323. || !TEST_true(OSSL_PARAM_BLD_push_uint32(bld, "i32", 1532))
  324. || !TEST_true(OSSL_PARAM_BLD_push_uint64(bld, "i64", 9999999))
  325. || !TEST_true(OSSL_PARAM_BLD_push_size_t(bld, "st", 65537))
  326. || !TEST_ptr(bn_priv = BN_secure_new())
  327. || !TEST_true(BN_set_word(bn_priv, 1729))
  328. || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, "bignumber_priv", bn_priv))
  329. || !TEST_ptr(params_blt = OSSL_PARAM_BLD_to_param(bld)))
  330. goto err;
  331. if (!TEST_ptr(bld2)
  332. || !TEST_true(OSSL_PARAM_BLD_push_octet_string(bld2, "oct_s", data1,
  333. sizeof(data1)))
  334. || !TEST_true(OSSL_PARAM_BLD_push_octet_ptr(bld2, "oct_p", data2,
  335. sizeof(data2)))
  336. || !TEST_true(OSSL_PARAM_BLD_push_uint32(bld2, "i32", 99))
  337. || !TEST_ptr(bn_pub = BN_new())
  338. || !TEST_true(BN_set_word(bn_pub, 0x42))
  339. || !TEST_true(OSSL_PARAM_BLD_push_BN(bld2, "bignumber_pub", bn_pub))
  340. || !TEST_ptr(params2_blt = OSSL_PARAM_BLD_to_param(bld2)))
  341. goto err;
  342. if (!TEST_ptr(params = OSSL_PARAM_merge(params_blt, params2_blt)))
  343. goto err;
  344. if (!TEST_ptr(p = OSSL_PARAM_locate(params, "i"))
  345. || !TEST_true(OSSL_PARAM_get_uint(p, &i))
  346. || !TEST_str_eq(p->key, "i")
  347. || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
  348. || !TEST_size_t_eq(p->data_size, sizeof(int))
  349. || !TEST_uint_eq(i, 6)
  350. /* Check unsigned int32 */
  351. || !TEST_ptr(p = OSSL_PARAM_locate(params, "i32"))
  352. || !TEST_true(OSSL_PARAM_get_uint32(p, &i32))
  353. || !TEST_str_eq(p->key, "i32")
  354. || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
  355. || !TEST_size_t_eq(p->data_size, sizeof(int32_t))
  356. || !TEST_uint_eq((unsigned int)i32, 99)
  357. /* Check unsigned int64 */
  358. || !TEST_ptr(p = OSSL_PARAM_locate(params, "i64"))
  359. || !TEST_str_eq(p->key, "i64")
  360. || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
  361. || !TEST_size_t_eq(p->data_size, sizeof(int64_t))
  362. || !TEST_true(OSSL_PARAM_get_uint64(p, &i64))
  363. || !TEST_ulong_eq((unsigned long)i64, 9999999)
  364. /* Check unsigned long int */
  365. || !TEST_ptr(p = OSSL_PARAM_locate(params, "l"))
  366. || !TEST_str_eq(p->key, "l")
  367. || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
  368. || !TEST_size_t_eq(p->data_size, sizeof(unsigned long int))
  369. || !TEST_true(OSSL_PARAM_get_ulong(p, &l))
  370. || !TEST_ulong_eq(l, 42)
  371. /* Check size_t */
  372. || !TEST_ptr(p = OSSL_PARAM_locate(params, "st"))
  373. || !TEST_str_eq(p->key, "st")
  374. || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
  375. || !TEST_size_t_eq(p->data_size, sizeof(size_t))
  376. || !TEST_true(OSSL_PARAM_get_size_t(p, &st))
  377. || !TEST_size_t_eq(st, 65537)
  378. /* Check octet string */
  379. || !TEST_ptr(p = OSSL_PARAM_locate(params, "oct_s"))
  380. || !TEST_str_eq(p->key, "oct_s")
  381. || !TEST_uint_eq(p->data_type, OSSL_PARAM_OCTET_STRING)
  382. || !TEST_mem_eq(p->data, p->data_size, data1, sizeof(data1))
  383. /* Check octet pointer */
  384. || !TEST_ptr(p = OSSL_PARAM_locate(params, "oct_p"))
  385. || !TEST_str_eq(p->key, "oct_p")
  386. || !TEST_uint_eq(p->data_type, OSSL_PARAM_OCTET_PTR)
  387. || !TEST_mem_eq(*(void **)p->data, p->data_size, data2, sizeof(data2))
  388. /* Check BN */
  389. || !TEST_ptr(p = OSSL_PARAM_locate(params, "bignumber_pub"))
  390. || !TEST_str_eq(p->key, "bignumber_pub")
  391. || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
  392. || !TEST_true(OSSL_PARAM_get_BN(p, &bn_pub_res))
  393. || !TEST_int_eq(BN_cmp(bn_pub_res, bn_pub), 0)
  394. || !TEST_ptr(p = OSSL_PARAM_locate(params, "bignumber_priv"))
  395. || !TEST_str_eq(p->key, "bignumber_priv")
  396. || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
  397. || !TEST_true(OSSL_PARAM_get_BN(p, &bn_priv_res))
  398. || !TEST_int_eq(BN_cmp(bn_priv_res, bn_priv), 0))
  399. goto err;
  400. res = 1;
  401. err:
  402. OSSL_PARAM_free(params);
  403. OSSL_PARAM_free(params_blt);
  404. OSSL_PARAM_free(params2_blt);
  405. OSSL_PARAM_BLD_free(bld);
  406. OSSL_PARAM_BLD_free(bld2);
  407. BN_free(bn_priv);
  408. BN_free(bn_priv_res);
  409. BN_free(bn_pub);
  410. BN_free(bn_pub_res);
  411. return res;
  412. }
  413. int setup_tests(void)
  414. {
  415. ADD_ALL_TESTS(template_public_test, 5);
  416. /* Only run the secure memory testing if we have secure memory available */
  417. if (CRYPTO_secure_malloc_init(1<<16, 16))
  418. ADD_ALL_TESTS(template_private_test, 5);
  419. ADD_TEST(builder_limit_test);
  420. ADD_TEST(builder_merge_test);
  421. return 1;
  422. }