OPENSSL_free(params);
}
}
-
-OSSL_PARAM *ossl_param_bld_to_param_ex(OSSL_PARAM_BLD *bld, OSSL_PARAM *params,
- size_t param_n, void *data,
- size_t data_n, void *secure,
- size_t secure_n)
-{
- if (params == NULL || data == NULL) {
- CRYPTOerr(CRYPTO_F_OSSL_PARAM_BLD_TO_PARAM_EX,
- CRYPTO_R_INVALID_NULL_ARGUMENT);
- return NULL;
- }
- if (param_n < bld->curr + 1) {
- CRYPTOerr(CRYPTO_F_OSSL_PARAM_BLD_TO_PARAM_EX,
- CRYPTO_R_INSUFFICIENT_PARAM_SIZE);
- return NULL;
- }
- if (data_n < ALIGN_SIZE * bld->total_blocks) {
- CRYPTOerr(CRYPTO_F_OSSL_PARAM_BLD_TO_PARAM_EX,
- CRYPTO_R_INSUFFICIENT_DATA_SPACE);
- return NULL;
- }
- if (bld->secure_blocks > 0 && secure_n < ALIGN_SIZE * bld->secure_blocks) {
- CRYPTOerr(CRYPTO_F_OSSL_PARAM_BLD_TO_PARAM_EX,
- CRYPTO_R_INSUFFICIENT_SECURE_DATA_SPACE);
- return NULL;
- }
- param_bld_convert(bld, params, (OSSL_PARAM_BLD_BLOCK *)data,
- (OSSL_PARAM_BLD_BLOCK *)secure);
- return params;
-}
=head1 NAME
-ossl_param_bld_init, ossl_param_bld_to_param, ossl_param_bld_to_param_ex,
+ossl_param_bld_init, ossl_param_bld_to_param,
ossl_param_bld_free, ossl_param_bld_push_int, ossl_param_bld_push_uint,
ossl_param_bld_push_long, ossl_param_bld_push_ulong,
ossl_param_bld_push_int32, ossl_param_bld_push_uint32,
void ossl_param_bld_init(OSSL_PARAM_BLD *bld);
OSSL_PARAM *ossl_param_bld_to_param(OSSL_PARAM_BLD *bld);
- OSSL_PARAM *ossl_param_bld_to_param_ex(OSSL_PARAM_BLD *bld,
- OSSL_PARAM *params, size_t param_n,
- void *data, size_t data_n,
- void *secure, size_t secure_n);
void ossl_param_bld_free(OSSL_PARAM *params);
int ossl_param_bld_push_TYPE(OSSL_PARAM_BLD *bld, const char *key, TYPE val);
ossl_param_bld_free() deallocates the memory allocated by
ossl_param_bld_to_param().
-ossl_param_bld_to_param_ex() behaves like ossl_param_bld_to_param(), except that
-no additional memory is allocated.
-An OSSL_PARAM array of at least I<param_n> elements is passed in as I<params>.
-The auxiliary storage for the parameters is a block of memory pointed to
-by I<data> of at least I<data_n> bytes in size.
-If required, secure memory for private BIGNUMs should be pointed to by
-I<secure> of at least I<secure_n> bytes in size.
-
=begin comment
POD is pretty good at recognising function names and making them appropriately
=head1 RETURN VALUES
-ossl_param_bld_to_param() and ossl_param_bld_to_param_ex() return the
-allocated OSSL_PARAM array, or NULL on error.
+ossl_param_bld_to_param() returns the allocated OSSL_PARAM array, or NULL
+on error.
All of the ossl_param_bld_push_TYPE functions return 1 on success and 0
on error.
return res;
}
-static int template_static_params_test(int n)
-{
- unsigned char data[1000], secure[500];
- OSSL_PARAM_BLD bld;
- OSSL_PARAM params[20], *p;
- BIGNUM *bn = NULL, *bn_r = NULL;
- BIGNUM *bn0 = NULL, *bn0_r = NULL;
- const size_t bn_bytes = 200;
- unsigned int i;
- char *utf = NULL;
- int res = 0;
-
- ossl_param_bld_init(&bld);
- if (!TEST_true(ossl_param_bld_push_uint(&bld, "i", 6))
- || !TEST_ptr(bn = (n & 1) == 0 ? BN_new() : BN_secure_new())
- || !TEST_true(BN_set_word(bn, 1337))
- || !TEST_false(ossl_param_bld_push_BN_pad(&bld, "bn", bn, 0))
- || !TEST_false(ossl_param_bld_push_BN_pad(&bld, "bn", bn, 1))
- || !TEST_true(ossl_param_bld_push_BN_pad(&bld, "bn", bn, bn_bytes))
- || !TEST_ptr(bn0 = BN_new())
- || !TEST_true(ossl_param_bld_push_BN_pad(&bld, "bn0", bn0, 0))
- || !TEST_true(ossl_param_bld_push_utf8_string(&bld, "utf8_s", "bar",
- 0))
- || !TEST_ptr(ossl_param_bld_to_param_ex(&bld, params,
- OSSL_NELEM(params),
- data, sizeof(data),
- secure, sizeof(secure)))
- /* Check unsigned int */
- || !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 BIGNUM */
- || !TEST_ptr(p = OSSL_PARAM_locate(params, "bn"))
- || !TEST_true(OSSL_PARAM_get_BN(p, &bn_r))
- || !TEST_str_eq(p->key, "bn")
- || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
- || !TEST_size_t_eq(p->data_size, bn_bytes)
- || !TEST_uint_eq((unsigned int)BN_get_word(bn_r), 1337)
- /* Check BIGNUM zero */
- || !TEST_ptr(p = OSSL_PARAM_locate(params, "bn0"))
- || !TEST_true(OSSL_PARAM_get_BN(p, &bn0_r))
- || !TEST_str_eq(p->key, "bn0")
- || !TEST_uint_eq(p->data_type, OSSL_PARAM_UNSIGNED_INTEGER)
- || !TEST_size_t_eq(p->data_size, 0)
- || !TEST_uint_eq((unsigned int)BN_get_word(bn0_r), 0)
- /* Check UTF8 string */
- || !TEST_ptr(p = OSSL_PARAM_locate(params, "utf8_s"))
- || !TEST_str_eq(p->data, "bar")
- || !TEST_true(OSSL_PARAM_get_utf8_string(p, &utf, 0))
- || !TEST_str_eq(utf, "bar"))
- goto err;
- res = 1;
-err:
- OPENSSL_free(utf);
- BN_free(bn);
- BN_free(bn_r);
- BN_free(bn0);
- BN_free(bn0_r);
- return res;
-}
-
-static int template_static_fail_test(int n)
-{
- unsigned char data[10000], secure[500];
- OSSL_PARAM_BLD bld;
- OSSL_PARAM prms[20];
- BIGNUM *bn = NULL;
- int res = 0;
-
- ossl_param_bld_init(&bld);
- if (!TEST_true(ossl_param_bld_push_uint(&bld, "i", 6))
- || !TEST_ptr(bn = (n & 1) == 0 ? BN_new() : BN_secure_new())
- || !TEST_true(BN_hex2bn(&bn, "ABCDEF78901234567890ABCDEF0987987654321"))
- || !TEST_true(ossl_param_bld_push_BN(&bld, "bn", bn))
- || !TEST_true(ossl_param_bld_push_utf8_string(&bld, "utf8_s", "abc",
- 1000))
- /* No OSSL_PARAMS */
- || !TEST_ptr_null(ossl_param_bld_to_param_ex(&bld, NULL, 0, data,
- sizeof(data), secure,
- sizeof(secure)))
- /* Short OSSL_PARAMS */
- || !TEST_ptr_null(ossl_param_bld_to_param_ex(&bld, prms, 2,
- data, sizeof(data),
- secure, sizeof(secure)))
- /* No normal data */
- || !TEST_ptr_null(ossl_param_bld_to_param_ex(&bld, prms,
- OSSL_NELEM(prms),
- NULL, 0, secure,
- sizeof(secure)))
- /* Not enough normal data */
- || !TEST_ptr_null(ossl_param_bld_to_param_ex(&bld, prms,
- OSSL_NELEM(prms),
- data, 50, secure,
- sizeof(secure))))
- goto err;
- if ((n & 1) == 1) {
- /* No secure data */
- if (!TEST_ptr_null(ossl_param_bld_to_param_ex(&bld, prms,
- OSSL_NELEM(prms),
- data, sizeof(data),
- NULL, 0))
- /* Not enough secure data */
- || !TEST_ptr_null(ossl_param_bld_to_param_ex(&bld, prms,
- OSSL_NELEM(prms),
- data, sizeof(data),
- secure, 4)))
- goto err;
- }
- res = 1;
-err:
- BN_free(bn);
- return res;
-}
-
int setup_tests(void)
{
ADD_TEST(template_public_test);
ADD_TEST(template_private_test);
- ADD_ALL_TESTS(template_static_params_test, 2);
- ADD_ALL_TESTS(template_static_fail_test, 2);
return 1;
}