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