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