param_build_test.c 19 KB

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