]>
Commit | Line | Data |
---|---|---|
9ad41d24 RL |
1 | /* |
2 | * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. | |
3 | * | |
4 | * Licensed under the Apache License 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * https://www.openssl.org/source/license.html | |
8 | * or in the file LICENSE in the source distribution. | |
9 | */ | |
10 | ||
11 | /* | |
12 | * This program tests the use of OSSL_PARAM, currently in raw form. | |
13 | */ | |
14 | ||
15 | #include <string.h> | |
16 | #include <openssl/bn.h> | |
17 | #include <openssl/core.h> | |
bc1e0be7 | 18 | #include <openssl/params.h> |
9ad41d24 RL |
19 | #include "internal/nelem.h" |
20 | #include "testutil.h" | |
21 | ||
22 | /*- | |
23 | * PROVIDER SECTION | |
24 | * ================ | |
25 | * | |
26 | * Even though it's not necessarily ONLY providers doing this part, | |
27 | * they are naturally going to be the most common users of | |
28 | * set_params and get_params functions. | |
29 | */ | |
30 | ||
31 | /* | |
32 | * In real use cases, setters and getters would take an object with | |
33 | * which the parameters are associated. This structure is a cheap | |
34 | * simulation. | |
35 | */ | |
36 | struct object_st { | |
37 | /* | |
38 | * Documented as a native integer, of the size given by sizeof(int). | |
39 | * Assumed data type OSSL_PARAM_INTEGER | |
40 | */ | |
41 | int p1; | |
42 | /* | |
43 | * Documented as a native double, of the size given by sizeof(double). | |
44 | * Assumed data type OSSL_PARAM_REAL | |
45 | */ | |
46 | double p2; | |
47 | /* | |
48 | * Documented as an arbitrarly large unsigned integer. | |
49 | * The data size must be large enough to accomodate. | |
50 | * Assumed data type OSSL_PARAM_UNSIGNED_INTEGER | |
51 | */ | |
52 | BIGNUM *p3; | |
53 | /* | |
54 | * Documented as a C string. | |
55 | * The data size must be large enough to accomodate. | |
56 | * Assumed data type OSSL_PARAM_UTF8_STRING | |
57 | */ | |
58 | char *p4; | |
bc1e0be7 | 59 | size_t p4_l; |
fff68416 RL |
60 | /* |
61 | * Documented as a C string. | |
62 | * Assumed data type OSSL_PARAM_UTF8_STRING | |
63 | */ | |
64 | char p5[256]; | |
65 | size_t p5_l; | |
9ad41d24 RL |
66 | /* |
67 | * Documented as a pointer to a constant C string. | |
bc1e0be7 | 68 | * Assumed data type OSSL_PARAM_UTF8_PTR |
9ad41d24 | 69 | */ |
fff68416 RL |
70 | const char *p6; |
71 | size_t p6_l; | |
9ad41d24 RL |
72 | }; |
73 | ||
74 | #define p1_init 42 /* The ultimate answer */ | |
75 | #define p2_init 6.283 /* Magic number */ | |
76 | /* Stolen from evp_data, BLAKE2s256 test */ | |
77 | #define p3_init \ | |
78 | "4142434445464748494a4b4c4d4e4f50" \ | |
79 | "5152535455565758595a616263646566" \ | |
80 | "6768696a6b6c6d6e6f70717273747576" \ | |
81 | "7778797a30313233343536373839" | |
82 | #define p4_init "BLAKE2s256" /* Random string */ | |
fff68416 RL |
83 | #define p5_init "Hellow World" /* Random string */ |
84 | #define p6_init OPENSSL_FULL_VERSION_STR /* Static string */ | |
9ad41d24 RL |
85 | |
86 | static void cleanup_object(void *vobj) | |
87 | { | |
88 | struct object_st *obj = vobj; | |
89 | ||
90 | BN_free(obj->p3); | |
91 | obj->p3 = NULL; | |
92 | OPENSSL_free(obj->p4); | |
93 | obj->p4 = NULL; | |
94 | OPENSSL_free(obj); | |
95 | } | |
96 | ||
97 | static void *init_object(void) | |
98 | { | |
99 | struct object_st *obj = OPENSSL_zalloc(sizeof(*obj)); | |
100 | ||
101 | obj->p1 = p1_init; | |
102 | obj->p2 = p2_init; | |
103 | if (!TEST_true(BN_hex2bn(&obj->p3, p3_init))) | |
104 | goto fail; | |
105 | if (!TEST_ptr(obj->p4 = OPENSSL_strdup(p4_init))) | |
106 | goto fail; | |
fff68416 RL |
107 | strcpy(obj->p5, p5_init); |
108 | obj->p6 = p6_init; | |
9ad41d24 RL |
109 | |
110 | return obj; | |
111 | fail: | |
112 | cleanup_object(obj); | |
113 | obj = NULL; | |
114 | ||
115 | return NULL; | |
116 | } | |
117 | ||
118 | /* | |
119 | * RAW provider, which handles the parameters in a very raw manner, | |
120 | * with no fancy API and very minimal checking. The application that | |
121 | * calls these to set or request parameters MUST get its OSSL_PARAM | |
122 | * array right. | |
123 | */ | |
124 | ||
125 | static int raw_set_params(void *vobj, const OSSL_PARAM *params) | |
126 | { | |
127 | struct object_st *obj = vobj; | |
128 | ||
129 | for (; params->key != NULL; params++) | |
130 | if (strcmp(params->key, "p1") == 0) { | |
131 | obj->p1 = *(int *)params->data; | |
132 | } else if (strcmp(params->key, "p2") == 0) { | |
133 | obj->p2 = *(double *)params->data; | |
134 | } else if (strcmp(params->key, "p3") == 0) { | |
135 | BN_free(obj->p3); | |
136 | if (!TEST_ptr(obj->p3 = BN_native2bn(params->data, | |
137 | params->data_size, NULL))) | |
138 | return 0; | |
139 | } else if (strcmp(params->key, "p4") == 0) { | |
140 | OPENSSL_free(obj->p4); | |
141 | if (!TEST_ptr(obj->p4 = OPENSSL_strndup(params->data, | |
142 | params->data_size))) | |
143 | return 0; | |
144 | } else if (strcmp(params->key, "p5") == 0) { | |
fff68416 | 145 | strncpy(obj->p5, params->data, params->data_size); |
bbcaef63 | 146 | obj->p5_l = strlen(obj->p5) + 1; |
fff68416 RL |
147 | } else if (strcmp(params->key, "p6") == 0) { |
148 | obj->p6 = *(const char **)params->data; | |
bbcaef63 | 149 | obj->p6_l = params->data_size; |
9ad41d24 RL |
150 | } |
151 | ||
152 | return 1; | |
153 | } | |
154 | ||
4e7991b4 | 155 | static int raw_get_params(void *vobj, OSSL_PARAM *params) |
9ad41d24 RL |
156 | { |
157 | struct object_st *obj = vobj; | |
158 | ||
159 | for (; params->key != NULL; params++) | |
160 | if (strcmp(params->key, "p1") == 0) { | |
4e7991b4 | 161 | params->return_size = sizeof(obj->p1); |
9ad41d24 RL |
162 | *(int *)params->data = obj->p1; |
163 | } else if (strcmp(params->key, "p2") == 0) { | |
4e7991b4 | 164 | params->return_size = sizeof(obj->p2); |
9ad41d24 RL |
165 | *(double *)params->data = obj->p2; |
166 | } else if (strcmp(params->key, "p3") == 0) { | |
167 | size_t bytes = BN_num_bytes(obj->p3); | |
168 | ||
4e7991b4 | 169 | params->return_size = bytes; |
9ad41d24 RL |
170 | if (!TEST_size_t_ge(params->data_size, bytes)) |
171 | return 0; | |
172 | BN_bn2nativepad(obj->p3, params->data, bytes); | |
173 | } else if (strcmp(params->key, "p4") == 0) { | |
174 | size_t bytes = strlen(obj->p4) + 1; | |
175 | ||
4e7991b4 | 176 | params->return_size = bytes; |
9ad41d24 RL |
177 | if (!TEST_size_t_ge(params->data_size, bytes)) |
178 | return 0; | |
179 | strcpy(params->data, obj->p4); | |
180 | } else if (strcmp(params->key, "p5") == 0) { | |
fff68416 RL |
181 | size_t bytes = strlen(obj->p5) + 1; |
182 | ||
4e7991b4 | 183 | params->return_size = bytes; |
fff68416 RL |
184 | if (!TEST_size_t_ge(params->data_size, bytes)) |
185 | return 0; | |
186 | strcpy(params->data, obj->p5); | |
187 | } else if (strcmp(params->key, "p6") == 0) { | |
9ad41d24 RL |
188 | /* |
189 | * We COULD also use OPENSSL_FULL_VERSION_STR directly and | |
190 | * use sizeof(OPENSSL_FULL_VERSION_STR) instead of calling | |
191 | * strlen(). | |
192 | * The caller wouldn't know the difference. | |
193 | */ | |
fff68416 | 194 | size_t bytes = strlen(obj->p6) + 1; |
9ad41d24 | 195 | |
4e7991b4 | 196 | params->return_size = bytes; |
fff68416 | 197 | *(const char **)params->data = obj->p6; |
9ad41d24 RL |
198 | } |
199 | ||
200 | return 1; | |
201 | } | |
202 | ||
bc1e0be7 RL |
203 | /* |
204 | * API provider, which handles the parameters using the API from params.h | |
205 | */ | |
206 | ||
207 | static int api_set_params(void *vobj, const OSSL_PARAM *params) | |
208 | { | |
209 | struct object_st *obj = vobj; | |
210 | const OSSL_PARAM *p = NULL; | |
211 | ||
4e7991b4 | 212 | if ((p = OSSL_PARAM_locate_const(params, "p1")) != NULL |
bc1e0be7 RL |
213 | && !TEST_true(OSSL_PARAM_get_int(p, &obj->p1))) |
214 | return 0; | |
4e7991b4 | 215 | if ((p = OSSL_PARAM_locate_const(params, "p2")) != NULL |
bc1e0be7 RL |
216 | && !TEST_true(OSSL_PARAM_get_double(p, &obj->p2))) |
217 | return 0; | |
4e7991b4 | 218 | if ((p = OSSL_PARAM_locate_const(params, "p3")) != NULL |
bc1e0be7 RL |
219 | && !TEST_true(OSSL_PARAM_get_BN(p, &obj->p3))) |
220 | return 0; | |
4e7991b4 | 221 | if ((p = OSSL_PARAM_locate_const(params, "p4")) != NULL) { |
bc1e0be7 RL |
222 | OPENSSL_free(obj->p4); |
223 | obj->p4 = NULL; | |
224 | /* If the value pointer is NULL, we get it automatically allocated */ | |
225 | if (!TEST_true(OSSL_PARAM_get_utf8_string(p, &obj->p4, 0))) | |
226 | return 0; | |
227 | } | |
4e7991b4 | 228 | if ((p = OSSL_PARAM_locate_const(params, "p5")) != NULL) { |
fff68416 RL |
229 | char *p5_ptr = obj->p5; |
230 | if (!TEST_true(OSSL_PARAM_get_utf8_string(p, &p5_ptr, sizeof(obj->p5)))) | |
231 | return 0; | |
bbcaef63 RL |
232 | obj->p5_l = strlen(obj->p5) + 1; |
233 | } | |
4e7991b4 | 234 | if ((p = OSSL_PARAM_locate_const(params, "p6")) != NULL) { |
bbcaef63 RL |
235 | if (!TEST_true(OSSL_PARAM_get_utf8_ptr(p, &obj->p6))) |
236 | return 0; | |
237 | obj->p6_l = strlen(obj->p6) + 1; | |
fff68416 | 238 | } |
bc1e0be7 RL |
239 | |
240 | return 1; | |
241 | } | |
242 | ||
4e7991b4 | 243 | static int api_get_params(void *vobj, OSSL_PARAM *params) |
bc1e0be7 RL |
244 | { |
245 | struct object_st *obj = vobj; | |
4e7991b4 | 246 | OSSL_PARAM *p = NULL; |
bc1e0be7 RL |
247 | |
248 | if ((p = OSSL_PARAM_locate(params, "p1")) != NULL | |
249 | && !TEST_true(OSSL_PARAM_set_int(p, obj->p1))) | |
250 | return 0; | |
251 | if ((p = OSSL_PARAM_locate(params, "p2")) != NULL | |
252 | && !TEST_true(OSSL_PARAM_set_double(p, obj->p2))) | |
253 | return 0; | |
254 | if ((p = OSSL_PARAM_locate(params, "p3")) != NULL | |
255 | && !TEST_true(OSSL_PARAM_set_BN(p, obj->p3))) | |
256 | return 0; | |
257 | if ((p = OSSL_PARAM_locate(params, "p4")) != NULL | |
258 | && !TEST_true(OSSL_PARAM_set_utf8_string(p, obj->p4))) | |
259 | return 0; | |
260 | if ((p = OSSL_PARAM_locate(params, "p5")) != NULL | |
fff68416 RL |
261 | && !TEST_true(OSSL_PARAM_set_utf8_string(p, obj->p5))) |
262 | return 0; | |
263 | if ((p = OSSL_PARAM_locate(params, "p6")) != NULL | |
264 | && !TEST_true(OSSL_PARAM_set_utf8_ptr(p, obj->p6))) | |
bc1e0be7 RL |
265 | return 0; |
266 | ||
267 | return 1; | |
268 | } | |
269 | ||
9ad41d24 RL |
270 | /* |
271 | * This structure only simulates a provider dispatch, the real deal is | |
272 | * a bit more code that's not necessary in these tests. | |
273 | */ | |
274 | struct provider_dispatch_st { | |
275 | int (*set_params)(void *obj, const OSSL_PARAM *params); | |
4e7991b4 | 276 | int (*get_params)(void *obj, OSSL_PARAM *params); |
9ad41d24 RL |
277 | }; |
278 | ||
279 | /* "raw" provider */ | |
280 | static const struct provider_dispatch_st provider_raw = { | |
281 | raw_set_params, raw_get_params | |
282 | }; | |
283 | ||
bc1e0be7 RL |
284 | /* "api" provider */ |
285 | static const struct provider_dispatch_st provider_api = { | |
286 | api_set_params, api_get_params | |
287 | }; | |
288 | ||
9ad41d24 RL |
289 | /*- |
290 | * APPLICATION SECTION | |
291 | * =================== | |
292 | */ | |
293 | ||
294 | /* In all our tests, these are variables that get manipulated as parameters | |
295 | * | |
296 | * These arrays consistenly do nothing with the "p2" parameter, and | |
297 | * always include a "foo" parameter. This is to check that the | |
298 | * set_params and get_params calls ignore the lack of parameters that | |
299 | * the application isn't interested in, as well as ignore parameters | |
300 | * they don't understand (the application may have one big bag of | |
301 | * parameters). | |
302 | */ | |
303 | static int app_p1; /* "p1" */ | |
304 | static double app_p2; /* "p2" is ignored */ | |
305 | static BIGNUM *app_p3 = NULL; /* "p3" */ | |
306 | static unsigned char bignumbin[4096]; /* "p3" */ | |
307 | static size_t bignumbin_l; /* "p3" */ | |
308 | static char app_p4[256]; /* "p4" */ | |
fff68416 | 309 | static char app_p5[256]; /* "p5" */ |
fff68416 | 310 | static const char *app_p6 = NULL; /* "p6" */ |
9ad41d24 | 311 | static unsigned char foo[1]; /* "foo" */ |
9ad41d24 RL |
312 | |
313 | #define app_p1_init 17 /* A random number */ | |
314 | #define app_p2_init 47.11 /* Another random number */ | |
315 | #define app_p3_init "deadbeef" /* Classic */ | |
316 | #define app_p4_init "Hello" | |
317 | #define app_p5_init "World" | |
fff68416 | 318 | #define app_p6_init "Cookie" |
9ad41d24 RL |
319 | #define app_foo_init 'z' |
320 | ||
321 | static int cleanup_app_variables(void) | |
322 | { | |
323 | BN_free(app_p3); | |
324 | app_p3 = NULL; | |
325 | return 1; | |
326 | } | |
327 | ||
328 | static int init_app_variables(void) | |
329 | { | |
330 | int l = 0; | |
331 | ||
332 | cleanup_app_variables(); | |
333 | ||
334 | app_p1 = app_p1_init; | |
335 | app_p2 = app_p2_init; | |
336 | if (!BN_hex2bn(&app_p3, app_p3_init) | |
337 | || (l = BN_bn2nativepad(app_p3, bignumbin, sizeof(bignumbin))) < 0) | |
338 | return 0; | |
339 | bignumbin_l = (size_t)l; | |
340 | strcpy(app_p4, app_p4_init); | |
fff68416 | 341 | strcpy(app_p5, app_p5_init); |
fff68416 | 342 | app_p6 = app_p6_init; |
9ad41d24 | 343 | foo[0] = app_foo_init; |
9ad41d24 RL |
344 | |
345 | return 1; | |
346 | } | |
347 | ||
348 | /* | |
349 | * Here, we define test OSSL_PARAM arrays | |
350 | */ | |
351 | ||
352 | /* An array of OSSL_PARAM, specific in the most raw manner possible */ | |
4e7991b4 P |
353 | static OSSL_PARAM static_raw_params[] = { |
354 | { "p1", OSSL_PARAM_INTEGER, &app_p1, sizeof(app_p1), 0 }, | |
355 | { "p3", OSSL_PARAM_UNSIGNED_INTEGER, &bignumbin, sizeof(bignumbin), 0 }, | |
356 | { "p4", OSSL_PARAM_UTF8_STRING, &app_p4, sizeof(app_p4), 0 }, | |
357 | { "p5", OSSL_PARAM_UTF8_STRING, &app_p5, sizeof(app_p5), 0 }, | |
bbcaef63 | 358 | /* sizeof(app_p6_init), because we know that's what we're using */ |
4e7991b4 P |
359 | { "p6", OSSL_PARAM_UTF8_PTR, &app_p6, sizeof(app_p6_init), 0 }, |
360 | { "foo", OSSL_PARAM_OCTET_STRING, &foo, sizeof(foo), 0 }, | |
361 | { NULL, 0, NULL, 0, 0 } | |
9ad41d24 RL |
362 | }; |
363 | ||
bc1e0be7 | 364 | /* The same array of OSSL_PARAM, specified with the macros from params.h */ |
4e7991b4 | 365 | static OSSL_PARAM static_api_params[] = { |
bc1e0be7 | 366 | OSSL_PARAM_int("p1", &app_p1), |
4e7991b4 P |
367 | OSSL_PARAM_BN("p3", &bignumbin, sizeof(bignumbin)), |
368 | OSSL_PARAM_DEFN("p4", OSSL_PARAM_UTF8_STRING, &app_p4, sizeof(app_p4)), | |
369 | OSSL_PARAM_DEFN("p5", OSSL_PARAM_UTF8_STRING, &app_p5, sizeof(app_p5)), | |
bbcaef63 | 370 | /* sizeof(app_p6_init), because we know that's what we're using */ |
4e7991b4 P |
371 | OSSL_PARAM_DEFN("p6", OSSL_PARAM_UTF8_PTR, &app_p6, sizeof(app_p6_init)), |
372 | OSSL_PARAM_DEFN("foo", OSSL_PARAM_OCTET_STRING, &foo, sizeof(foo)), | |
bc1e0be7 RL |
373 | OSSL_PARAM_END |
374 | }; | |
375 | ||
fff68416 RL |
376 | /* |
377 | * The same array again, but constructed at run-time | |
378 | * This exercises the OSSL_PARAM constructor functions | |
379 | */ | |
84727507 | 380 | static OSSL_PARAM *construct_api_params(void) |
fff68416 RL |
381 | { |
382 | size_t n = 0; | |
383 | static OSSL_PARAM params[10]; | |
fff68416 | 384 | |
4e7991b4 P |
385 | params[n++] = OSSL_PARAM_construct_int("p1", &app_p1); |
386 | params[n++] = OSSL_PARAM_construct_BN("p3", bignumbin, sizeof(bignumbin)); | |
387 | params[n++] = OSSL_PARAM_construct_utf8_string("p4", app_p4, | |
388 | sizeof(app_p4)); | |
fff68416 | 389 | params[n++] = OSSL_PARAM_construct_utf8_string("p5", app_p5, |
4e7991b4 | 390 | sizeof(app_p5)); |
bbcaef63 | 391 | /* sizeof(app_p6_init), because we know that's what we're using */ |
fff68416 | 392 | params[n++] = OSSL_PARAM_construct_utf8_ptr("p6", (char **)&app_p6, |
4e7991b4 P |
393 | sizeof(app_p6_init)); |
394 | params[n++] = OSSL_PARAM_construct_octet_string("foo", &foo, sizeof(foo)); | |
195852fe | 395 | params[n++] = OSSL_PARAM_construct_end(); |
fff68416 RL |
396 | |
397 | return params; | |
398 | } | |
399 | ||
400 | struct param_owner_st { | |
4e7991b4 | 401 | OSSL_PARAM *static_params; |
fff68416 RL |
402 | OSSL_PARAM *(*constructed_params)(void); |
403 | }; | |
404 | ||
932c3d0f | 405 | static const struct param_owner_st raw_params = { |
fff68416 RL |
406 | static_raw_params, NULL |
407 | }; | |
408 | ||
932c3d0f | 409 | static const struct param_owner_st api_params = { |
fff68416 RL |
410 | static_api_params, construct_api_params |
411 | }; | |
412 | ||
9ad41d24 RL |
413 | /*- |
414 | * TESTING | |
415 | * ======= | |
416 | */ | |
417 | ||
418 | /* | |
419 | * Test cases to combine parameters with "provider side" functions | |
420 | */ | |
421 | static struct { | |
422 | const struct provider_dispatch_st *prov; | |
fff68416 | 423 | const struct param_owner_st *app; |
9ad41d24 RL |
424 | const char *desc; |
425 | } test_cases[] = { | |
bc1e0be7 | 426 | /* Tests within specific methods */ |
fff68416 RL |
427 | { &provider_raw, &raw_params, "raw provider vs raw params" }, |
428 | { &provider_api, &api_params, "api provider vs api params" }, | |
bc1e0be7 RL |
429 | |
430 | /* Mixed methods */ | |
fff68416 RL |
431 | { &provider_raw, &api_params, "raw provider vs api params" }, |
432 | { &provider_api, &raw_params, "api provider vs raw params" }, | |
9ad41d24 RL |
433 | }; |
434 | ||
435 | /* Generic tester of combinations of "providers" and params */ | |
4e7991b4 | 436 | static int test_case_variant(OSSL_PARAM *params, const struct provider_dispatch_st *prov) |
9ad41d24 | 437 | { |
9ad41d24 RL |
438 | BIGNUM *verify_p3 = NULL; |
439 | void *obj = NULL; | |
440 | int errcnt = 0; | |
4e7991b4 | 441 | OSSL_PARAM *p; |
9ad41d24 | 442 | |
9ad41d24 RL |
443 | /* |
444 | * Initialize | |
445 | */ | |
446 | if (!TEST_ptr(obj = init_object()) | |
447 | || !TEST_true(BN_hex2bn(&verify_p3, p3_init))) { | |
448 | errcnt++; | |
449 | goto fin; | |
450 | } | |
451 | ||
452 | /* | |
453 | * Get parameters a first time, just to see that getting works and | |
454 | * gets us the values we expect. | |
455 | */ | |
456 | init_app_variables(); | |
457 | ||
458 | if (!TEST_true(prov->get_params(obj, params)) | |
459 | || !TEST_int_eq(app_p1, p1_init) /* "provider" value */ | |
d3620841 | 460 | || !TEST_double_eq(app_p2, app_p2_init) /* Should remain untouched */ |
9ad41d24 RL |
461 | || !TEST_ptr(BN_native2bn(bignumbin, bignumbin_l, app_p3)) |
462 | || !TEST_BN_eq(app_p3, verify_p3) /* "provider" value */ | |
463 | || !TEST_str_eq(app_p4, p4_init) /* "provider" value */ | |
4e7991b4 P |
464 | || !TEST_ptr(p = OSSL_PARAM_locate(params, "p5")) |
465 | || !TEST_size_t_eq(p->return_size, sizeof(p5_init)) /* "provider" value */ | |
9ad41d24 | 466 | || !TEST_str_eq(app_p5, p5_init) /* "provider" value */ |
4e7991b4 P |
467 | || !TEST_ptr(p = OSSL_PARAM_locate(params, "p6")) |
468 | || !TEST_size_t_eq(p->return_size, sizeof(p6_init)) /* "provider" value */ | |
fff68416 | 469 | || !TEST_str_eq(app_p6, p6_init) /* "provider" value */ |
9ad41d24 | 470 | || !TEST_char_eq(foo[0], app_foo_init) /* Should remain untouched */ |
4e7991b4 P |
471 | || !TEST_ptr(p = OSSL_PARAM_locate(params, "foo")) |
472 | || !TEST_int_eq(p->return_size, 0)) | |
9ad41d24 RL |
473 | errcnt++; |
474 | ||
475 | /* | |
476 | * Set parameters, then sneak into the object itself and check | |
477 | * that its attributes got set (or ignored) properly. | |
478 | */ | |
479 | init_app_variables(); | |
480 | ||
481 | if (!TEST_true(prov->set_params(obj, params))) { | |
482 | errcnt++; | |
483 | } else { | |
484 | struct object_st *sneakpeek = obj; | |
485 | ||
486 | if (!TEST_int_eq(sneakpeek->p1, app_p1) /* app value set */ | |
d3620841 | 487 | || !TEST_double_eq(sneakpeek->p2, p2_init) /* Should remain untouched */ |
9ad41d24 RL |
488 | || !TEST_BN_eq(sneakpeek->p3, app_p3) /* app value set */ |
489 | || !TEST_str_eq(sneakpeek->p4, app_p4) /* app value set */ | |
bbcaef63 | 490 | || !TEST_str_eq(sneakpeek->p5, app_p5) /* app value set */ |
bbcaef63 | 491 | || !TEST_str_eq(sneakpeek->p6, app_p6)) /* app value set */ |
9ad41d24 RL |
492 | errcnt++; |
493 | } | |
494 | ||
495 | /* | |
496 | * Get parameters again, checking that we get different values | |
497 | * than earlier where relevant. | |
498 | */ | |
499 | BN_free(verify_p3); | |
500 | verify_p3 = NULL; | |
501 | ||
502 | if (!TEST_true(BN_hex2bn(&verify_p3, app_p3_init))) { | |
503 | errcnt++; | |
504 | goto fin; | |
505 | } | |
506 | ||
507 | if (!TEST_true(prov->get_params(obj, params)) | |
508 | || !TEST_int_eq(app_p1, app_p1_init) /* app value */ | |
d3620841 | 509 | || !TEST_double_eq(app_p2, app_p2_init) /* Should remain untouched */ |
9ad41d24 RL |
510 | || !TEST_ptr(BN_native2bn(bignumbin, bignumbin_l, app_p3)) |
511 | || !TEST_BN_eq(app_p3, verify_p3) /* app value */ | |
512 | || !TEST_str_eq(app_p4, app_p4_init) /* app value */ | |
4e7991b4 P |
513 | || !TEST_ptr(p = OSSL_PARAM_locate(params, "p5")) |
514 | || !TEST_size_t_eq(p->return_size, | |
bbcaef63 | 515 | sizeof(app_p5_init)) /* app value */ |
9ad41d24 | 516 | || !TEST_str_eq(app_p5, app_p5_init) /* app value */ |
4e7991b4 P |
517 | || !TEST_ptr(p = OSSL_PARAM_locate(params, "p6")) |
518 | || !TEST_size_t_eq(p->return_size, | |
bbcaef63 | 519 | sizeof(app_p6_init)) /* app value */ |
fff68416 | 520 | || !TEST_str_eq(app_p6, app_p6_init) /* app value */ |
9ad41d24 | 521 | || !TEST_char_eq(foo[0], app_foo_init) /* Should remain untouched */ |
4e7991b4 P |
522 | || !TEST_ptr(p = OSSL_PARAM_locate(params, "foo")) |
523 | || !TEST_int_eq(p->return_size, 0)) | |
9ad41d24 RL |
524 | errcnt++; |
525 | ||
526 | fin: | |
527 | BN_free(verify_p3); | |
528 | verify_p3 = NULL; | |
529 | cleanup_app_variables(); | |
530 | cleanup_object(obj); | |
531 | ||
532 | return errcnt == 0; | |
533 | } | |
534 | ||
fff68416 RL |
535 | static int test_case(int i) |
536 | { | |
537 | TEST_info("Case: %s", test_cases[i].desc); | |
538 | ||
539 | return test_case_variant(test_cases[i].app->static_params, | |
540 | test_cases[i].prov) | |
541 | && (test_cases[i].app->constructed_params == NULL | |
542 | || test_case_variant(test_cases[i].app->constructed_params(), | |
543 | test_cases[i].prov)); | |
544 | } | |
545 | ||
9ad41d24 RL |
546 | int setup_tests(void) |
547 | { | |
548 | ADD_ALL_TESTS(test_case, OSSL_NELEM(test_cases)); | |
549 | return 1; | |
550 | } |