Commit cb929645 authored by Richard Levitte's avatar Richard Levitte
Browse files

EVP_set_default_properties(): New function to set global properties



EVP_MD_fetch() can be given a property query string.  However, there
are cases when it won't, for example in implicit fetches.  Therefore,
we also need a way to set a global property query string to be used in
all subsequent fetches.  This also applies to all future algorithm
fetching functions.

Reviewed-by: default avatarPaul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/8681)
parent bc362b9b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -858,6 +858,7 @@ EVP_F_EVP_PKEY_VERIFY:142:EVP_PKEY_verify
EVP_F_EVP_PKEY_VERIFY_INIT:143:EVP_PKEY_verify_init
EVP_F_EVP_PKEY_VERIFY_RECOVER:144:EVP_PKEY_verify_recover
EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT:145:EVP_PKEY_verify_recover_init
EVP_F_EVP_SET_DEFAULT_PROPERTIES:236:EVP_set_default_properties
EVP_F_EVP_SIGNFINAL:107:EVP_SignFinal
EVP_F_EVP_VERIFYFINAL:108:EVP_VerifyFinal
EVP_F_GMAC_CTRL:215:gmac_ctrl
+2 −0
Original line number Diff line number Diff line
@@ -156,6 +156,8 @@ static const ERR_STRING_DATA EVP_str_functs[] = {
     "EVP_PKEY_verify_recover"},
    {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT, 0),
     "EVP_PKEY_verify_recover_init"},
    {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_SET_DEFAULT_PROPERTIES, 0),
     "EVP_set_default_properties"},
    {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_SIGNFINAL, 0), "EVP_SignFinal"},
    {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_VERIFYFINAL, 0), "EVP_VerifyFinal"},
    {ERR_PACK(ERR_LIB_EVP, EVP_F_GMAC_CTRL, 0), "gmac_ctrl"},
+11 −2
Original line number Diff line number Diff line
@@ -78,8 +78,7 @@ static void *alloc_tmp_method_store(void)
        ossl_method_store_free(store);
}

static
struct OSSL_METHOD_STORE *get_default_method_store(OPENSSL_CTX *libctx)
static OSSL_METHOD_STORE *get_default_method_store(OPENSSL_CTX *libctx)
{
    if (!RUN_ONCE(&default_method_store_init_flag,
                  do_default_method_store_init))
@@ -195,3 +194,13 @@ void *evp_generic_fetch(OPENSSL_CTX *libctx, int operation_id,

    return method;
}

int EVP_set_default_properties(OPENSSL_CTX *libctx, const char *propq)
{
    OSSL_METHOD_STORE *store = get_default_method_store(libctx);

    if (store != NULL)
        return ossl_method_store_set_global_properties(store, propq);
    EVPerr(EVP_F_EVP_SET_DEFAULT_PROPERTIES, ERR_R_INTERNAL_ERROR);
    return 0;
}
+7 −4
Original line number Diff line number Diff line
@@ -39,9 +39,11 @@ algorithm from the default provider.

With explicit fetch an application uses the EVP_MD_fetch() function to obtain
an algorithm implementation. An implementation with the given name and
satisfying the search criteria specified in the B<properties> parameter will be
looked for within the available providers and returned. See L<OSSL_PROVIDER(3)>
for information about providers.
satisfying the search criteria specified in the B<properties> parameter
combined with the default search criteria will be looked for within the
available providers and returned.
See L<EVP_set_default_properties(3)> for information on default search criteria
and L<OSSL_PROVIDER(3)> for information about providers.

=item User defined

@@ -156,7 +158,8 @@ other providers:
=head1 SEE ALSO

L<EVP_DigestInit(3)>, L<EVP_MD_meth_new(3)>, L<EVP_MD_meth_free(3)>,
L<EVP_MD_upref(3)>, L<OSSL_PROVIDER_load(3)>, L<OPENSSL_CTX(3)>
L<EVP_MD_upref(3)>, L<OSSL_PROVIDER_load(3)>, L<OPENSSL_CTX(3)>,
L<EVP_set_default_properties(3)>

=head1 HISTORY

+52 −0
Original line number Diff line number Diff line
=pod

=head1 NAME

EVP_set_default_properties
- Set default properties for future algorithm fetches

=head1 SYNOPSIS

 #include <openssl/evp.h>

 int EVP_set_default_properties(OPENSSL_CTX *libctx, const char *propq);

=head1 DESCRIPTION

EVP_set_default_properties() sets the default properties for all
future EVP algorithm fetches, implicit as well as explicit.

=for comment TODO(3.0) We should consider having an EVP document in
section 7 that details everything about implicit vs explicit fetches
and how they relate to properties.

EVP_set_default_properties stores the properties given with the string
I<propq> among the EVP data that's been stored in the library context
given with I<libctx> (NULL signifies the default library context).

Any previous default property for the specified library context will
be dropped.

=head1 RETURN VALUES

EVP_set_default_properties() returns 1 on success, or 0 on failure.
The latter adds an error on the error stack.

=head1 SEE ALSO

L<EVP_MD_fetch>

=head1 HISTORY

The functions described here were added in OpenSSL 3.0.

=head1 COPYRIGHT

Copyright 2019 The OpenSSL Project Authors. 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
L<https://www.openssl.org/source/license.html>.

=cut
Loading