Raise an error on syscall failure in tls_retry_write_records
[openssl.git] / test / param_build_test.c
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
11 #include <string.h>
12 #include <openssl/params.h>
13 #include <openssl/param_build.h>
14 #include "internal/nelem.h"
15 #include "testutil.h"
16
17 static const OSSL_PARAM params_empty[] = { OSSL_PARAM_END };
18
19 static int template_public_test(int tstid)
20 {
21     OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
22     OSSL_PARAM *params = NULL, *params_blt = NULL, *p1 = NULL, *p;
23     BIGNUM *pbn = NULL, *pbn_res = NULL;
24     BIGNUM *nbn = NULL, *nbn_res = NULL;
25     int i;
26     long int l;
27     int32_t i32;
28     int64_t i64;
29     double d;
30     time_t t;
31     char *utf = NULL;
32     const char *cutf;
33     int res = 0;
34
35     if (!TEST_ptr(bld)
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))
39         || !TEST_true(OSSL_PARAM_BLD_push_time_t(bld, "t", 11224))
40         || !TEST_true(OSSL_PARAM_BLD_push_double(bld, "d", 1.61803398875))
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))
48         || !TEST_true(OSSL_PARAM_BLD_push_utf8_string(bld, "utf8_s", "foo",
49                                                       sizeof("foo")))
50         || !TEST_true(OSSL_PARAM_BLD_push_utf8_ptr(bld, "utf8_p", "bar-boom",
51                                                    0))
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
56     switch (tstid) {
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"))
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)
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)
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))
125         || !TEST_str_eq(cutf, "bar-boom")
126         /* Check BN (positive BN becomes unsigned integer) */
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)
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))
138         goto err;
139     res = 1;
140 err:
141     OPENSSL_free(p1);
142     if (params != params_blt)
143         OPENSSL_free(params);
144     OSSL_PARAM_free(params_blt);
145     OSSL_PARAM_BLD_free(bld);
146     OPENSSL_free(utf);
147     BN_free(pbn);
148     BN_free(pbn_res);
149     BN_free(nbn);
150     BN_free(nbn_res);
151     return res;
152 }
153
154 static int template_private_test(int tstid)
155 {
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;
162     OSSL_PARAM *params = NULL, *params_blt = NULL, *p1 = NULL, *p;
163     unsigned int i;
164     unsigned long int l;
165     uint32_t i32;
166     uint64_t i64;
167     size_t st;
168     BIGNUM *pbn = NULL, *pbn_res = NULL;
169     BIGNUM *nbn = NULL, *nbn_res = NULL;
170     int res = 0;
171
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))
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))
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))
194         || !TEST_true(OSSL_PARAM_BLD_push_octet_string(bld, "oct_s", data1,
195                                                        data1_size))
196         || !TEST_true(OSSL_PARAM_BLD_push_octet_ptr(bld, "oct_p", data2,
197                                                     data2_size))
198         || !TEST_ptr(params_blt = OSSL_PARAM_BLD_to_param(bld)))
199         goto err;
200     switch (tstid) {
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"))
221         || !TEST_false(CRYPTO_secure_allocated(p->data))
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"))
229         || !TEST_false(CRYPTO_secure_allocated(p->data))
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"))
237         || !TEST_false(CRYPTO_secure_allocated(p->data))
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"))
245         || !TEST_false(CRYPTO_secure_allocated(p->data))
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"))
253         || !TEST_false(CRYPTO_secure_allocated(p->data))
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"))
261         || !TEST_true(CRYPTO_secure_allocated(p->data))
262         || !TEST_str_eq(p->key, "oct_s")
263         || !TEST_uint_eq(p->data_type, OSSL_PARAM_OCTET_STRING)
264         || !TEST_mem_eq(p->data, p->data_size, data1, data1_size)
265         /* Check octet pointer */
266         || !TEST_ptr(p = OSSL_PARAM_locate(params, "oct_p"))
267         || !TEST_false(CRYPTO_secure_allocated(p->data))
268         || !TEST_true(CRYPTO_secure_allocated(*(void **)p->data))
269         || !TEST_str_eq(p->key, "oct_p")
270         || !TEST_uint_eq(p->data_type, OSSL_PARAM_OCTET_PTR)
271         || !TEST_mem_eq(*(void **)p->data, p->data_size, data2, data2_size)
272         /* Check BN (positive BN becomes unsigned integer) */
273         || !TEST_ptr(p = OSSL_PARAM_locate(params, "bignumber"))
274         || !TEST_true(CRYPTO_secure_allocated(p->data))
275         || !TEST_str_eq(p->key, "bignumber")
276         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
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))
288         goto err;
289     res = 1;
290 err:
291     OSSL_PARAM_free(p1);
292     if (params != params_blt)
293         OSSL_PARAM_free(params);
294     OSSL_PARAM_free(params_blt);
295     OSSL_PARAM_BLD_free(bld);
296     OPENSSL_secure_free(data1);
297     OPENSSL_secure_free(data2);
298     BN_free(pbn);
299     BN_free(pbn_res);
300     BN_free(nbn);
301     BN_free(nbn_res);
302     return res;
303 }
304
305 static 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;
315
316     for (i = 0; i < n; i++) {
317         names[i][0] = 'A' + (i / 26) - 1;
318         names[i][1] = 'a' + (i % 26) - 1;
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;
325     /* Count the elements in the params array, expecting n */
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 */
331     OSSL_PARAM_free(params);
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;
337     /* Count the elements in the params array, expecting 1 */
338     for (i = 0; params[i].key != NULL; i++);
339     if (!TEST_int_eq(i, 1))
340         goto err;
341     res = 1;
342 err:
343     OSSL_PARAM_free(params);
344     OSSL_PARAM_BLD_free(bld);
345     return res;
346 }
347
348 static 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;
448 err:
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
461 int setup_tests(void)
462 {
463     ADD_ALL_TESTS(template_public_test, 5);
464     /* Only run the secure memory testing if we have secure memory available */
465     if (CRYPTO_secure_malloc_init(1<<16, 16))
466         ADD_ALL_TESTS(template_private_test, 5);
467     ADD_TEST(builder_limit_test);
468     ADD_TEST(builder_merge_test);
469     return 1;
470 }