2 * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
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
13 #include "internal/nelem.h"
14 #include "internal/endian.h"
15 #include <openssl/params.h>
16 #include <openssl/bn.h>
18 /* The maximum size of the static buffers used to test most things */
21 static void swap_copy(unsigned char *out
, const void *in
, size_t len
)
25 for (j
= 0; j
< len
; j
++)
26 out
[j
] = ((unsigned char *)in
)[len
- j
- 1];
30 * A memory copy that converts the native byte ordering either to or from
31 * little endian format.
33 * On a little endian machine copying either is just a memcpy(3), on a
34 * big endian machine copying from native to or from little endian involves
37 static void le_copy(unsigned char *out
, const void *in
, size_t len
)
44 swap_copy(out
, in
, len
);
49 unsigned char value
[MAX_LEN
];
51 { 4, { 0x38, 0x27, 0xbf, 0x3b } },
52 { 4, { 0x9f, 0x26, 0x48, 0x22 } },
53 { 8, { 0x59, 0xb2, 0x1a, 0xe9, 0x2a, 0xd8, 0x46, 0x40 } },
54 { 8, { 0xb4, 0xae, 0xbd, 0xb4, 0xdd, 0x04, 0xb1, 0x4c } },
55 { 16, { 0x61, 0xe8, 0x7e, 0x31, 0xe9, 0x33, 0x83, 0x3d,
56 0x87, 0x99, 0xc7, 0xd8, 0x5d, 0xa9, 0x8b, 0x42 } },
57 { 16, { 0xee, 0x6e, 0x8b, 0xc3, 0xec, 0xcf, 0x37, 0xcc,
58 0x89, 0x67, 0xf2, 0x68, 0x33, 0xa0, 0x14, 0xb0 } },
61 static int test_param_type_extra(OSSL_PARAM
*param
, const unsigned char *cmp
,
67 unsigned char buf
[MAX_LEN
];
68 const int bit32
= param
->data_size
== sizeof(int32_t);
69 const int sizet
= bit32
&& sizeof(size_t) > sizeof(int32_t);
70 const int signd
= param
->data_type
== OSSL_PARAM_INTEGER
;
73 * Set the unmodified sentinal directly because there is no param array
76 param
->return_size
= OSSL_PARAM_UNMODIFIED
;
78 if ((bit32
&& !TEST_true(OSSL_PARAM_get_int32(param
, &i32
)))
79 || !TEST_true(OSSL_PARAM_get_int64(param
, &i64
)))
83 && !TEST_true(OSSL_PARAM_get_uint32(param
, (uint32_t *)&i32
)))
84 || !TEST_true(OSSL_PARAM_get_uint64(param
, (uint64_t *)&i64
))
85 || (sizet
&& !TEST_true(OSSL_PARAM_get_size_t(param
, &s
))))
88 if (!TEST_false(OSSL_PARAM_modified(param
)))
91 /* Check signed types */
93 le_copy(buf
, &i32
, sizeof(i32
));
94 sz
= sizeof(i32
) < width
? sizeof(i32
) : width
;
95 if (!TEST_mem_eq(buf
, sz
, cmp
, sz
))
98 le_copy(buf
, &i64
, sizeof(i64
));
99 sz
= sizeof(i64
) < width
? sizeof(i64
) : width
;
100 if (!TEST_mem_eq(buf
, sz
, cmp
, sz
))
102 if (sizet
&& !signd
) {
103 le_copy(buf
, &s
, sizeof(s
));
104 sz
= sizeof(s
) < width
? sizeof(s
) : width
;
105 if (!TEST_mem_eq(buf
, sz
, cmp
, sz
))
109 /* Check a widening write if possible */
110 if (sizeof(size_t) > width
) {
112 if (!TEST_true(OSSL_PARAM_set_int32(param
, 12345))
113 || !TEST_true(OSSL_PARAM_get_int64(param
, &i64
))
114 || !TEST_size_t_eq((size_t)i64
, 12345))
117 if (!TEST_true(OSSL_PARAM_set_uint32(param
, 12345))
118 || !TEST_true(OSSL_PARAM_get_uint64(param
, (uint64_t *)&i64
))
119 || !TEST_size_t_eq((size_t)i64
, 12345))
122 if (!TEST_true(OSSL_PARAM_modified(param
)))
129 * The test cases for each of the bastic integral types are similar.
130 * For each type, a param of that type is set and an attempt to read it
131 * get is made. Finally, the above function is called to verify that
132 * the params can be read as other types.
134 * All the real work is done via byte buffers which are converted to machine
135 * byte order and to little endian for comparisons. Narrower values are best
136 * compared using little endian because their values and positions don't
140 static int test_param_int(int n
)
143 unsigned char buf
[MAX_LEN
], cmp
[sizeof(int)];
144 const size_t len
= raw_values
[n
].len
>= sizeof(int) ?
145 sizeof(int) : raw_values
[n
].len
;
146 OSSL_PARAM param
= OSSL_PARAM_int("a", NULL
);
148 memset(buf
, 0, sizeof(buf
));
149 le_copy(buf
, raw_values
[n
].value
, sizeof(in
));
150 memcpy(&in
, buf
, sizeof(in
));
152 if (!TEST_true(OSSL_PARAM_set_int(¶m
, in
)))
154 le_copy(cmp
, &out
, sizeof(out
));
155 if (!TEST_mem_eq(cmp
, len
, raw_values
[n
].value
, len
))
158 if (!TEST_true(OSSL_PARAM_get_int(¶m
, &in
)))
160 le_copy(cmp
, &in
, sizeof(in
));
161 if (!TEST_mem_eq(cmp
, sizeof(in
), raw_values
[n
].value
, sizeof(in
)))
164 return test_param_type_extra(¶m
, raw_values
[n
].value
, sizeof(int));
167 static int test_param_long(int n
)
170 unsigned char buf
[MAX_LEN
], cmp
[sizeof(long int)];
171 const size_t len
= raw_values
[n
].len
>= sizeof(long int)
172 ? sizeof(long int) : raw_values
[n
].len
;
173 OSSL_PARAM param
= OSSL_PARAM_long("a", NULL
);
175 memset(buf
, 0, sizeof(buf
));
176 le_copy(buf
, raw_values
[n
].value
, sizeof(in
));
177 memcpy(&in
, buf
, sizeof(in
));
179 if (!TEST_true(OSSL_PARAM_set_long(¶m
, in
)))
181 le_copy(cmp
, &out
, sizeof(out
));
182 if (!TEST_mem_eq(cmp
, len
, raw_values
[n
].value
, len
))
185 if (!TEST_true(OSSL_PARAM_get_long(¶m
, &in
)))
187 le_copy(cmp
, &in
, sizeof(in
));
188 if (!TEST_mem_eq(cmp
, sizeof(in
), raw_values
[n
].value
, sizeof(in
)))
191 return test_param_type_extra(¶m
, raw_values
[n
].value
, sizeof(long int));
194 static int test_param_uint(int n
)
196 unsigned int in
, out
;
197 unsigned char buf
[MAX_LEN
], cmp
[sizeof(unsigned int)];
198 const size_t len
= raw_values
[n
].len
>= sizeof(unsigned int) ? sizeof(unsigned int) : raw_values
[n
].len
;
199 OSSL_PARAM param
= OSSL_PARAM_uint("a", NULL
);
201 memset(buf
, 0, sizeof(buf
));
202 le_copy(buf
, raw_values
[n
].value
, sizeof(in
));
203 memcpy(&in
, buf
, sizeof(in
));
205 if (!TEST_true(OSSL_PARAM_set_uint(¶m
, in
)))
207 le_copy(cmp
, &out
, sizeof(out
));
208 if (!TEST_mem_eq(cmp
, len
, raw_values
[n
].value
, len
))
211 if (!TEST_true(OSSL_PARAM_get_uint(¶m
, &in
)))
213 le_copy(cmp
, &in
, sizeof(in
));
214 if (!TEST_mem_eq(cmp
, sizeof(in
), raw_values
[n
].value
, sizeof(in
)))
217 return test_param_type_extra(¶m
, raw_values
[n
].value
, sizeof(unsigned int));
220 static int test_param_ulong(int n
)
222 unsigned long int in
, out
;
223 unsigned char buf
[MAX_LEN
], cmp
[sizeof(unsigned long int)];
224 const size_t len
= raw_values
[n
].len
>= sizeof(unsigned long int)
225 ? sizeof(unsigned long int) : raw_values
[n
].len
;
226 OSSL_PARAM param
= OSSL_PARAM_ulong("a", NULL
);
228 memset(buf
, 0, sizeof(buf
));
229 le_copy(buf
, raw_values
[n
].value
, sizeof(in
));
230 memcpy(&in
, buf
, sizeof(in
));
232 if (!TEST_true(OSSL_PARAM_set_ulong(¶m
, in
)))
234 le_copy(cmp
, &out
, sizeof(out
));
235 if (!TEST_mem_eq(cmp
, len
, raw_values
[n
].value
, len
))
238 if (!TEST_true(OSSL_PARAM_get_ulong(¶m
, &in
)))
240 le_copy(cmp
, &in
, sizeof(in
));
241 if (!TEST_mem_eq(cmp
, sizeof(in
), raw_values
[n
].value
, sizeof(in
)))
244 return test_param_type_extra(¶m
, raw_values
[n
].value
, sizeof(unsigned long int));
247 static int test_param_int32(int n
)
250 unsigned char buf
[MAX_LEN
], cmp
[sizeof(int32_t)];
251 const size_t len
= raw_values
[n
].len
>= sizeof(int32_t)
252 ? sizeof(int32_t) : raw_values
[n
].len
;
253 OSSL_PARAM param
= OSSL_PARAM_int32("a", NULL
);
255 memset(buf
, 0, sizeof(buf
));
256 le_copy(buf
, raw_values
[n
].value
, sizeof(in
));
257 memcpy(&in
, buf
, sizeof(in
));
259 if (!TEST_true(OSSL_PARAM_set_int32(¶m
, in
)))
261 le_copy(cmp
, &out
, sizeof(out
));
262 if (!TEST_mem_eq(cmp
, len
, raw_values
[n
].value
, len
))
265 if (!TEST_true(OSSL_PARAM_get_int32(¶m
, &in
)))
267 le_copy(cmp
, &in
, sizeof(in
));
268 if (!TEST_mem_eq(cmp
, sizeof(in
), raw_values
[n
].value
, sizeof(in
)))
271 return test_param_type_extra(¶m
, raw_values
[n
].value
, sizeof(int32_t));
274 static int test_param_uint32(int n
)
277 unsigned char buf
[MAX_LEN
], cmp
[sizeof(uint32_t)];
278 const size_t len
= raw_values
[n
].len
>= sizeof(uint32_t)
279 ? sizeof(uint32_t) : raw_values
[n
].len
;
280 OSSL_PARAM param
= OSSL_PARAM_uint32("a", NULL
);
282 memset(buf
, 0, sizeof(buf
));
283 le_copy(buf
, raw_values
[n
].value
, sizeof(in
));
284 memcpy(&in
, buf
, sizeof(in
));
286 if (!TEST_true(OSSL_PARAM_set_uint32(¶m
, in
)))
288 le_copy(cmp
, &out
, sizeof(out
));
289 if (!TEST_mem_eq(cmp
, len
, raw_values
[n
].value
, len
))
292 if (!TEST_true(OSSL_PARAM_get_uint32(¶m
, &in
)))
294 le_copy(cmp
, &in
, sizeof(in
));
295 if (!TEST_mem_eq(cmp
, sizeof(in
), raw_values
[n
].value
, sizeof(in
)))
298 return test_param_type_extra(¶m
, raw_values
[n
].value
, sizeof(uint32_t));
301 static int test_param_int64(int n
)
304 unsigned char buf
[MAX_LEN
], cmp
[sizeof(int64_t)];
305 const size_t len
= raw_values
[n
].len
>= sizeof(int64_t)
306 ? sizeof(int64_t) : raw_values
[n
].len
;
307 OSSL_PARAM param
= OSSL_PARAM_int64("a", NULL
);
309 memset(buf
, 0, sizeof(buf
));
310 le_copy(buf
, raw_values
[n
].value
, sizeof(in
));
311 memcpy(&in
, buf
, sizeof(in
));
313 if (!TEST_true(OSSL_PARAM_set_int64(¶m
, in
)))
315 le_copy(cmp
, &out
, sizeof(out
));
316 if (!TEST_mem_eq(cmp
, len
, raw_values
[n
].value
, len
))
319 if (!TEST_true(OSSL_PARAM_get_int64(¶m
, &in
)))
321 le_copy(cmp
, &in
, sizeof(in
));
322 if (!TEST_mem_eq(cmp
, sizeof(in
), raw_values
[n
].value
, sizeof(in
)))
325 return test_param_type_extra(¶m
, raw_values
[n
].value
, sizeof(int64_t));
328 static int test_param_uint64(int n
)
331 unsigned char buf
[MAX_LEN
], cmp
[sizeof(uint64_t)];
332 const size_t len
= raw_values
[n
].len
>= sizeof(uint64_t)
333 ? sizeof(uint64_t) : raw_values
[n
].len
;
334 OSSL_PARAM param
= OSSL_PARAM_uint64("a", NULL
);
336 memset(buf
, 0, sizeof(buf
));
337 le_copy(buf
, raw_values
[n
].value
, sizeof(in
));
338 memcpy(&in
, buf
, sizeof(in
));
340 if (!TEST_true(OSSL_PARAM_set_uint64(¶m
, in
)))
342 le_copy(cmp
, &out
, sizeof(out
));
343 if (!TEST_mem_eq(cmp
, len
, raw_values
[n
].value
, len
))
346 if (!TEST_true(OSSL_PARAM_get_uint64(¶m
, &in
)))
348 le_copy(cmp
, &in
, sizeof(in
));
349 if (!TEST_mem_eq(cmp
, sizeof(in
), raw_values
[n
].value
, sizeof(in
)))
352 return test_param_type_extra(¶m
, raw_values
[n
].value
, sizeof(uint64_t));
355 static int test_param_size_t(int n
)
358 unsigned char buf
[MAX_LEN
], cmp
[sizeof(size_t)];
359 const size_t len
= raw_values
[n
].len
>= sizeof(size_t)
360 ? sizeof(size_t) : raw_values
[n
].len
;
361 OSSL_PARAM param
= OSSL_PARAM_size_t("a", NULL
);
363 memset(buf
, 0, sizeof(buf
));
364 le_copy(buf
, raw_values
[n
].value
, sizeof(in
));
365 memcpy(&in
, buf
, sizeof(in
));
367 if (!TEST_true(OSSL_PARAM_set_size_t(¶m
, in
)))
369 le_copy(cmp
, &out
, sizeof(out
));
370 if (!TEST_mem_eq(cmp
, len
, raw_values
[n
].value
, len
))
373 if (!TEST_true(OSSL_PARAM_get_size_t(¶m
, &in
)))
375 le_copy(cmp
, &in
, sizeof(in
));
376 if (!TEST_mem_eq(cmp
, sizeof(in
), raw_values
[n
].value
, sizeof(in
)))
379 return test_param_type_extra(¶m
, raw_values
[n
].value
, sizeof(size_t));
382 static int test_param_time_t(int n
)
385 unsigned char buf
[MAX_LEN
], cmp
[sizeof(size_t)];
386 const size_t len
= raw_values
[n
].len
>= sizeof(size_t)
387 ? sizeof(time_t) : raw_values
[n
].len
;
388 OSSL_PARAM param
= OSSL_PARAM_time_t("a", NULL
);
390 memset(buf
, 0, sizeof(buf
));
391 le_copy(buf
, raw_values
[n
].value
, sizeof(in
));
392 memcpy(&in
, buf
, sizeof(in
));
394 if (!TEST_true(OSSL_PARAM_set_time_t(¶m
, in
)))
396 le_copy(cmp
, &out
, sizeof(out
));
397 if (!TEST_mem_eq(cmp
, len
, raw_values
[n
].value
, len
))
400 if (!TEST_true(OSSL_PARAM_get_time_t(¶m
, &in
)))
402 le_copy(cmp
, &in
, sizeof(in
));
403 if (!TEST_mem_eq(cmp
, sizeof(in
), raw_values
[n
].value
, sizeof(in
)))
406 return test_param_type_extra(¶m
, raw_values
[n
].value
, sizeof(size_t));
409 static int test_param_bignum(int n
)
411 unsigned char buf
[MAX_LEN
], bnbuf
[MAX_LEN
];
412 const size_t len
= raw_values
[n
].len
;
413 BIGNUM
*b
= NULL
, *c
= NULL
;
414 OSSL_PARAM param
= OSSL_PARAM_DEFN("bn", OSSL_PARAM_UNSIGNED_INTEGER
,
419 param
.data_size
= len
;
421 le_copy(buf
, raw_values
[n
].value
, len
);
422 if (!TEST_ptr(b
= BN_lebin2bn(raw_values
[n
].value
, (int)len
, NULL
)))
425 if (!TEST_true(OSSL_PARAM_set_BN(¶m
, b
))
426 || !TEST_mem_eq(bnbuf
, param
.return_size
, buf
, param
.return_size
))
428 param
.data_size
= param
.return_size
;
429 if (!TEST_true(OSSL_PARAM_get_BN(¶m
, &c
))
430 || !TEST_BN_eq(b
, c
))
440 static int test_param_real(void)
443 OSSL_PARAM param
= OSSL_PARAM_double("r", NULL
);
446 return TEST_true(OSSL_PARAM_set_double(¶m
, 3.14159))
447 && TEST_double_eq(p
, 3.14159);
450 static int test_param_construct(void)
452 static const char *int_names
[] = {
453 "int", "long", "int32", "int64"
455 static const char *uint_names
[] = {
456 "uint", "ulong", "uint32", "uint64", "size_t"
458 static const unsigned char bn_val
[16] = {
459 0xac, 0x75, 0x22, 0x7d, 0x81, 0x06, 0x7a, 0x23,
460 0xa6, 0xed, 0x87, 0xc7, 0xab, 0xf4, 0x73, 0x22
462 OSSL_PARAM params
[20];
463 char buf
[100], buf2
[100], *bufp
, *bufp2
;
464 unsigned char ubuf
[100];
465 void *vp
, *vpn
= NULL
, *vp2
;
467 int i
, n
= 0, ret
= 0;
470 unsigned long int ul
;
477 BIGNUM
*bn
= NULL
, *bn2
= NULL
;
479 params
[n
++] = OSSL_PARAM_construct_int("int", &i
);
480 params
[n
++] = OSSL_PARAM_construct_uint("uint", &u
);
481 params
[n
++] = OSSL_PARAM_construct_long("long", &l
);
482 params
[n
++] = OSSL_PARAM_construct_ulong("ulong", &ul
);
483 params
[n
++] = OSSL_PARAM_construct_int32("int32", &i32
);
484 params
[n
++] = OSSL_PARAM_construct_int64("int64", &i64
);
485 params
[n
++] = OSSL_PARAM_construct_uint32("uint32", &u32
);
486 params
[n
++] = OSSL_PARAM_construct_uint64("uint64", &u64
);
487 params
[n
++] = OSSL_PARAM_construct_size_t("size_t", &s
);
488 params
[n
++] = OSSL_PARAM_construct_double("double", &d
);
489 params
[n
++] = OSSL_PARAM_construct_BN("bignum", ubuf
, sizeof(ubuf
));
490 params
[n
++] = OSSL_PARAM_construct_utf8_string("utf8str", buf
, sizeof(buf
));
491 params
[n
++] = OSSL_PARAM_construct_octet_string("octstr", buf
, sizeof(buf
));
492 params
[n
++] = OSSL_PARAM_construct_utf8_ptr("utf8ptr", &bufp
, 0);
493 params
[n
++] = OSSL_PARAM_construct_octet_ptr("octptr", &vp
, 0);
494 params
[n
] = OSSL_PARAM_construct_end();
497 if (!TEST_ptr_null(OSSL_PARAM_locate(params
, "fnord")))
500 /* All signed integral types */
501 for (j
= 0; j
< OSSL_NELEM(int_names
); j
++) {
502 if (!TEST_ptr(cp
= OSSL_PARAM_locate(params
, int_names
[j
]))
503 || !TEST_true(OSSL_PARAM_set_int32(cp
, (int32_t)(3 + j
)))
504 || !TEST_true(OSSL_PARAM_get_int64(cp
, &i64
))
505 || !TEST_size_t_eq(cp
->data_size
, cp
->return_size
)
506 || !TEST_size_t_eq((size_t)i64
, 3 + j
)) {
507 TEST_note("iteration %zu var %s", j
+ 1, int_names
[j
]);
511 /* All unsigned integral types */
512 for (j
= 0; j
< OSSL_NELEM(uint_names
); j
++) {
513 if (!TEST_ptr(cp
= OSSL_PARAM_locate(params
, uint_names
[j
]))
514 || !TEST_true(OSSL_PARAM_set_uint32(cp
, (uint32_t)(3 + j
)))
515 || !TEST_true(OSSL_PARAM_get_uint64(cp
, &u64
))
516 || !TEST_size_t_eq(cp
->data_size
, cp
->return_size
)
517 || !TEST_size_t_eq((size_t)u64
, 3 + j
)) {
518 TEST_note("iteration %zu var %s", j
+ 1, uint_names
[j
]);
523 if (!TEST_ptr(cp
= OSSL_PARAM_locate(params
, "double"))
524 || !TEST_true(OSSL_PARAM_set_double(cp
, 3.14))
525 || !TEST_true(OSSL_PARAM_get_double(cp
, &d2
))
526 || !TEST_size_t_eq(cp
->return_size
, sizeof(double))
527 || !TEST_double_eq(d
, d2
))
531 if (!TEST_ptr(cp
= OSSL_PARAM_locate(params
, "utf8str"))
532 || !TEST_true(OSSL_PARAM_set_utf8_string(cp
, "abcdef"))
533 || !TEST_size_t_eq(cp
->return_size
, sizeof("abcdef"))
534 || !TEST_true(OSSL_PARAM_get_utf8_string(cp
, &bufp
, 0))
535 || !TEST_str_eq(bufp
, "abcdef"))
539 if (!TEST_true(OSSL_PARAM_get_utf8_string(cp
, &bufp
, sizeof(buf2
)))
540 || !TEST_str_eq(buf2
, "abcdef"))
544 if (!TEST_ptr(cp
= OSSL_PARAM_locate(params
, "utf8ptr"))
545 || !TEST_true(OSSL_PARAM_set_utf8_ptr(cp
, "tuvwxyz"))
546 || !TEST_size_t_eq(cp
->return_size
, sizeof("tuvwxyz"))
547 || !TEST_str_eq(bufp
, "tuvwxyz")
548 || !TEST_true(OSSL_PARAM_get_utf8_ptr(cp
, (const char **)&bufp2
))
549 || !TEST_ptr_eq(bufp2
, bufp
))
552 if (!TEST_ptr(cp
= OSSL_PARAM_locate(params
, "octstr"))
553 || !TEST_true(OSSL_PARAM_set_octet_string(cp
, "abcdefghi",
554 sizeof("abcdefghi")))
555 || !TEST_size_t_eq(cp
->return_size
, sizeof("abcdefghi")))
557 /* Match the return size to avoid trailing garbage bytes */
558 cp
->data_size
= cp
->return_size
;
559 if (!TEST_true(OSSL_PARAM_get_octet_string(cp
, &vpn
, 0, &s
))
560 || !TEST_size_t_eq(s
, sizeof("abcdefghi"))
561 || !TEST_mem_eq(vpn
, sizeof("abcdefghi"),
562 "abcdefghi", sizeof("abcdefghi")))
565 if (!TEST_true(OSSL_PARAM_get_octet_string(cp
, &vp
, sizeof(buf2
), &s
))
566 || !TEST_size_t_eq(s
, sizeof("abcdefghi"))
567 || !TEST_mem_eq(vp
, sizeof("abcdefghi"),
568 "abcdefghi", sizeof("abcdefghi")))
572 if (!TEST_ptr(cp
= OSSL_PARAM_locate(params
, "octptr"))
573 || !TEST_true(OSSL_PARAM_set_octet_ptr(cp
, &ul
, sizeof(ul
)))
574 || !TEST_size_t_eq(cp
->return_size
, sizeof(ul
))
575 || !TEST_ptr_eq(vp
, &ul
))
577 /* Match the return size to avoid trailing garbage bytes */
578 cp
->data_size
= cp
->return_size
;
579 if (!TEST_true(OSSL_PARAM_get_octet_ptr(cp
, (const void **)&vp2
, &k
))
580 || !TEST_size_t_eq(k
, sizeof(ul
))
581 || !TEST_ptr_eq(vp2
, vp
))
584 if (!TEST_ptr(cp
= OSSL_PARAM_locate(params
, "bignum"))
585 || !TEST_ptr(bn
= BN_lebin2bn(bn_val
, (int)sizeof(bn_val
), NULL
))
586 || !TEST_true(OSSL_PARAM_set_BN(cp
, bn
))
587 || !TEST_size_t_eq(cp
->data_size
, cp
->return_size
))
589 /* Match the return size to avoid trailing garbage bytes */
590 cp
->data_size
= cp
->return_size
;
591 if(!TEST_true(OSSL_PARAM_get_BN(cp
, &bn2
))
592 || !TEST_BN_eq(bn
, bn2
))
602 static int test_param_modified(void)
604 OSSL_PARAM param
[3] = { OSSL_PARAM_int("a", NULL
),
605 OSSL_PARAM_int("b", NULL
),
611 if (!TEST_false(OSSL_PARAM_modified(param
))
612 && !TEST_true(OSSL_PARAM_set_int32(param
, 1234))
613 && !TEST_true(OSSL_PARAM_modified(param
))
614 && !TEST_false(OSSL_PARAM_modified(param
+ 1))
615 && !TEST_true(OSSL_PARAM_set_int32(param
+ 1, 1))
616 && !TEST_true(OSSL_PARAM_modified(param
+ 1)))
618 OSSL_PARAM_set_all_unmodified(param
);
619 if (!TEST_false(OSSL_PARAM_modified(param
))
620 && !TEST_true(OSSL_PARAM_set_int32(param
, 4321))
621 && !TEST_true(OSSL_PARAM_modified(param
))
622 && !TEST_false(OSSL_PARAM_modified(param
+ 1))
623 && !TEST_true(OSSL_PARAM_set_int32(param
+ 1, 2))
624 && !TEST_true(OSSL_PARAM_modified(param
+ 1)))
629 int setup_tests(void)
631 ADD_ALL_TESTS(test_param_int
, OSSL_NELEM(raw_values
));
632 ADD_ALL_TESTS(test_param_long
, OSSL_NELEM(raw_values
));
633 ADD_ALL_TESTS(test_param_uint
, OSSL_NELEM(raw_values
));
634 ADD_ALL_TESTS(test_param_ulong
, OSSL_NELEM(raw_values
));
635 ADD_ALL_TESTS(test_param_int32
, OSSL_NELEM(raw_values
));
636 ADD_ALL_TESTS(test_param_uint32
, OSSL_NELEM(raw_values
));
637 ADD_ALL_TESTS(test_param_size_t
, OSSL_NELEM(raw_values
));
638 ADD_ALL_TESTS(test_param_time_t
, OSSL_NELEM(raw_values
));
639 ADD_ALL_TESTS(test_param_int64
, OSSL_NELEM(raw_values
));
640 ADD_ALL_TESTS(test_param_uint64
, OSSL_NELEM(raw_values
));
641 ADD_ALL_TESTS(test_param_bignum
, OSSL_NELEM(raw_values
));
642 ADD_TEST(test_param_real
);
643 ADD_TEST(test_param_construct
);
644 ADD_TEST(test_param_modified
);