1 1.1 christos /* 2 1.1 christos * Copyright 2019-2025 The OpenSSL Project Authors. All Rights Reserved. 3 1.1 christos * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. 4 1.1 christos * 5 1.1 christos * Licensed under the Apache License 2.0 (the "License"). You may not use 6 1.1 christos * this file except in compliance with the License. You can obtain a copy 7 1.1 christos * in the file LICENSE in the source distribution or at 8 1.1 christos * https://www.openssl.org/source/license.html 9 1.1 christos */ 10 1.1 christos 11 1.1 christos #include <string.h> 12 1.1 christos #include "testutil.h" 13 1.1 christos #include "internal/nelem.h" 14 1.1 christos #include "internal/endian.h" 15 1.1 christos #include <openssl/params.h> 16 1.1 christos #include <openssl/bn.h> 17 1.1 christos 18 1.1 christos /* The maximum size of the static buffers used to test most things */ 19 1.1 christos #define MAX_LEN 20 20 1.1 christos 21 1.1 christos static void swap_copy(unsigned char *out, const void *in, size_t len) 22 1.1 christos { 23 1.1 christos size_t j; 24 1.1 christos 25 1.1 christos for (j = 0; j < len; j++) 26 1.1 christos out[j] = ((unsigned char *)in)[len - j - 1]; 27 1.1 christos } 28 1.1 christos 29 1.1 christos /* 30 1.1 christos * A memory copy that converts the native byte ordering either to or from 31 1.1 christos * little endian format. 32 1.1 christos * 33 1.1 christos * On a little endian machine copying either is just a memcpy(3), on a 34 1.1 christos * big endian machine copying from native to or from little endian involves 35 1.1 christos * byte reversal. 36 1.1 christos */ 37 1.1 christos static void le_copy(unsigned char *out, size_t outlen, 38 1.1.1.2 christos const void *in, size_t inlen) 39 1.1 christos { 40 1.1 christos DECLARE_IS_ENDIAN; 41 1.1 christos 42 1.1 christos if (IS_LITTLE_ENDIAN) { 43 1.1 christos memcpy(out, in, outlen); 44 1.1 christos } else { 45 1.1 christos if (outlen < inlen) { 46 1.1 christos in = (const char *)in + inlen - outlen; 47 1.1 christos inlen = outlen; 48 1.1 christos } 49 1.1 christos if (!ossl_assert(outlen <= inlen)) 50 1.1 christos return; 51 1.1 christos swap_copy(out, in, inlen); 52 1.1 christos } 53 1.1 christos } 54 1.1 christos 55 1.1 christos static const struct { 56 1.1 christos size_t len; 57 1.1 christos unsigned char value[MAX_LEN]; 58 1.1 christos } raw_values[] = { 59 1.1 christos { 1, { 0x47 } }, 60 1.1 christos { 1, { 0xd0 } }, 61 1.1 christos { 2, { 0x01, 0xe9 } }, 62 1.1 christos { 2, { 0xff, 0x53 } }, 63 1.1 christos { 3, { 0x16, 0xff, 0x7c } }, 64 1.1 christos { 3, { 0xa8, 0x9c, 0x0e } }, 65 1.1 christos { 4, { 0x38, 0x27, 0xbf, 0x3b } }, 66 1.1 christos { 4, { 0x9f, 0x26, 0x48, 0x22 } }, 67 1.1 christos { 5, { 0x30, 0x65, 0xfa, 0xe4, 0x81 } }, 68 1.1 christos { 5, { 0xd1, 0x76, 0x01, 0x1b, 0xcd } }, 69 1.1 christos { 8, { 0x59, 0xb2, 0x1a, 0xe9, 0x2a, 0xd8, 0x46, 0x40 } }, 70 1.1 christos { 8, { 0xb4, 0xae, 0xbd, 0xb4, 0xdd, 0x04, 0xb1, 0x4c } }, 71 1.1.1.2 christos { 16, { 0x61, 0xe8, 0x7e, 0x31, 0xe9, 0x33, 0x83, 0x3d, 0x87, 0x99, 0xc7, 0xd8, 0x5d, 0xa9, 0x8b, 0x42 } }, 72 1.1.1.2 christos { 16, { 0xee, 0x6e, 0x8b, 0xc3, 0xec, 0xcf, 0x37, 0xcc, 0x89, 0x67, 0xf2, 0x68, 0x33, 0xa0, 0x14, 0xb0 } }, 73 1.1 christos }; 74 1.1 christos 75 1.1 christos static int test_param_type_null(OSSL_PARAM *param) 76 1.1 christos { 77 1.1 christos int rc = 0; 78 1.1 christos uint64_t intval; 79 1.1 christos double dval; 80 1.1 christos BIGNUM *bn; 81 1.1 christos 82 1.1.1.2 christos switch (param->data_type) { 83 1.1 christos case OSSL_PARAM_INTEGER: 84 1.1 christos if (param->data_size == sizeof(int32_t)) 85 1.1 christos rc = OSSL_PARAM_get_int32(param, (int32_t *)&intval); 86 1.1 christos else if (param->data_size == sizeof(uint64_t)) 87 1.1 christos rc = OSSL_PARAM_get_int64(param, (int64_t *)&intval); 88 1.1 christos else 89 1.1 christos return 1; 90 1.1 christos break; 91 1.1 christos case OSSL_PARAM_UNSIGNED_INTEGER: 92 1.1 christos if (param->data_size == sizeof(uint32_t)) 93 1.1 christos rc = OSSL_PARAM_get_uint32(param, (uint32_t *)&intval); 94 1.1 christos else if (param->data_size == sizeof(uint64_t)) 95 1.1 christos rc = OSSL_PARAM_get_uint64(param, &intval); 96 1.1 christos else 97 1.1 christos rc = OSSL_PARAM_get_BN(param, &bn); 98 1.1 christos break; 99 1.1 christos case OSSL_PARAM_REAL: 100 1.1 christos rc = OSSL_PARAM_get_double(param, &dval); 101 1.1 christos break; 102 1.1 christos case OSSL_PARAM_UTF8_STRING: 103 1.1 christos case OSSL_PARAM_OCTET_STRING: 104 1.1 christos case OSSL_PARAM_UTF8_PTR: 105 1.1 christos case OSSL_PARAM_OCTET_PTR: 106 1.1 christos /* these are allowed to be null */ 107 1.1 christos return 1; 108 1.1 christos break; 109 1.1 christos } 110 1.1 christos 111 1.1 christos /* 112 1.1 christos * we expect the various OSSL_PARAM_get functions above 113 1.1 christos * to return failure when the data is set to NULL 114 1.1 christos */ 115 1.1 christos return rc == 0; 116 1.1 christos } 117 1.1 christos 118 1.1 christos static int test_param_type_extra(OSSL_PARAM *param, const unsigned char *cmp, 119 1.1.1.2 christos size_t width) 120 1.1 christos { 121 1.1 christos int32_t i32; 122 1.1 christos int64_t i64; 123 1.1 christos size_t s, sz; 124 1.1 christos unsigned char buf[MAX_LEN]; 125 1.1 christos const int bit32 = param->data_size <= sizeof(int32_t); 126 1.1 christos const int sizet = param->data_size <= sizeof(size_t); 127 1.1 christos const int signd = param->data_type == OSSL_PARAM_INTEGER; 128 1.1 christos 129 1.1 christos /* 130 1.1 christos * Set the unmodified sentinel directly because there is no param array 131 1.1 christos * for these tests. 132 1.1 christos */ 133 1.1 christos param->return_size = OSSL_PARAM_UNMODIFIED; 134 1.1 christos if (signd) { 135 1.1 christos if ((bit32 && !TEST_true(OSSL_PARAM_get_int32(param, &i32))) 136 1.1 christos || !TEST_true(OSSL_PARAM_get_int64(param, &i64))) 137 1.1 christos return 0; 138 1.1 christos } else { 139 1.1 christos if ((bit32 140 1.1.1.2 christos && !TEST_true(OSSL_PARAM_get_uint32(param, (uint32_t *)&i32))) 141 1.1 christos || !TEST_true(OSSL_PARAM_get_uint64(param, (uint64_t *)&i64)) 142 1.1 christos || (sizet && !TEST_true(OSSL_PARAM_get_size_t(param, &s)))) 143 1.1 christos return 0; 144 1.1 christos } 145 1.1 christos if (!TEST_false(OSSL_PARAM_modified(param))) 146 1.1 christos return 0; 147 1.1 christos 148 1.1 christos /* Check signed types */ 149 1.1 christos if (bit32) { 150 1.1 christos le_copy(buf, sizeof(i32), &i32, sizeof(i32)); 151 1.1 christos sz = sizeof(i32) < width ? sizeof(i32) : width; 152 1.1 christos if (!TEST_mem_eq(buf, sz, cmp, sz)) 153 1.1 christos return 0; 154 1.1 christos } 155 1.1 christos le_copy(buf, sizeof(i64), &i64, sizeof(i64)); 156 1.1 christos sz = sizeof(i64) < width ? sizeof(i64) : width; 157 1.1 christos if (!TEST_mem_eq(buf, sz, cmp, sz)) 158 1.1 christos return 0; 159 1.1 christos if (sizet && !signd) { 160 1.1 christos le_copy(buf, sizeof(s), &s, sizeof(s)); 161 1.1 christos sz = sizeof(s) < width ? sizeof(s) : width; 162 1.1 christos if (!TEST_mem_eq(buf, sz, cmp, sz)) 163 1.1 christos return 0; 164 1.1 christos } 165 1.1 christos 166 1.1 christos /* Check a widening write if possible */ 167 1.1 christos if (sizeof(size_t) > width) { 168 1.1 christos if (signd) { 169 1.1 christos if (!TEST_true(OSSL_PARAM_set_int32(param, 12345)) 170 1.1 christos || !TEST_true(OSSL_PARAM_get_int64(param, &i64)) 171 1.1 christos || !TEST_size_t_eq((size_t)i64, 12345)) 172 1.1 christos return 0; 173 1.1 christos } else { 174 1.1 christos if (!TEST_true(OSSL_PARAM_set_uint32(param, 12345)) 175 1.1 christos || !TEST_true(OSSL_PARAM_get_uint64(param, (uint64_t *)&i64)) 176 1.1 christos || !TEST_size_t_eq((size_t)i64, 12345)) 177 1.1 christos return 0; 178 1.1 christos } 179 1.1 christos if (!TEST_true(OSSL_PARAM_modified(param))) 180 1.1 christos return 0; 181 1.1 christos } 182 1.1 christos return 1; 183 1.1 christos } 184 1.1 christos 185 1.1 christos /* 186 1.1 christos * The test cases for each of the bastic integral types are similar. 187 1.1 christos * For each type, a param of that type is set and an attempt to read it 188 1.1 christos * get is made. Finally, the above function is called to verify that 189 1.1 christos * the params can be read as other types. 190 1.1 christos * 191 1.1 christos * All the real work is done via byte buffers which are converted to machine 192 1.1 christos * byte order and to little endian for comparisons. Narrower values are best 193 1.1 christos * compared using little endian because their values and positions don't 194 1.1 christos * change. 195 1.1 christos */ 196 1.1 christos 197 1.1 christos static int test_param_int(int n) 198 1.1 christos { 199 1.1 christos int in, out; 200 1.1 christos unsigned char buf[MAX_LEN], cmp[sizeof(int)]; 201 1.1.1.2 christos const size_t len = raw_values[n].len >= sizeof(int) ? sizeof(int) : raw_values[n].len; 202 1.1 christos OSSL_PARAM param = OSSL_PARAM_int("a", NULL); 203 1.1 christos 204 1.1 christos if (!TEST_int_eq(test_param_type_null(¶m), 1)) 205 1.1 christos return 0; 206 1.1 christos 207 1.1 christos memset(buf, 0, sizeof(buf)); 208 1.1 christos le_copy(buf, sizeof(in), raw_values[n].value, sizeof(in)); 209 1.1 christos memcpy(&in, buf, sizeof(in)); 210 1.1 christos param.data = &out; 211 1.1 christos if (!TEST_true(OSSL_PARAM_set_int(¶m, in))) 212 1.1 christos return 0; 213 1.1 christos le_copy(cmp, sizeof(out), &out, sizeof(out)); 214 1.1 christos if (!TEST_mem_eq(cmp, len, raw_values[n].value, len)) 215 1.1 christos return 0; 216 1.1 christos in = 0; 217 1.1 christos if (!TEST_true(OSSL_PARAM_get_int(¶m, &in))) 218 1.1 christos return 0; 219 1.1 christos le_copy(cmp, sizeof(in), &in, sizeof(in)); 220 1.1 christos if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in))) 221 1.1 christos return 0; 222 1.1 christos param.data = &out; 223 1.1 christos return test_param_type_extra(¶m, raw_values[n].value, sizeof(int)); 224 1.1 christos } 225 1.1 christos 226 1.1 christos static int test_param_long(int n) 227 1.1 christos { 228 1.1 christos long int in, out; 229 1.1 christos unsigned char buf[MAX_LEN], cmp[sizeof(long int)]; 230 1.1 christos const size_t len = raw_values[n].len >= sizeof(long int) 231 1.1.1.2 christos ? sizeof(long int) 232 1.1.1.2 christos : raw_values[n].len; 233 1.1 christos OSSL_PARAM param = OSSL_PARAM_long("a", NULL); 234 1.1 christos 235 1.1 christos if (!TEST_int_eq(test_param_type_null(¶m), 1)) 236 1.1 christos return 0; 237 1.1 christos 238 1.1 christos memset(buf, 0, sizeof(buf)); 239 1.1 christos le_copy(buf, sizeof(in), raw_values[n].value, sizeof(in)); 240 1.1 christos memcpy(&in, buf, sizeof(in)); 241 1.1 christos param.data = &out; 242 1.1 christos if (!TEST_true(OSSL_PARAM_set_long(¶m, in))) 243 1.1 christos return 0; 244 1.1 christos le_copy(cmp, sizeof(out), &out, sizeof(out)); 245 1.1 christos if (!TEST_mem_eq(cmp, len, raw_values[n].value, len)) 246 1.1 christos return 0; 247 1.1 christos in = 0; 248 1.1 christos if (!TEST_true(OSSL_PARAM_get_long(¶m, &in))) 249 1.1 christos return 0; 250 1.1 christos le_copy(cmp, sizeof(in), &in, sizeof(in)); 251 1.1 christos if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in))) 252 1.1 christos return 0; 253 1.1 christos param.data = &out; 254 1.1 christos return test_param_type_extra(¶m, raw_values[n].value, sizeof(long int)); 255 1.1 christos } 256 1.1 christos 257 1.1 christos static int test_param_uint(int n) 258 1.1 christos { 259 1.1 christos unsigned int in, out; 260 1.1 christos unsigned char buf[MAX_LEN], cmp[sizeof(unsigned int)]; 261 1.1 christos const size_t len = raw_values[n].len >= sizeof(unsigned int) ? sizeof(unsigned int) : raw_values[n].len; 262 1.1 christos OSSL_PARAM param = OSSL_PARAM_uint("a", NULL); 263 1.1 christos 264 1.1 christos if (!TEST_int_eq(test_param_type_null(¶m), 1)) 265 1.1 christos return 0; 266 1.1 christos 267 1.1 christos memset(buf, 0, sizeof(buf)); 268 1.1 christos le_copy(buf, sizeof(in), raw_values[n].value, sizeof(in)); 269 1.1 christos memcpy(&in, buf, sizeof(in)); 270 1.1 christos param.data = &out; 271 1.1 christos if (!TEST_true(OSSL_PARAM_set_uint(¶m, in))) 272 1.1 christos return 0; 273 1.1 christos le_copy(cmp, sizeof(out), &out, sizeof(out)); 274 1.1 christos if (!TEST_mem_eq(cmp, len, raw_values[n].value, len)) 275 1.1 christos return 0; 276 1.1 christos in = 0; 277 1.1 christos if (!TEST_true(OSSL_PARAM_get_uint(¶m, &in))) 278 1.1 christos return 0; 279 1.1 christos le_copy(cmp, sizeof(in), &in, sizeof(in)); 280 1.1 christos if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in))) 281 1.1 christos return 0; 282 1.1 christos param.data = &out; 283 1.1 christos return test_param_type_extra(¶m, raw_values[n].value, sizeof(unsigned int)); 284 1.1 christos } 285 1.1 christos 286 1.1 christos static int test_param_ulong(int n) 287 1.1 christos { 288 1.1 christos unsigned long int in, out; 289 1.1 christos unsigned char buf[MAX_LEN], cmp[sizeof(unsigned long int)]; 290 1.1 christos const size_t len = raw_values[n].len >= sizeof(unsigned long int) 291 1.1.1.2 christos ? sizeof(unsigned long int) 292 1.1.1.2 christos : raw_values[n].len; 293 1.1 christos OSSL_PARAM param = OSSL_PARAM_ulong("a", NULL); 294 1.1 christos 295 1.1 christos if (!TEST_int_eq(test_param_type_null(¶m), 1)) 296 1.1 christos return 0; 297 1.1 christos 298 1.1 christos memset(buf, 0, sizeof(buf)); 299 1.1 christos le_copy(buf, sizeof(in), raw_values[n].value, sizeof(in)); 300 1.1 christos memcpy(&in, buf, sizeof(in)); 301 1.1 christos param.data = &out; 302 1.1 christos if (!TEST_true(OSSL_PARAM_set_ulong(¶m, in))) 303 1.1 christos return 0; 304 1.1 christos le_copy(cmp, sizeof(out), &out, sizeof(out)); 305 1.1 christos if (!TEST_mem_eq(cmp, len, raw_values[n].value, len)) 306 1.1 christos return 0; 307 1.1 christos in = 0; 308 1.1 christos if (!TEST_true(OSSL_PARAM_get_ulong(¶m, &in))) 309 1.1 christos return 0; 310 1.1 christos le_copy(cmp, sizeof(in), &in, sizeof(in)); 311 1.1 christos if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in))) 312 1.1 christos return 0; 313 1.1 christos param.data = &out; 314 1.1 christos return test_param_type_extra(¶m, raw_values[n].value, sizeof(unsigned long int)); 315 1.1 christos } 316 1.1 christos 317 1.1 christos static int test_param_int32(int n) 318 1.1 christos { 319 1.1 christos int32_t in, out; 320 1.1 christos unsigned char buf[MAX_LEN], cmp[sizeof(int32_t)]; 321 1.1 christos const size_t len = raw_values[n].len >= sizeof(int32_t) 322 1.1.1.2 christos ? sizeof(int32_t) 323 1.1.1.2 christos : raw_values[n].len; 324 1.1 christos OSSL_PARAM param = OSSL_PARAM_int32("a", NULL); 325 1.1 christos 326 1.1 christos if (!TEST_int_eq(test_param_type_null(¶m), 1)) 327 1.1 christos return 0; 328 1.1 christos 329 1.1 christos memset(buf, 0, sizeof(buf)); 330 1.1 christos le_copy(buf, sizeof(in), raw_values[n].value, sizeof(in)); 331 1.1 christos memcpy(&in, buf, sizeof(in)); 332 1.1 christos param.data = &out; 333 1.1 christos if (!TEST_true(OSSL_PARAM_set_int32(¶m, in))) 334 1.1 christos return 0; 335 1.1 christos le_copy(cmp, sizeof(out), &out, sizeof(out)); 336 1.1 christos if (!TEST_mem_eq(cmp, len, raw_values[n].value, len)) 337 1.1 christos return 0; 338 1.1 christos in = 0; 339 1.1 christos if (!TEST_true(OSSL_PARAM_get_int32(¶m, &in))) 340 1.1 christos return 0; 341 1.1 christos le_copy(cmp, sizeof(in), &in, sizeof(in)); 342 1.1 christos if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in))) 343 1.1 christos return 0; 344 1.1 christos param.data = &out; 345 1.1 christos return test_param_type_extra(¶m, raw_values[n].value, sizeof(int32_t)); 346 1.1 christos } 347 1.1 christos 348 1.1 christos static int test_param_uint32(int n) 349 1.1 christos { 350 1.1 christos uint32_t in, out; 351 1.1 christos unsigned char buf[MAX_LEN], cmp[sizeof(uint32_t)]; 352 1.1 christos const size_t len = raw_values[n].len >= sizeof(uint32_t) 353 1.1.1.2 christos ? sizeof(uint32_t) 354 1.1.1.2 christos : raw_values[n].len; 355 1.1 christos OSSL_PARAM param = OSSL_PARAM_uint32("a", NULL); 356 1.1 christos 357 1.1 christos if (!TEST_int_eq(test_param_type_null(¶m), 1)) 358 1.1 christos return 0; 359 1.1 christos 360 1.1 christos memset(buf, 0, sizeof(buf)); 361 1.1 christos le_copy(buf, sizeof(in), raw_values[n].value, sizeof(in)); 362 1.1 christos memcpy(&in, buf, sizeof(in)); 363 1.1 christos param.data = &out; 364 1.1 christos if (!TEST_true(OSSL_PARAM_set_uint32(¶m, in))) 365 1.1 christos return 0; 366 1.1 christos le_copy(cmp, sizeof(out), &out, sizeof(out)); 367 1.1 christos if (!TEST_mem_eq(cmp, len, raw_values[n].value, len)) 368 1.1 christos return 0; 369 1.1 christos in = 0; 370 1.1 christos if (!TEST_true(OSSL_PARAM_get_uint32(¶m, &in))) 371 1.1 christos return 0; 372 1.1 christos le_copy(cmp, sizeof(in), &in, sizeof(in)); 373 1.1 christos if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in))) 374 1.1 christos return 0; 375 1.1 christos param.data = &out; 376 1.1 christos return test_param_type_extra(¶m, raw_values[n].value, sizeof(uint32_t)); 377 1.1 christos } 378 1.1 christos 379 1.1 christos static int test_param_int64(int n) 380 1.1 christos { 381 1.1 christos int64_t in, out; 382 1.1 christos unsigned char buf[MAX_LEN], cmp[sizeof(int64_t)]; 383 1.1 christos const size_t len = raw_values[n].len >= sizeof(int64_t) 384 1.1.1.2 christos ? sizeof(int64_t) 385 1.1.1.2 christos : raw_values[n].len; 386 1.1 christos OSSL_PARAM param = OSSL_PARAM_int64("a", NULL); 387 1.1 christos 388 1.1 christos if (!TEST_int_eq(test_param_type_null(¶m), 1)) 389 1.1 christos return 0; 390 1.1 christos 391 1.1 christos memset(buf, 0, sizeof(buf)); 392 1.1 christos le_copy(buf, sizeof(in), raw_values[n].value, sizeof(in)); 393 1.1 christos memcpy(&in, buf, sizeof(in)); 394 1.1 christos param.data = &out; 395 1.1 christos if (!TEST_true(OSSL_PARAM_set_int64(¶m, in))) 396 1.1 christos return 0; 397 1.1 christos le_copy(cmp, sizeof(out), &out, sizeof(out)); 398 1.1 christos if (!TEST_mem_eq(cmp, len, raw_values[n].value, len)) 399 1.1 christos return 0; 400 1.1 christos in = 0; 401 1.1 christos if (!TEST_true(OSSL_PARAM_get_int64(¶m, &in))) 402 1.1 christos return 0; 403 1.1 christos le_copy(cmp, sizeof(in), &in, sizeof(in)); 404 1.1 christos if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in))) 405 1.1 christos return 0; 406 1.1 christos param.data = &out; 407 1.1 christos return test_param_type_extra(¶m, raw_values[n].value, sizeof(int64_t)); 408 1.1 christos } 409 1.1 christos 410 1.1 christos static int test_param_uint64(int n) 411 1.1 christos { 412 1.1 christos uint64_t in, out; 413 1.1 christos unsigned char buf[MAX_LEN], cmp[sizeof(uint64_t)]; 414 1.1 christos const size_t len = raw_values[n].len >= sizeof(uint64_t) 415 1.1.1.2 christos ? sizeof(uint64_t) 416 1.1.1.2 christos : raw_values[n].len; 417 1.1 christos OSSL_PARAM param = OSSL_PARAM_uint64("a", NULL); 418 1.1 christos 419 1.1 christos if (!TEST_int_eq(test_param_type_null(¶m), 1)) 420 1.1 christos return 0; 421 1.1 christos 422 1.1 christos memset(buf, 0, sizeof(buf)); 423 1.1 christos le_copy(buf, sizeof(in), raw_values[n].value, sizeof(in)); 424 1.1 christos memcpy(&in, buf, sizeof(in)); 425 1.1 christos param.data = &out; 426 1.1 christos if (!TEST_true(OSSL_PARAM_set_uint64(¶m, in))) 427 1.1 christos return 0; 428 1.1 christos le_copy(cmp, sizeof(out), &out, sizeof(out)); 429 1.1 christos if (!TEST_mem_eq(cmp, len, raw_values[n].value, len)) 430 1.1 christos return 0; 431 1.1 christos in = 0; 432 1.1 christos if (!TEST_true(OSSL_PARAM_get_uint64(¶m, &in))) 433 1.1 christos return 0; 434 1.1 christos le_copy(cmp, sizeof(in), &in, sizeof(in)); 435 1.1 christos if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in))) 436 1.1 christos return 0; 437 1.1 christos param.data = &out; 438 1.1 christos return test_param_type_extra(¶m, raw_values[n].value, sizeof(uint64_t)); 439 1.1 christos } 440 1.1 christos 441 1.1 christos static int test_param_size_t(int n) 442 1.1 christos { 443 1.1 christos size_t in, out; 444 1.1 christos unsigned char buf[MAX_LEN], cmp[sizeof(size_t)]; 445 1.1 christos const size_t len = raw_values[n].len >= sizeof(size_t) 446 1.1.1.2 christos ? sizeof(size_t) 447 1.1.1.2 christos : raw_values[n].len; 448 1.1 christos OSSL_PARAM param = OSSL_PARAM_size_t("a", NULL); 449 1.1 christos 450 1.1 christos if (!TEST_int_eq(test_param_type_null(¶m), 1)) 451 1.1 christos return 0; 452 1.1 christos 453 1.1 christos memset(buf, 0, sizeof(buf)); 454 1.1 christos le_copy(buf, sizeof(in), raw_values[n].value, sizeof(in)); 455 1.1 christos memcpy(&in, buf, sizeof(in)); 456 1.1 christos param.data = &out; 457 1.1 christos if (!TEST_true(OSSL_PARAM_set_size_t(¶m, in))) 458 1.1 christos return 0; 459 1.1 christos le_copy(cmp, sizeof(out), &out, sizeof(out)); 460 1.1 christos if (!TEST_mem_eq(cmp, len, raw_values[n].value, len)) 461 1.1 christos return 0; 462 1.1 christos in = 0; 463 1.1 christos if (!TEST_true(OSSL_PARAM_get_size_t(¶m, &in))) 464 1.1 christos return 0; 465 1.1 christos le_copy(cmp, sizeof(in), &in, sizeof(in)); 466 1.1 christos if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in))) 467 1.1 christos return 0; 468 1.1 christos param.data = &out; 469 1.1 christos return test_param_type_extra(¶m, raw_values[n].value, sizeof(size_t)); 470 1.1 christos } 471 1.1 christos 472 1.1 christos static int test_param_time_t(int n) 473 1.1 christos { 474 1.1 christos time_t in, out; 475 1.1 christos unsigned char buf[MAX_LEN], cmp[sizeof(time_t)]; 476 1.1 christos const size_t len = raw_values[n].len >= sizeof(time_t) 477 1.1.1.2 christos ? sizeof(time_t) 478 1.1.1.2 christos : raw_values[n].len; 479 1.1 christos OSSL_PARAM param = OSSL_PARAM_time_t("a", NULL); 480 1.1 christos 481 1.1 christos if (!TEST_int_eq(test_param_type_null(¶m), 1)) 482 1.1 christos return 0; 483 1.1 christos 484 1.1 christos memset(buf, 0, sizeof(buf)); 485 1.1 christos le_copy(buf, sizeof(in), raw_values[n].value, sizeof(in)); 486 1.1 christos memcpy(&in, buf, sizeof(in)); 487 1.1 christos param.data = &out; 488 1.1 christos if (!TEST_true(OSSL_PARAM_set_time_t(¶m, in))) 489 1.1 christos return 0; 490 1.1 christos le_copy(cmp, sizeof(out), &out, sizeof(out)); 491 1.1 christos if (!TEST_mem_eq(cmp, len, raw_values[n].value, len)) 492 1.1 christos return 0; 493 1.1 christos in = 0; 494 1.1 christos if (!TEST_true(OSSL_PARAM_get_time_t(¶m, &in))) 495 1.1 christos return 0; 496 1.1 christos le_copy(cmp, sizeof(in), &in, sizeof(in)); 497 1.1 christos if (!TEST_mem_eq(cmp, sizeof(in), raw_values[n].value, sizeof(in))) 498 1.1 christos return 0; 499 1.1 christos param.data = &out; 500 1.1 christos return test_param_type_extra(¶m, raw_values[n].value, sizeof(size_t)); 501 1.1 christos } 502 1.1 christos 503 1.1 christos static int test_param_bignum(int n) 504 1.1 christos { 505 1.1 christos unsigned char buf[MAX_LEN], bnbuf[MAX_LEN]; 506 1.1 christos const size_t len = raw_values[n].len; 507 1.1 christos BIGNUM *b = NULL, *c = NULL; 508 1.1 christos OSSL_PARAM param = OSSL_PARAM_DEFN("bn", OSSL_PARAM_UNSIGNED_INTEGER, 509 1.1.1.2 christos NULL, 0); 510 1.1 christos int ret = 0; 511 1.1 christos 512 1.1 christos if (!TEST_int_eq(test_param_type_null(¶m), 1)) 513 1.1 christos return 0; 514 1.1 christos 515 1.1 christos param.data = bnbuf; 516 1.1 christos param.data_size = sizeof(bnbuf); 517 1.1 christos 518 1.1 christos if (!TEST_ptr(b = BN_lebin2bn(raw_values[n].value, (int)len, NULL))) 519 1.1 christos goto err; 520 1.1 christos 521 1.1 christos if (!TEST_true(OSSL_PARAM_set_BN(¶m, b))) 522 1.1 christos goto err; 523 1.1 christos le_copy(buf, len, bnbuf, sizeof(bnbuf)); 524 1.1 christos if (!TEST_mem_eq(raw_values[n].value, len, buf, len)) 525 1.1 christos goto err; 526 1.1 christos param.data_size = param.return_size; 527 1.1 christos if (!TEST_true(OSSL_PARAM_get_BN(¶m, &c)) 528 1.1 christos || !TEST_BN_eq(b, c)) 529 1.1 christos goto err; 530 1.1 christos 531 1.1 christos ret = 1; 532 1.1 christos err: 533 1.1 christos BN_free(b); 534 1.1 christos BN_free(c); 535 1.1 christos return ret; 536 1.1 christos } 537 1.1 christos 538 1.1 christos static int test_param_signed_bignum(int n) 539 1.1 christos { 540 1.1 christos unsigned char buf[MAX_LEN], bnbuf[MAX_LEN]; 541 1.1 christos const size_t len = raw_values[n].len; 542 1.1 christos BIGNUM *b = NULL, *c = NULL; 543 1.1 christos OSSL_PARAM param = OSSL_PARAM_DEFN("bn", OSSL_PARAM_INTEGER, NULL, 0); 544 1.1 christos int ret = 0; 545 1.1 christos 546 1.1 christos if (!TEST_int_eq(test_param_type_null(¶m), 1)) 547 1.1 christos return 0; 548 1.1 christos 549 1.1 christos param.data = bnbuf; 550 1.1 christos param.data_size = sizeof(bnbuf); 551 1.1 christos 552 1.1 christos if (!TEST_ptr(b = BN_signed_lebin2bn(raw_values[n].value, (int)len, NULL))) 553 1.1 christos goto err; 554 1.1 christos 555 1.1 christos /* raw_values are little endian */ 556 1.1 christos if (!TEST_false(!!(raw_values[n].value[len - 1] & 0x80) ^ BN_is_negative(b))) 557 1.1 christos goto err; 558 1.1 christos if (!TEST_true(OSSL_PARAM_set_BN(¶m, b))) 559 1.1 christos goto err; 560 1.1 christos le_copy(buf, len, bnbuf, sizeof(bnbuf)); 561 1.1 christos if (!TEST_mem_eq(raw_values[n].value, len, buf, len)) 562 1.1 christos goto err; 563 1.1 christos param.data_size = param.return_size; 564 1.1 christos if (!TEST_true(OSSL_PARAM_get_BN(¶m, &c)) 565 1.1 christos || !TEST_BN_eq(b, c)) { 566 1.1 christos BN_print_fp(stderr, c); 567 1.1 christos goto err; 568 1.1 christos } 569 1.1 christos 570 1.1 christos ret = 1; 571 1.1 christos err: 572 1.1 christos BN_free(b); 573 1.1 christos BN_free(c); 574 1.1 christos return ret; 575 1.1 christos } 576 1.1 christos 577 1.1 christos static int test_param_real(void) 578 1.1 christos { 579 1.1 christos double p; 580 1.1 christos OSSL_PARAM param = OSSL_PARAM_double("r", NULL); 581 1.1 christos 582 1.1 christos if (!TEST_int_eq(test_param_type_null(¶m), 1)) 583 1.1 christos return 0; 584 1.1 christos 585 1.1 christos param.data = &p; 586 1.1 christos return TEST_true(OSSL_PARAM_set_double(¶m, 3.14159)) 587 1.1.1.2 christos && TEST_double_eq(p, 3.14159); 588 1.1 christos } 589 1.1 christos 590 1.1 christos static int test_param_construct(int tstid) 591 1.1 christos { 592 1.1 christos static const char *int_names[] = { 593 1.1 christos "int", "long", "int32", "int64" 594 1.1 christos }; 595 1.1 christos static const char *uint_names[] = { 596 1.1 christos "uint", "ulong", "uint32", "uint64", "size_t" 597 1.1 christos }; 598 1.1 christos static const unsigned char bn_val[16] = { 599 1.1 christos 0xac, 0x75, 0x22, 0x7d, 0x81, 0x06, 0x7a, 0x23, 600 1.1 christos 0xa6, 0xed, 0x87, 0xc7, 0xab, 0xf4, 0x73, 0x22 601 1.1 christos }; 602 1.1 christos OSSL_PARAM *p = NULL, *p1 = NULL; 603 1.1 christos static const OSSL_PARAM params_empty[] = { 604 1.1 christos OSSL_PARAM_END 605 1.1 christos }; 606 1.1 christos OSSL_PARAM params[20]; 607 1.1 christos char buf[100], buf2[100], *bufp, *bufp2; 608 1.1 christos unsigned char ubuf[100]; 609 1.1 christos void *vp, *vpn = NULL, *vp2; 610 1.1 christos OSSL_PARAM *cp; 611 1.1 christos int i, n = 0, ret = 0; 612 1.1 christos unsigned int u; 613 1.1 christos long int l; 614 1.1 christos unsigned long int ul; 615 1.1 christos int32_t i32; 616 1.1 christos uint32_t u32; 617 1.1 christos int64_t i64; 618 1.1 christos uint64_t u64; 619 1.1 christos size_t j, k, s; 620 1.1 christos double d, d2; 621 1.1 christos BIGNUM *bn = NULL, *bn2 = NULL; 622 1.1 christos 623 1.1 christos params[n++] = OSSL_PARAM_construct_int("int", &i); 624 1.1 christos params[n++] = OSSL_PARAM_construct_uint("uint", &u); 625 1.1 christos params[n++] = OSSL_PARAM_construct_long("long", &l); 626 1.1 christos params[n++] = OSSL_PARAM_construct_ulong("ulong", &ul); 627 1.1 christos params[n++] = OSSL_PARAM_construct_int32("int32", &i32); 628 1.1 christos params[n++] = OSSL_PARAM_construct_int64("int64", &i64); 629 1.1 christos params[n++] = OSSL_PARAM_construct_uint32("uint32", &u32); 630 1.1 christos params[n++] = OSSL_PARAM_construct_uint64("uint64", &u64); 631 1.1 christos params[n++] = OSSL_PARAM_construct_size_t("size_t", &s); 632 1.1 christos params[n++] = OSSL_PARAM_construct_double("double", &d); 633 1.1 christos params[n++] = OSSL_PARAM_construct_BN("bignum", ubuf, sizeof(ubuf)); 634 1.1 christos params[n++] = OSSL_PARAM_construct_utf8_string("utf8str", buf, sizeof(buf)); 635 1.1 christos params[n++] = OSSL_PARAM_construct_octet_string("octstr", buf, sizeof(buf)); 636 1.1 christos params[n++] = OSSL_PARAM_construct_utf8_ptr("utf8ptr", &bufp, 0); 637 1.1 christos params[n++] = OSSL_PARAM_construct_octet_ptr("octptr", &vp, 0); 638 1.1 christos params[n] = OSSL_PARAM_construct_end(); 639 1.1 christos 640 1.1 christos switch (tstid) { 641 1.1 christos case 0: 642 1.1 christos p = params; 643 1.1 christos break; 644 1.1 christos case 1: 645 1.1 christos p = OSSL_PARAM_merge(params, params_empty); 646 1.1 christos break; 647 1.1 christos case 2: 648 1.1 christos p = OSSL_PARAM_dup(params); 649 1.1 christos break; 650 1.1 christos default: 651 1.1 christos p1 = OSSL_PARAM_dup(params); 652 1.1 christos p = OSSL_PARAM_merge(p1, params_empty); 653 1.1 christos break; 654 1.1 christos } 655 1.1 christos 656 1.1 christos /* Search failure */ 657 1.1 christos if (!TEST_ptr_null(OSSL_PARAM_locate(p, "fnord"))) 658 1.1 christos goto err; 659 1.1 christos 660 1.1 christos /* All signed integral types */ 661 1.1 christos for (j = 0; j < OSSL_NELEM(int_names); j++) { 662 1.1 christos if (!TEST_ptr(cp = OSSL_PARAM_locate(p, int_names[j])) 663 1.1 christos || !TEST_true(OSSL_PARAM_set_int32(cp, (int32_t)(3 + j))) 664 1.1 christos || !TEST_true(OSSL_PARAM_get_int64(cp, &i64)) 665 1.1 christos || !TEST_size_t_eq(cp->data_size, cp->return_size) 666 1.1 christos || !TEST_size_t_eq((size_t)i64, 3 + j)) { 667 1.1 christos TEST_note("iteration %zu var %s", j + 1, int_names[j]); 668 1.1 christos goto err; 669 1.1 christos } 670 1.1 christos } 671 1.1 christos /* All unsigned integral types */ 672 1.1 christos for (j = 0; j < OSSL_NELEM(uint_names); j++) { 673 1.1 christos if (!TEST_ptr(cp = OSSL_PARAM_locate(p, uint_names[j])) 674 1.1 christos || !TEST_true(OSSL_PARAM_set_uint32(cp, (uint32_t)(3 + j))) 675 1.1 christos || !TEST_true(OSSL_PARAM_get_uint64(cp, &u64)) 676 1.1 christos || !TEST_size_t_eq(cp->data_size, cp->return_size) 677 1.1 christos || !TEST_size_t_eq((size_t)u64, 3 + j)) { 678 1.1 christos TEST_note("iteration %zu var %s", j + 1, uint_names[j]); 679 1.1 christos goto err; 680 1.1 christos } 681 1.1 christos } 682 1.1 christos /* Real */ 683 1.1 christos if (!TEST_ptr(cp = OSSL_PARAM_locate(p, "double")) 684 1.1 christos || !TEST_true(OSSL_PARAM_set_double(cp, 3.14)) 685 1.1 christos || !TEST_true(OSSL_PARAM_get_double(cp, &d2)) 686 1.1 christos || !TEST_size_t_eq(cp->return_size, sizeof(double)) 687 1.1 christos || !TEST_double_eq(d2, 3.14) 688 1.1 christos || (tstid <= 1 && !TEST_double_eq(d, d2))) 689 1.1 christos goto err; 690 1.1 christos /* UTF8 string */ 691 1.1 christos bufp = NULL; 692 1.1 christos if (!TEST_ptr(cp = OSSL_PARAM_locate(p, "utf8str")) 693 1.1 christos || !TEST_true(OSSL_PARAM_set_utf8_string(cp, "abcdef")) 694 1.1 christos || !TEST_size_t_eq(cp->return_size, sizeof("abcdef") - 1) 695 1.1 christos || !TEST_true(OSSL_PARAM_get_utf8_string(cp, &bufp, 0)) 696 1.1 christos || !TEST_str_eq(bufp, "abcdef")) { 697 1.1 christos OPENSSL_free(bufp); 698 1.1 christos goto err; 699 1.1 christos } 700 1.1 christos OPENSSL_free(bufp); 701 1.1 christos bufp = buf2; 702 1.1 christos if (!TEST_true(OSSL_PARAM_get_utf8_string(cp, &bufp, sizeof(buf2))) 703 1.1 christos || !TEST_str_eq(buf2, "abcdef")) 704 1.1 christos goto err; 705 1.1 christos /* UTF8 pointer */ 706 1.1 christos /* Note that the size of a UTF8 string does *NOT* include the NUL byte */ 707 1.1 christos bufp = buf; 708 1.1 christos if (!TEST_ptr(cp = OSSL_PARAM_locate(p, "utf8ptr")) 709 1.1 christos || !TEST_true(OSSL_PARAM_set_utf8_ptr(cp, "tuvwxyz")) 710 1.1 christos || !TEST_size_t_eq(cp->return_size, sizeof("tuvwxyz") - 1) 711 1.1 christos || !TEST_true(OSSL_PARAM_get_utf8_ptr(cp, (const char **)&bufp2)) 712 1.1 christos || !TEST_str_eq(bufp2, "tuvwxyz") 713 1.1 christos || (tstid <= 1 && !TEST_ptr_eq(bufp2, bufp))) 714 1.1 christos goto err; 715 1.1 christos /* OCTET string */ 716 1.1 christos if (!TEST_ptr(cp = OSSL_PARAM_locate(p, "octstr")) 717 1.1 christos || !TEST_true(OSSL_PARAM_set_octet_string(cp, "abcdefghi", 718 1.1.1.2 christos sizeof("abcdefghi"))) 719 1.1 christos || !TEST_size_t_eq(cp->return_size, sizeof("abcdefghi"))) 720 1.1 christos goto err; 721 1.1 christos /* Match the return size to avoid trailing garbage bytes */ 722 1.1 christos cp->data_size = cp->return_size; 723 1.1 christos if (!TEST_true(OSSL_PARAM_get_octet_string(cp, &vpn, 0, &s)) 724 1.1 christos || !TEST_size_t_eq(s, sizeof("abcdefghi")) 725 1.1 christos || !TEST_mem_eq(vpn, sizeof("abcdefghi"), 726 1.1.1.2 christos "abcdefghi", sizeof("abcdefghi"))) 727 1.1 christos goto err; 728 1.1 christos vp = buf2; 729 1.1 christos if (!TEST_true(OSSL_PARAM_get_octet_string(cp, &vp, sizeof(buf2), &s)) 730 1.1 christos || !TEST_size_t_eq(s, sizeof("abcdefghi")) 731 1.1 christos || !TEST_mem_eq(vp, sizeof("abcdefghi"), 732 1.1.1.2 christos "abcdefghi", sizeof("abcdefghi"))) 733 1.1 christos goto err; 734 1.1 christos /* OCTET pointer */ 735 1.1 christos vp = &l; 736 1.1 christos if (!TEST_ptr(cp = OSSL_PARAM_locate(p, "octptr")) 737 1.1 christos || !TEST_true(OSSL_PARAM_set_octet_ptr(cp, &ul, sizeof(ul))) 738 1.1 christos || !TEST_size_t_eq(cp->return_size, sizeof(ul)) 739 1.1 christos || (tstid <= 1 && !TEST_ptr_eq(vp, &ul))) 740 1.1 christos goto err; 741 1.1 christos /* Match the return size to avoid trailing garbage bytes */ 742 1.1 christos cp->data_size = cp->return_size; 743 1.1 christos if (!TEST_true(OSSL_PARAM_get_octet_ptr(cp, (const void **)&vp2, &k)) 744 1.1 christos || !TEST_size_t_eq(k, sizeof(ul)) 745 1.1 christos || (tstid <= 1 && !TEST_ptr_eq(vp2, vp))) 746 1.1 christos goto err; 747 1.1 christos /* BIGNUM */ 748 1.1 christos if (!TEST_ptr(cp = OSSL_PARAM_locate(p, "bignum")) 749 1.1 christos || !TEST_ptr(bn = BN_lebin2bn(bn_val, (int)sizeof(bn_val), NULL)) 750 1.1 christos || !TEST_true(OSSL_PARAM_set_BN(cp, bn)) 751 1.1 christos || !TEST_size_t_eq(cp->data_size, cp->return_size)) 752 1.1 christos goto err; 753 1.1 christos /* Match the return size to avoid trailing garbage bytes */ 754 1.1 christos cp->data_size = cp->return_size; 755 1.1 christos if (!TEST_true(OSSL_PARAM_get_BN(cp, &bn2)) 756 1.1 christos || !TEST_BN_eq(bn, bn2)) 757 1.1 christos goto err; 758 1.1 christos ret = 1; 759 1.1 christos err: 760 1.1 christos if (p != params) 761 1.1 christos OPENSSL_free(p); 762 1.1 christos OPENSSL_free(p1); 763 1.1 christos OPENSSL_free(vpn); 764 1.1 christos BN_free(bn); 765 1.1 christos BN_free(bn2); 766 1.1 christos return ret; 767 1.1 christos } 768 1.1 christos 769 1.1 christos static int test_param_modified(void) 770 1.1 christos { 771 1.1 christos OSSL_PARAM param[3] = { OSSL_PARAM_int("a", NULL), 772 1.1.1.2 christos OSSL_PARAM_int("b", NULL), 773 1.1.1.2 christos OSSL_PARAM_END }; 774 1.1 christos int a, b; 775 1.1 christos 776 1.1 christos param->data = &a; 777 1.1 christos param[1].data = &b; 778 1.1 christos if (!TEST_false(OSSL_PARAM_modified(param)) 779 1.1.1.2 christos && !TEST_true(OSSL_PARAM_set_int32(param, 1234)) 780 1.1.1.2 christos && !TEST_true(OSSL_PARAM_modified(param)) 781 1.1.1.2 christos && !TEST_false(OSSL_PARAM_modified(param + 1)) 782 1.1.1.2 christos && !TEST_true(OSSL_PARAM_set_int32(param + 1, 1)) 783 1.1.1.2 christos && !TEST_true(OSSL_PARAM_modified(param + 1))) 784 1.1 christos return 0; 785 1.1 christos OSSL_PARAM_set_all_unmodified(param); 786 1.1 christos if (!TEST_false(OSSL_PARAM_modified(param)) 787 1.1.1.2 christos && !TEST_true(OSSL_PARAM_set_int32(param, 4321)) 788 1.1.1.2 christos && !TEST_true(OSSL_PARAM_modified(param)) 789 1.1.1.2 christos && !TEST_false(OSSL_PARAM_modified(param + 1)) 790 1.1.1.2 christos && !TEST_true(OSSL_PARAM_set_int32(param + 1, 2)) 791 1.1.1.2 christos && !TEST_true(OSSL_PARAM_modified(param + 1))) 792 1.1 christos return 0; 793 1.1 christos return 1; 794 1.1 christos } 795 1.1 christos 796 1.1 christos static int test_param_copy_null(void) 797 1.1 christos { 798 1.1 christos int ret, val; 799 1.1 christos int a = 1, b = 2, i = 0; 800 1.1 christos OSSL_PARAM *cp1 = NULL, *cp2 = NULL, *p; 801 1.1 christos OSSL_PARAM param[3]; 802 1.1 christos 803 1.1 christos param[i++] = OSSL_PARAM_construct_int("a", &a); 804 1.1 christos param[i++] = OSSL_PARAM_construct_int("b", &b); 805 1.1 christos param[i] = OSSL_PARAM_construct_end(); 806 1.1 christos 807 1.1 christos ret = TEST_ptr_null(OSSL_PARAM_dup(NULL)) 808 1.1.1.2 christos && TEST_ptr(cp1 = OSSL_PARAM_merge(NULL, param)) 809 1.1.1.2 christos && TEST_ptr(p = OSSL_PARAM_locate(cp1, "a")) 810 1.1.1.2 christos && TEST_true(OSSL_PARAM_get_int(p, &val)) 811 1.1.1.2 christos && TEST_int_eq(val, 1) 812 1.1.1.2 christos && TEST_ptr(p = OSSL_PARAM_locate(cp1, "b")) 813 1.1.1.2 christos && TEST_true(OSSL_PARAM_get_int(p, &val)) 814 1.1.1.2 christos && TEST_int_eq(val, 2) 815 1.1.1.2 christos && TEST_ptr(cp2 = OSSL_PARAM_merge(param, NULL)) 816 1.1.1.2 christos && TEST_ptr(p = OSSL_PARAM_locate(cp2, "a")) 817 1.1.1.2 christos && TEST_true(OSSL_PARAM_get_int(p, &val)) 818 1.1.1.2 christos && TEST_int_eq(val, 1) 819 1.1.1.2 christos && TEST_ptr(p = OSSL_PARAM_locate(cp2, "b")) 820 1.1.1.2 christos && TEST_true(OSSL_PARAM_get_int(p, &val)) 821 1.1.1.2 christos && TEST_int_eq(val, 2) 822 1.1.1.2 christos && TEST_ptr_null(OSSL_PARAM_merge(NULL, NULL)); 823 1.1 christos OSSL_PARAM_free(cp2); 824 1.1 christos OSSL_PARAM_free(cp1); 825 1.1 christos return ret; 826 1.1 christos } 827 1.1 christos static int test_param_merge(void) 828 1.1 christos { 829 1.1 christos int val, ret; 830 1.1.1.2 christos int values[] = { 1, 2, 3, 4 }; 831 1.1 christos OSSL_PARAM *p = NULL, *cp = NULL; 832 1.1 christos OSSL_PARAM param[3], param1[3]; 833 1.1 christos 834 1.1 christos param[0] = OSSL_PARAM_construct_int("diff1", &values[0]); 835 1.1 christos param[1] = OSSL_PARAM_construct_int("same", &values[1]); 836 1.1 christos param[2] = OSSL_PARAM_construct_end(); 837 1.1 christos param1[0] = OSSL_PARAM_construct_int("diff2", &values[2]); 838 1.1 christos param1[1] = OSSL_PARAM_construct_int("same", &values[3]); 839 1.1 christos param1[2] = OSSL_PARAM_construct_end(); 840 1.1 christos 841 1.1 christos ret = TEST_ptr(p = OSSL_PARAM_merge(param, param1)) 842 1.1 christos && TEST_ptr(cp = OSSL_PARAM_locate(p, "diff1")) 843 1.1 christos && TEST_true(OSSL_PARAM_get_int(p, &val)) 844 1.1 christos && TEST_int_eq(val, values[0]) 845 1.1 christos && TEST_ptr(cp = OSSL_PARAM_locate(p, "diff2")) 846 1.1 christos && TEST_true(OSSL_PARAM_get_int(cp, &val)) 847 1.1 christos && TEST_int_eq(val, values[2]) 848 1.1 christos && TEST_ptr(cp = OSSL_PARAM_locate(p, "same")) 849 1.1 christos && TEST_true(OSSL_PARAM_get_int(cp, &val)) 850 1.1 christos && TEST_int_eq(val, values[3]); 851 1.1 christos OSSL_PARAM_free(p); 852 1.1 christos return ret; 853 1.1 christos } 854 1.1 christos 855 1.1 christos int setup_tests(void) 856 1.1 christos { 857 1.1 christos ADD_ALL_TESTS(test_param_int, OSSL_NELEM(raw_values)); 858 1.1 christos ADD_ALL_TESTS(test_param_long, OSSL_NELEM(raw_values)); 859 1.1 christos ADD_ALL_TESTS(test_param_uint, OSSL_NELEM(raw_values)); 860 1.1 christos ADD_ALL_TESTS(test_param_ulong, OSSL_NELEM(raw_values)); 861 1.1 christos ADD_ALL_TESTS(test_param_int32, OSSL_NELEM(raw_values)); 862 1.1 christos ADD_ALL_TESTS(test_param_uint32, OSSL_NELEM(raw_values)); 863 1.1 christos ADD_ALL_TESTS(test_param_size_t, OSSL_NELEM(raw_values)); 864 1.1 christos ADD_ALL_TESTS(test_param_time_t, OSSL_NELEM(raw_values)); 865 1.1 christos ADD_ALL_TESTS(test_param_int64, OSSL_NELEM(raw_values)); 866 1.1 christos ADD_ALL_TESTS(test_param_uint64, OSSL_NELEM(raw_values)); 867 1.1 christos ADD_ALL_TESTS(test_param_bignum, OSSL_NELEM(raw_values)); 868 1.1 christos ADD_ALL_TESTS(test_param_signed_bignum, OSSL_NELEM(raw_values)); 869 1.1 christos ADD_TEST(test_param_real); 870 1.1 christos ADD_ALL_TESTS(test_param_construct, 4); 871 1.1 christos ADD_TEST(test_param_modified); 872 1.1 christos ADD_TEST(test_param_copy_null); 873 1.1 christos ADD_TEST(test_param_merge); 874 1.1 christos return 1; 875 1.1 christos } 876