| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2023-09-07 16:59:15 +08:00
										 |  |  |  * Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |  * Copyright (c) 2019, Oracle and/or its affiliates.  All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							|  |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <openssl/params.h>
 | 
					
						
							| 
									
										
										
										
											2021-05-26 03:06:22 +08:00
										 |  |  | #include <openssl/param_build.h>
 | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | #include "internal/nelem.h"
 | 
					
						
							|  |  |  | #include "testutil.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-07 09:27:18 +08:00
										 |  |  | static const OSSL_PARAM params_empty[] = { OSSL_PARAM_END }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-04 15:09:40 +08:00
										 |  |  | static int template_public_single_zero_test(int idx) | 
					
						
							| 
									
										
										
										
											2023-01-10 14:50:24 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     OSSL_PARAM_BLD *bld = NULL; | 
					
						
							|  |  |  |     OSSL_PARAM *params = NULL, *params_blt = NULL, *p; | 
					
						
							|  |  |  |     BIGNUM *zbn = NULL, *zbn_res = NULL; | 
					
						
							|  |  |  |     int res = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!TEST_ptr(bld = OSSL_PARAM_BLD_new()) | 
					
						
							|  |  |  |         || !TEST_ptr(zbn = BN_new()) | 
					
						
							| 
									
										
										
										
											2023-09-04 15:09:40 +08:00
										 |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, "zeronumber", | 
					
						
							|  |  |  |                                              idx == 0 ? zbn : NULL)) | 
					
						
							| 
									
										
										
										
											2023-01-10 14:50:24 +08:00
										 |  |  |         || !TEST_ptr(params_blt = OSSL_PARAM_BLD_to_param(bld))) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     params = params_blt; | 
					
						
							|  |  |  |     /* Check BN (zero BN becomes unsigned integer) */ | 
					
						
							|  |  |  |     if (!TEST_ptr(p = OSSL_PARAM_locate(params, "zeronumber")) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "zeronumber") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_BN(p, &zbn_res)) | 
					
						
							|  |  |  |         || !TEST_BN_eq(zbn_res, zbn)) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  |     res = 1; | 
					
						
							|  |  |  | err: | 
					
						
							|  |  |  |     if (params != params_blt) | 
					
						
							|  |  |  |         OPENSSL_free(params); | 
					
						
							|  |  |  |     OSSL_PARAM_free(params_blt); | 
					
						
							|  |  |  |     OSSL_PARAM_BLD_free(bld); | 
					
						
							|  |  |  |     BN_free(zbn); | 
					
						
							|  |  |  |     BN_free(zbn_res); | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int template_private_single_zero_test(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     OSSL_PARAM_BLD *bld = NULL; | 
					
						
							|  |  |  |     OSSL_PARAM *params = NULL, *params_blt = NULL, *p; | 
					
						
							|  |  |  |     BIGNUM *zbn = NULL, *zbn_res = NULL; | 
					
						
							|  |  |  |     int res = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!TEST_ptr(bld = OSSL_PARAM_BLD_new()) | 
					
						
							|  |  |  |         || !TEST_ptr(zbn = BN_secure_new()) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, "zeronumber", zbn)) | 
					
						
							|  |  |  |         || !TEST_ptr(params_blt = OSSL_PARAM_BLD_to_param(bld))) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     params = params_blt; | 
					
						
							|  |  |  |     /* Check BN (zero BN becomes unsigned integer) */ | 
					
						
							|  |  |  |     if (!TEST_ptr(p = OSSL_PARAM_locate(params, "zeronumber")) | 
					
						
							|  |  |  |         || !TEST_true(CRYPTO_secure_allocated(p->data)) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "zeronumber") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_BN(p, &zbn_res)) | 
					
						
							|  |  |  |         || !TEST_int_eq(BN_get_flags(zbn, BN_FLG_SECURE), BN_FLG_SECURE) | 
					
						
							|  |  |  |         || !TEST_BN_eq(zbn_res, zbn)) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  |     res = 1; | 
					
						
							|  |  |  | err: | 
					
						
							|  |  |  |     if (params != params_blt) | 
					
						
							|  |  |  |         OPENSSL_free(params); | 
					
						
							|  |  |  |     OSSL_PARAM_free(params_blt); | 
					
						
							|  |  |  |     OSSL_PARAM_BLD_free(bld); | 
					
						
							|  |  |  |     BN_free(zbn); | 
					
						
							|  |  |  |     BN_free(zbn_res); | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-07 09:27:18 +08:00
										 |  |  | static int template_public_test(int tstid) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-26 07:28:01 +08:00
										 |  |  |     OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new(); | 
					
						
							| 
									
										
										
										
											2021-04-07 09:27:18 +08:00
										 |  |  |     OSSL_PARAM *params = NULL, *params_blt = NULL, *p1 = NULL, *p; | 
					
						
							| 
									
										
										
										
											2023-01-10 14:50:24 +08:00
										 |  |  |     BIGNUM *zbn = NULL, *zbn_res = NULL; | 
					
						
							| 
									
										
										
										
											2021-11-29 01:03:40 +08:00
										 |  |  |     BIGNUM *pbn = NULL, *pbn_res = NULL; | 
					
						
							|  |  |  |     BIGNUM *nbn = NULL, *nbn_res = NULL; | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |     int i; | 
					
						
							|  |  |  |     long int l; | 
					
						
							|  |  |  |     int32_t i32; | 
					
						
							|  |  |  |     int64_t i64; | 
					
						
							|  |  |  |     double d; | 
					
						
							| 
									
										
										
										
											2020-05-11 07:37:45 +08:00
										 |  |  |     time_t t; | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |     char *utf = NULL; | 
					
						
							|  |  |  |     const char *cutf; | 
					
						
							|  |  |  |     int res = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 07:28:01 +08:00
										 |  |  |     if (!TEST_ptr(bld) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_long(bld, "l", 42)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_int32(bld, "i32", 1532)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_int64(bld, "i64", -9999999)) | 
					
						
							| 
									
										
										
										
											2020-05-11 07:37:45 +08:00
										 |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_time_t(bld, "t", 11224)) | 
					
						
							| 
									
										
										
										
											2020-03-26 07:28:01 +08:00
										 |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_double(bld, "d", 1.61803398875)) | 
					
						
							| 
									
										
										
										
											2023-01-10 14:50:24 +08:00
										 |  |  |         || !TEST_ptr(zbn = BN_new()) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, "zeronumber", zbn)) | 
					
						
							| 
									
										
										
										
											2021-11-29 01:03:40 +08:00
										 |  |  |         || !TEST_ptr(pbn = BN_new()) | 
					
						
							|  |  |  |         || !TEST_true(BN_set_word(pbn, 1729)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, "bignumber", pbn)) | 
					
						
							|  |  |  |         || !TEST_ptr(nbn = BN_secure_new()) | 
					
						
							|  |  |  |         || !TEST_true(BN_set_word(nbn, 1733)) | 
					
						
							|  |  |  |         || !TEST_true((BN_set_negative(nbn, 1), 1)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, "negativebignumber", nbn)) | 
					
						
							| 
									
										
										
										
											2020-03-26 07:28:01 +08:00
										 |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_utf8_string(bld, "utf8_s", "foo", | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |                                                       sizeof("foo"))) | 
					
						
							| 
									
										
										
										
											2020-03-26 07:28:01 +08:00
										 |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_utf8_ptr(bld, "utf8_p", "bar-boom", | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |                                                    0)) | 
					
						
							| 
									
										
										
										
											2021-04-07 09:27:18 +08:00
										 |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_int(bld, "i", -6)) | 
					
						
							|  |  |  |         || !TEST_ptr(params_blt = OSSL_PARAM_BLD_to_param(bld))) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-26 15:16:18 +08:00
										 |  |  |     switch (tstid) { | 
					
						
							| 
									
										
										
										
											2021-04-07 09:27:18 +08:00
										 |  |  |     case 0: | 
					
						
							|  |  |  |         params = params_blt; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case 1: | 
					
						
							|  |  |  |         params = OSSL_PARAM_merge(params_blt, params_empty); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case 2: | 
					
						
							|  |  |  |         params = OSSL_PARAM_dup(params_blt); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case 3: | 
					
						
							|  |  |  |         p1 = OSSL_PARAM_merge(params_blt, params_empty); | 
					
						
							|  |  |  |         params = OSSL_PARAM_dup(p1); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         p1 = OSSL_PARAM_dup(params_blt); | 
					
						
							|  |  |  |         params = OSSL_PARAM_merge(p1, params_empty); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     /* Check int */ | 
					
						
							|  |  |  |     if (!TEST_ptr(p = OSSL_PARAM_locate(params, "i")) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |         || !TEST_true(OSSL_PARAM_get_int(p, &i)) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "i") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_INTEGER) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(p->data_size, sizeof(int)) | 
					
						
							|  |  |  |         || !TEST_int_eq(i, -6) | 
					
						
							|  |  |  |         /* Check int32 */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "i32")) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_int32(p, &i32)) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "i32") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_INTEGER) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(p->data_size, sizeof(int32_t)) | 
					
						
							|  |  |  |         || !TEST_int_eq((int)i32, 1532) | 
					
						
							|  |  |  |         /* Check int64 */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "i64")) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "i64") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_INTEGER) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(p->data_size, sizeof(int64_t)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_int64(p, &i64)) | 
					
						
							|  |  |  |         || !TEST_long_eq((long)i64, -9999999) | 
					
						
							|  |  |  |         /* Check long */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "l")) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "l") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_INTEGER) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(p->data_size, sizeof(long int)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_long(p, &l)) | 
					
						
							|  |  |  |         || !TEST_long_eq(l, 42) | 
					
						
							| 
									
										
										
										
											2020-05-11 07:37:45 +08:00
										 |  |  |         /* Check time_t */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "t")) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "t") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_INTEGER) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(p->data_size, sizeof(time_t)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_time_t(p, &t)) | 
					
						
							|  |  |  |         || !TEST_time_t_eq(t, 11224) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |         /* Check double */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "d")) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_double(p, &d)) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "d") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_REAL) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(p->data_size, sizeof(double)) | 
					
						
							|  |  |  |         || !TEST_double_eq(d, 1.61803398875) | 
					
						
							|  |  |  |         /* Check UTF8 string */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "utf8_s")) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->data, "foo") | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_utf8_string(p, &utf, 0)) | 
					
						
							|  |  |  |         || !TEST_str_eq(utf, "foo") | 
					
						
							|  |  |  |         /* Check UTF8 pointer */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "utf8_p")) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_utf8_ptr(p, &cutf)) | 
					
						
							| 
									
										
										
										
											2019-07-18 23:14:07 +08:00
										 |  |  |         || !TEST_str_eq(cutf, "bar-boom") | 
					
						
							| 
									
										
										
										
											2023-01-10 14:50:24 +08:00
										 |  |  |         /* Check BN (zero BN becomes unsigned integer) */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "zeronumber")) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "zeronumber") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_BN(p, &zbn_res)) | 
					
						
							|  |  |  |         || !TEST_BN_eq(zbn_res, zbn) | 
					
						
							| 
									
										
										
										
											2021-11-29 01:03:40 +08:00
										 |  |  |         /* Check BN (positive BN becomes unsigned integer) */ | 
					
						
							| 
									
										
										
										
											2019-07-18 23:14:07 +08:00
										 |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "bignumber")) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "bignumber") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							| 
									
										
										
										
											2021-11-29 01:03:40 +08:00
										 |  |  |         || !TEST_true(OSSL_PARAM_get_BN(p, &pbn_res)) | 
					
						
							|  |  |  |         || !TEST_BN_eq(pbn_res, pbn) | 
					
						
							|  |  |  |         /* Check BN (negative BN becomes signed integer) */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "negativebignumber")) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "negativebignumber") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_INTEGER) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_BN(p, &nbn_res)) | 
					
						
							|  |  |  |         || !TEST_BN_eq(nbn_res, nbn)) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  |     res = 1; | 
					
						
							|  |  |  | err: | 
					
						
							| 
									
										
										
										
											2021-04-07 09:27:18 +08:00
										 |  |  |     OPENSSL_free(p1); | 
					
						
							|  |  |  |     if (params != params_blt) | 
					
						
							|  |  |  |         OPENSSL_free(params); | 
					
						
							| 
									
										
										
										
											2021-04-07 11:45:19 +08:00
										 |  |  |     OSSL_PARAM_free(params_blt); | 
					
						
							| 
									
										
										
										
											2020-03-26 07:28:01 +08:00
										 |  |  |     OSSL_PARAM_BLD_free(bld); | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |     OPENSSL_free(utf); | 
					
						
							| 
									
										
										
										
											2023-01-10 14:50:24 +08:00
										 |  |  |     BN_free(zbn); | 
					
						
							|  |  |  |     BN_free(zbn_res); | 
					
						
							| 
									
										
										
										
											2021-11-29 01:03:40 +08:00
										 |  |  |     BN_free(pbn); | 
					
						
							|  |  |  |     BN_free(pbn_res); | 
					
						
							|  |  |  |     BN_free(nbn); | 
					
						
							|  |  |  |     BN_free(nbn_res); | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-07 09:27:18 +08:00
										 |  |  | static int template_private_test(int tstid) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-04-07 07:05:05 +08:00
										 |  |  |     int *data1 = NULL, *data2 = NULL, j; | 
					
						
							|  |  |  |     const int data1_num = 12; | 
					
						
							|  |  |  |     const int data1_size = data1_num * sizeof(int); | 
					
						
							|  |  |  |     const int data2_num = 5; | 
					
						
							|  |  |  |     const int data2_size = data2_num * sizeof(int); | 
					
						
							|  |  |  |     OSSL_PARAM_BLD *bld = NULL; | 
					
						
							| 
									
										
										
										
											2021-04-07 09:27:18 +08:00
										 |  |  |     OSSL_PARAM *params = NULL, *params_blt = NULL, *p1 = NULL, *p; | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |     unsigned int i; | 
					
						
							|  |  |  |     unsigned long int l; | 
					
						
							|  |  |  |     uint32_t i32; | 
					
						
							|  |  |  |     uint64_t i64; | 
					
						
							|  |  |  |     size_t st; | 
					
						
							| 
									
										
										
										
											2023-01-10 14:50:24 +08:00
										 |  |  |     BIGNUM *zbn = NULL, *zbn_res = NULL; | 
					
						
							| 
									
										
										
										
											2021-11-29 01:03:40 +08:00
										 |  |  |     BIGNUM *pbn = NULL, *pbn_res = NULL; | 
					
						
							|  |  |  |     BIGNUM *nbn = NULL, *nbn_res = NULL; | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |     int res = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-07 07:05:05 +08:00
										 |  |  |     if (!TEST_ptr(data1 = OPENSSL_secure_malloc(data1_size)) | 
					
						
							|  |  |  |             || !TEST_ptr(data2 = OPENSSL_secure_malloc(data2_size)) | 
					
						
							|  |  |  |             || !TEST_ptr(bld = OSSL_PARAM_BLD_new())) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (j = 0; j < data1_num; j++) | 
					
						
							|  |  |  |         data1[j] = -16 * j; | 
					
						
							|  |  |  |     for (j = 0; j < data2_num; j++) | 
					
						
							|  |  |  |         data2[j] = 2 * j; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!TEST_true(OSSL_PARAM_BLD_push_uint(bld, "i", 6)) | 
					
						
							| 
									
										
										
										
											2020-03-26 07:28:01 +08:00
										 |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_ulong(bld, "l", 42)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_uint32(bld, "i32", 1532)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_uint64(bld, "i64", 9999999)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_size_t(bld, "st", 65537)) | 
					
						
							| 
									
										
										
										
											2023-01-10 14:50:24 +08:00
										 |  |  |         || !TEST_ptr(zbn = BN_secure_new()) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, "zeronumber", zbn)) | 
					
						
							| 
									
										
										
										
											2021-11-29 01:03:40 +08:00
										 |  |  |         || !TEST_ptr(pbn = BN_secure_new()) | 
					
						
							|  |  |  |         || !TEST_true(BN_set_word(pbn, 1729)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, "bignumber", pbn)) | 
					
						
							|  |  |  |         || !TEST_ptr(nbn = BN_secure_new()) | 
					
						
							|  |  |  |         || !TEST_true(BN_set_word(nbn, 1733)) | 
					
						
							|  |  |  |         || !TEST_true((BN_set_negative(nbn, 1), 1)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, "negativebignumber", nbn)) | 
					
						
							| 
									
										
										
										
											2020-03-26 07:28:01 +08:00
										 |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_octet_string(bld, "oct_s", data1, | 
					
						
							| 
									
										
										
										
											2021-04-07 07:05:05 +08:00
										 |  |  |                                                        data1_size)) | 
					
						
							| 
									
										
										
										
											2020-03-26 07:28:01 +08:00
										 |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_octet_ptr(bld, "oct_p", data2, | 
					
						
							| 
									
										
										
										
											2021-04-07 07:05:05 +08:00
										 |  |  |                                                     data2_size)) | 
					
						
							| 
									
										
										
										
											2021-04-07 09:27:18 +08:00
										 |  |  |         || !TEST_ptr(params_blt = OSSL_PARAM_BLD_to_param(bld))) | 
					
						
							|  |  |  |         goto err; | 
					
						
							| 
									
										
										
										
											2021-10-26 15:16:18 +08:00
										 |  |  |     switch (tstid) { | 
					
						
							| 
									
										
										
										
											2021-04-07 09:27:18 +08:00
										 |  |  |     case 0: | 
					
						
							|  |  |  |         params = params_blt; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case 1: | 
					
						
							|  |  |  |         params = OSSL_PARAM_merge(params_blt, params_empty); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case 2: | 
					
						
							|  |  |  |         params = OSSL_PARAM_dup(params_blt); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case 3: | 
					
						
							|  |  |  |         p1 = OSSL_PARAM_merge(params_blt, params_empty); | 
					
						
							|  |  |  |         params = OSSL_PARAM_dup(p1); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         p1 = OSSL_PARAM_dup(params_blt); | 
					
						
							|  |  |  |         params = OSSL_PARAM_merge(p1, params_empty); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     /* Check unsigned int */ | 
					
						
							|  |  |  |     if (!TEST_ptr(p = OSSL_PARAM_locate(params, "i")) | 
					
						
							| 
									
										
										
										
											2021-04-07 07:05:05 +08:00
										 |  |  |         || !TEST_false(CRYPTO_secure_allocated(p->data)) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |         || !TEST_true(OSSL_PARAM_get_uint(p, &i)) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "i") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(p->data_size, sizeof(int)) | 
					
						
							|  |  |  |         || !TEST_uint_eq(i, 6) | 
					
						
							|  |  |  |         /* Check unsigned int32 */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "i32")) | 
					
						
							| 
									
										
										
										
											2021-04-07 07:05:05 +08:00
										 |  |  |         || !TEST_false(CRYPTO_secure_allocated(p->data)) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |         || !TEST_true(OSSL_PARAM_get_uint32(p, &i32)) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "i32") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(p->data_size, sizeof(int32_t)) | 
					
						
							|  |  |  |         || !TEST_uint_eq((unsigned int)i32, 1532) | 
					
						
							|  |  |  |         /* Check unsigned int64 */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "i64")) | 
					
						
							| 
									
										
										
										
											2021-04-07 07:05:05 +08:00
										 |  |  |         || !TEST_false(CRYPTO_secure_allocated(p->data)) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |         || !TEST_str_eq(p->key, "i64") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(p->data_size, sizeof(int64_t)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_uint64(p, &i64)) | 
					
						
							|  |  |  |         || !TEST_ulong_eq((unsigned long)i64, 9999999) | 
					
						
							|  |  |  |         /* Check unsigned long int */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "l")) | 
					
						
							| 
									
										
										
										
											2021-04-07 07:05:05 +08:00
										 |  |  |         || !TEST_false(CRYPTO_secure_allocated(p->data)) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |         || !TEST_str_eq(p->key, "l") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(p->data_size, sizeof(unsigned long int)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_ulong(p, &l)) | 
					
						
							|  |  |  |         || !TEST_ulong_eq(l, 42) | 
					
						
							|  |  |  |         /* Check size_t */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "st")) | 
					
						
							| 
									
										
										
										
											2021-04-07 07:05:05 +08:00
										 |  |  |         || !TEST_false(CRYPTO_secure_allocated(p->data)) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |         || !TEST_str_eq(p->key, "st") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(p->data_size, sizeof(size_t)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_size_t(p, &st)) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(st, 65537) | 
					
						
							|  |  |  |         /* Check octet string */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "oct_s")) | 
					
						
							| 
									
										
										
										
											2021-04-07 07:05:05 +08:00
										 |  |  |         || !TEST_true(CRYPTO_secure_allocated(p->data)) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |         || !TEST_str_eq(p->key, "oct_s") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_OCTET_STRING) | 
					
						
							| 
									
										
										
										
											2021-04-07 07:05:05 +08:00
										 |  |  |         || !TEST_mem_eq(p->data, p->data_size, data1, data1_size) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |         /* Check octet pointer */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "oct_p")) | 
					
						
							| 
									
										
										
										
											2021-04-07 07:05:05 +08:00
										 |  |  |         || !TEST_false(CRYPTO_secure_allocated(p->data)) | 
					
						
							|  |  |  |         || !TEST_true(CRYPTO_secure_allocated(*(void **)p->data)) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |         || !TEST_str_eq(p->key, "oct_p") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_OCTET_PTR) | 
					
						
							| 
									
										
										
										
											2021-04-07 07:05:05 +08:00
										 |  |  |         || !TEST_mem_eq(*(void **)p->data, p->data_size, data2, data2_size) | 
					
						
							| 
									
										
										
										
											2023-01-10 14:50:24 +08:00
										 |  |  |         /* Check BN (zero BN becomes unsigned integer) */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "zeronumber")) | 
					
						
							|  |  |  |         || !TEST_true(CRYPTO_secure_allocated(p->data)) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "zeronumber") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_BN(p, &zbn_res)) | 
					
						
							|  |  |  |         || !TEST_int_eq(BN_get_flags(pbn, BN_FLG_SECURE), BN_FLG_SECURE) | 
					
						
							|  |  |  |         || !TEST_BN_eq(zbn_res, zbn) | 
					
						
							| 
									
										
										
										
											2021-11-29 01:03:40 +08:00
										 |  |  |         /* Check BN (positive BN becomes unsigned integer) */ | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "bignumber")) | 
					
						
							| 
									
										
										
										
											2021-04-07 07:05:05 +08:00
										 |  |  |         || !TEST_true(CRYPTO_secure_allocated(p->data)) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |         || !TEST_str_eq(p->key, "bignumber") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							| 
									
										
										
										
											2021-11-29 01:03:40 +08:00
										 |  |  |         || !TEST_true(OSSL_PARAM_get_BN(p, &pbn_res)) | 
					
						
							|  |  |  |         || !TEST_int_eq(BN_get_flags(pbn, BN_FLG_SECURE), BN_FLG_SECURE) | 
					
						
							|  |  |  |         || !TEST_BN_eq(pbn_res, pbn) | 
					
						
							|  |  |  |         /* Check BN (negative BN becomes signed integer) */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "negativebignumber")) | 
					
						
							|  |  |  |         || !TEST_true(CRYPTO_secure_allocated(p->data)) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "negativebignumber") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_INTEGER) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_BN(p, &nbn_res)) | 
					
						
							|  |  |  |         || !TEST_int_eq(BN_get_flags(nbn, BN_FLG_SECURE), BN_FLG_SECURE) | 
					
						
							|  |  |  |         || !TEST_BN_eq(nbn_res, nbn)) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  |     res = 1; | 
					
						
							|  |  |  | err: | 
					
						
							| 
									
										
										
										
											2021-04-07 09:27:18 +08:00
										 |  |  |     OSSL_PARAM_free(p1); | 
					
						
							|  |  |  |     if (params != params_blt) | 
					
						
							|  |  |  |         OSSL_PARAM_free(params); | 
					
						
							| 
									
										
										
										
											2021-04-07 11:45:19 +08:00
										 |  |  |     OSSL_PARAM_free(params_blt); | 
					
						
							| 
									
										
										
										
											2020-03-26 07:28:01 +08:00
										 |  |  |     OSSL_PARAM_BLD_free(bld); | 
					
						
							| 
									
										
										
										
											2021-04-07 07:05:05 +08:00
										 |  |  |     OPENSSL_secure_free(data1); | 
					
						
							|  |  |  |     OPENSSL_secure_free(data2); | 
					
						
							| 
									
										
										
										
											2023-01-10 14:50:24 +08:00
										 |  |  |     BN_free(zbn); | 
					
						
							|  |  |  |     BN_free(zbn_res); | 
					
						
							| 
									
										
										
										
											2021-11-29 01:03:40 +08:00
										 |  |  |     BN_free(pbn); | 
					
						
							|  |  |  |     BN_free(pbn_res); | 
					
						
							|  |  |  |     BN_free(nbn); | 
					
						
							|  |  |  |     BN_free(nbn_res); | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:33:46 +08:00
										 |  |  | static int builder_limit_test(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const int n = 100; | 
					
						
							|  |  |  |     char names[100][3]; | 
					
						
							|  |  |  |     OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new(); | 
					
						
							|  |  |  |     OSSL_PARAM *params = NULL; | 
					
						
							|  |  |  |     int i, res = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!TEST_ptr(bld)) | 
					
						
							|  |  |  |         goto err; | 
					
						
							| 
									
										
										
										
											2021-10-26 15:16:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:33:46 +08:00
										 |  |  |     for (i = 0; i < n; i++) { | 
					
						
							|  |  |  |         names[i][0] = 'A' + (i / 26) - 1; | 
					
						
							| 
									
										
										
										
											2020-04-27 05:40:17 +08:00
										 |  |  |         names[i][1] = 'a' + (i % 26) - 1; | 
					
						
							| 
									
										
										
										
											2020-03-27 08:33:46 +08:00
										 |  |  |         names[i][2] = '\0'; | 
					
						
							|  |  |  |         if (!TEST_true(OSSL_PARAM_BLD_push_int(bld, names[i], 3 * i + 1))) | 
					
						
							|  |  |  |             goto err; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (!TEST_ptr(params = OSSL_PARAM_BLD_to_param(bld))) | 
					
						
							|  |  |  |         goto err; | 
					
						
							| 
									
										
										
										
											2022-01-03 07:00:27 +08:00
										 |  |  |     /* Count the elements in the params array, expecting n */ | 
					
						
							| 
									
										
										
										
											2020-03-27 08:33:46 +08:00
										 |  |  |     for (i = 0; params[i].key != NULL; i++); | 
					
						
							|  |  |  |     if (!TEST_int_eq(i, n)) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Verify that the build, cleared the builder structure */ | 
					
						
							| 
									
										
										
										
											2021-04-07 11:45:19 +08:00
										 |  |  |     OSSL_PARAM_free(params); | 
					
						
							| 
									
										
										
										
											2020-03-27 08:33:46 +08:00
										 |  |  |     params = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!TEST_true(OSSL_PARAM_BLD_push_int(bld, "g", 2)) | 
					
						
							|  |  |  |         || !TEST_ptr(params = OSSL_PARAM_BLD_to_param(bld))) | 
					
						
							|  |  |  |         goto err; | 
					
						
							| 
									
										
										
										
											2022-01-03 07:00:27 +08:00
										 |  |  |     /* Count the elements in the params array, expecting 1 */ | 
					
						
							| 
									
										
										
										
											2020-03-27 08:33:46 +08:00
										 |  |  |     for (i = 0; params[i].key != NULL; i++); | 
					
						
							|  |  |  |     if (!TEST_int_eq(i, 1)) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  |     res = 1; | 
					
						
							|  |  |  | err: | 
					
						
							| 
									
										
										
										
											2021-04-07 11:45:19 +08:00
										 |  |  |     OSSL_PARAM_free(params); | 
					
						
							| 
									
										
										
										
											2020-03-27 08:33:46 +08:00
										 |  |  |     OSSL_PARAM_BLD_free(bld); | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-07 09:27:18 +08:00
										 |  |  | static int builder_merge_test(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     static int data1[] = { 2, 3, 5, 7, 11, 15, 17 }; | 
					
						
							|  |  |  |     static unsigned char data2[] = { 2, 4, 6, 8, 10 }; | 
					
						
							|  |  |  |     OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new(); | 
					
						
							|  |  |  |     OSSL_PARAM_BLD *bld2 = OSSL_PARAM_BLD_new(); | 
					
						
							|  |  |  |     OSSL_PARAM *params = NULL, *params_blt = NULL, *params2_blt = NULL, *p; | 
					
						
							|  |  |  |     unsigned int i; | 
					
						
							|  |  |  |     unsigned long int l; | 
					
						
							|  |  |  |     uint32_t i32; | 
					
						
							|  |  |  |     uint64_t i64; | 
					
						
							|  |  |  |     size_t st; | 
					
						
							|  |  |  |     BIGNUM *bn_priv = NULL, *bn_priv_res = NULL; | 
					
						
							|  |  |  |     BIGNUM *bn_pub = NULL, *bn_pub_res = NULL; | 
					
						
							|  |  |  |     int res = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!TEST_ptr(bld) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_uint(bld, "i", 6)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_ulong(bld, "l", 42)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_uint32(bld, "i32", 1532)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_uint64(bld, "i64", 9999999)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_size_t(bld, "st", 65537)) | 
					
						
							|  |  |  |         || !TEST_ptr(bn_priv = BN_secure_new()) | 
					
						
							|  |  |  |         || !TEST_true(BN_set_word(bn_priv, 1729)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, "bignumber_priv", bn_priv)) | 
					
						
							|  |  |  |         || !TEST_ptr(params_blt = OSSL_PARAM_BLD_to_param(bld))) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!TEST_ptr(bld2) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_octet_string(bld2, "oct_s", data1, | 
					
						
							|  |  |  |                                                        sizeof(data1))) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_octet_ptr(bld2, "oct_p", data2, | 
					
						
							|  |  |  |                                                     sizeof(data2))) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_uint32(bld2, "i32", 99)) | 
					
						
							|  |  |  |         || !TEST_ptr(bn_pub = BN_new()) | 
					
						
							|  |  |  |         || !TEST_true(BN_set_word(bn_pub, 0x42)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_BLD_push_BN(bld2, "bignumber_pub", bn_pub)) | 
					
						
							|  |  |  |         || !TEST_ptr(params2_blt = OSSL_PARAM_BLD_to_param(bld2))) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!TEST_ptr(params = OSSL_PARAM_merge(params_blt, params2_blt))) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!TEST_ptr(p = OSSL_PARAM_locate(params, "i")) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_uint(p, &i)) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "i") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(p->data_size, sizeof(int)) | 
					
						
							|  |  |  |         || !TEST_uint_eq(i, 6) | 
					
						
							|  |  |  |         /* Check unsigned int32 */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "i32")) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_uint32(p, &i32)) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "i32") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(p->data_size, sizeof(int32_t)) | 
					
						
							|  |  |  |         || !TEST_uint_eq((unsigned int)i32, 99) | 
					
						
							|  |  |  |         /* Check unsigned int64 */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "i64")) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "i64") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(p->data_size, sizeof(int64_t)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_uint64(p, &i64)) | 
					
						
							|  |  |  |         || !TEST_ulong_eq((unsigned long)i64, 9999999) | 
					
						
							|  |  |  |         /* Check unsigned long int */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "l")) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "l") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(p->data_size, sizeof(unsigned long int)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_ulong(p, &l)) | 
					
						
							|  |  |  |         || !TEST_ulong_eq(l, 42) | 
					
						
							|  |  |  |         /* Check size_t */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "st")) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "st") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(p->data_size, sizeof(size_t)) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_size_t(p, &st)) | 
					
						
							|  |  |  |         || !TEST_size_t_eq(st, 65537) | 
					
						
							|  |  |  |         /* Check octet string */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "oct_s")) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "oct_s") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_OCTET_STRING) | 
					
						
							|  |  |  |         || !TEST_mem_eq(p->data, p->data_size, data1, sizeof(data1)) | 
					
						
							|  |  |  |         /* Check octet pointer */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "oct_p")) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "oct_p") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_OCTET_PTR) | 
					
						
							|  |  |  |         || !TEST_mem_eq(*(void **)p->data, p->data_size, data2, sizeof(data2)) | 
					
						
							|  |  |  |         /* Check BN */ | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "bignumber_pub")) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "bignumber_pub") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_BN(p, &bn_pub_res)) | 
					
						
							|  |  |  |         || !TEST_int_eq(BN_cmp(bn_pub_res, bn_pub), 0) | 
					
						
							|  |  |  |         || !TEST_ptr(p = OSSL_PARAM_locate(params, "bignumber_priv")) | 
					
						
							|  |  |  |         || !TEST_str_eq(p->key, "bignumber_priv") | 
					
						
							|  |  |  |         || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER) | 
					
						
							|  |  |  |         || !TEST_true(OSSL_PARAM_get_BN(p, &bn_priv_res)) | 
					
						
							|  |  |  |         || !TEST_int_eq(BN_cmp(bn_priv_res, bn_priv), 0)) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  |     res = 1; | 
					
						
							|  |  |  | err: | 
					
						
							|  |  |  |     OSSL_PARAM_free(params); | 
					
						
							|  |  |  |     OSSL_PARAM_free(params_blt); | 
					
						
							|  |  |  |     OSSL_PARAM_free(params2_blt); | 
					
						
							|  |  |  |     OSSL_PARAM_BLD_free(bld); | 
					
						
							|  |  |  |     OSSL_PARAM_BLD_free(bld2); | 
					
						
							|  |  |  |     BN_free(bn_priv); | 
					
						
							|  |  |  |     BN_free(bn_priv_res); | 
					
						
							|  |  |  |     BN_free(bn_pub); | 
					
						
							|  |  |  |     BN_free(bn_pub_res); | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | int setup_tests(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-09-04 15:09:40 +08:00
										 |  |  |     ADD_ALL_TESTS(template_public_single_zero_test, 2); | 
					
						
							| 
									
										
										
										
											2021-04-07 09:27:18 +08:00
										 |  |  |     ADD_ALL_TESTS(template_public_test, 5); | 
					
						
							| 
									
										
										
										
											2021-04-07 07:05:05 +08:00
										 |  |  |     /* Only run the secure memory testing if we have secure memory available */ | 
					
						
							| 
									
										
										
										
											2023-01-10 14:50:24 +08:00
										 |  |  |     if (CRYPTO_secure_malloc_init(1<<16, 16)) { | 
					
						
							|  |  |  |         ADD_TEST(template_private_single_zero_test); | 
					
						
							| 
									
										
										
										
											2021-04-07 09:27:18 +08:00
										 |  |  |         ADD_ALL_TESTS(template_private_test, 5); | 
					
						
							| 
									
										
										
										
											2023-01-10 14:50:24 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-03-27 08:33:46 +08:00
										 |  |  |     ADD_TEST(builder_limit_test); | 
					
						
							| 
									
										
										
										
											2021-04-07 09:27:18 +08:00
										 |  |  |     ADD_TEST(builder_merge_test); | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |     return 1; | 
					
						
							|  |  |  | } |