X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=providers%2Fdefltprov.c;h=4b15a21c0b208e06e9ef71d87992679dd7bd0434;hp=5bebf6665d2b1b793928af2f04643fea42b514b1;hb=5606922c3d2e8c3d3ffda4347cb9fe3992d75f89;hpb=6f4b7663150e2ee264836dbc5b338bd979828312 diff --git a/providers/defltprov.c b/providers/defltprov.c index 5bebf6665d..4b15a21c0b 100644 --- a/providers/defltprov.c +++ b/providers/defltprov.c @@ -1,5 +1,5 @@ /* - * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2019-2020 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 @@ -15,11 +15,20 @@ #include #include #include "prov/bio.h" +#include "prov/provider_ctx.h" #include "prov/providercommon.h" #include "prov/implementations.h" #include "prov/provider_util.h" #include "internal/nelem.h" +/* + * Forward declarations to ensure that interface functions are correctly + * defined. + */ +static OSSL_provider_gettable_params_fn deflt_gettable_params; +static OSSL_provider_get_params_fn deflt_get_params; +static OSSL_provider_query_operation_fn deflt_query; + #define ALGC(NAMES, FUNC, CHECK) { { NAMES, "provider=default", FUNC }, CHECK } #define ALG(NAMES, FUNC) ALGC(NAMES, FUNC, NULL) @@ -35,12 +44,12 @@ static const OSSL_PARAM deflt_param_types[] = { OSSL_PARAM_END }; -static const OSSL_PARAM *deflt_gettable_params(const OSSL_PROVIDER *prov) +static const OSSL_PARAM *deflt_gettable_params(void *provctx) { return deflt_param_types; } -static int deflt_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]) +static int deflt_get_params(void *provctx, OSSL_PARAM params[]) { OSSL_PARAM *p; @@ -254,43 +263,12 @@ static const OSSL_ALGORITHM_CAPABLE deflt_ciphers[] = { ALG("DES-EDE3-CFB", tdes_ede3_cfb_functions), ALG("DES-EDE3-CFB8", tdes_ede3_cfb8_functions), ALG("DES-EDE3-CFB1", tdes_ede3_cfb1_functions), + ALG("DES3-WRAP:id-smime-alg-CMS3DESwrap", tdes_wrap_cbc_functions), ALG("DES-EDE-ECB:DES-EDE", tdes_ede2_ecb_functions), ALG("DES-EDE-CBC", tdes_ede2_cbc_functions), ALG("DES-EDE-OFB", tdes_ede2_ofb_functions), ALG("DES-EDE-CFB", tdes_ede2_cfb_functions), - ALG("DESX-CBC:DESX", tdes_desx_cbc_functions), - ALG("DES3-WRAP:id-smime-alg-CMS3DESwrap", tdes_wrap_cbc_functions), - ALG("DES-ECB", des_ecb_functions), - ALG("DES-CBC:DES", des_cbc_functions), - ALG("DES-OFB", des_ofb64_functions), - ALG("DES-CFB", des_cfb64_functions), - ALG("DES-CFB1", des_cfb1_functions), - ALG("DES-CFB8", des_cfb8_functions), #endif /* OPENSSL_NO_DES */ -#ifndef OPENSSL_NO_BF - ALG("BF-ECB", blowfish128ecb_functions), - ALG("BF-CBC:BF:BLOWFISH", blowfish128cbc_functions), - ALG("BF-OFB", blowfish64ofb64_functions), - ALG("BF-CFB", blowfish64cfb64_functions), -#endif /* OPENSSL_NO_BF */ -#ifndef OPENSSL_NO_IDEA - ALG("IDEA-ECB", idea128ecb_functions), - ALG("IDEA-CBC:IDEA", idea128cbc_functions), - ALG("IDEA-OFB:IDEA-OFB64", idea128ofb64_functions), - ALG("IDEA-CFB:IDEA-CFB64", idea128cfb64_functions), -#endif /* OPENSSL_NO_IDEA */ -#ifndef OPENSSL_NO_CAST - ALG("CAST5-ECB", cast5128ecb_functions), - ALG("CAST5-CBC:CAST-CBC:CAST", cast5128cbc_functions), - ALG("CAST5-OFB", cast564ofb64_functions), - ALG("CAST5-CFB", cast564cfb64_functions), -#endif /* OPENSSL_NO_CAST */ -#ifndef OPENSSL_NO_SEED - ALG("SEED-ECB", seed128ecb_functions), - ALG("SEED-CBC:SEED", seed128cbc_functions), - ALG("SEED-OFB:SEED-OFB128", seed128ofb128_functions), - ALG("SEED-CFB:SEED-CFB128", seed128cfb128_functions), -#endif /* OPENSSL_NO_SEED */ #ifndef OPENSSL_NO_SM4 ALG("SM4-ECB", sm4128ecb_functions), ALG("SM4-CBC:SM4", sm4128cbc_functions), @@ -298,27 +276,6 @@ static const OSSL_ALGORITHM_CAPABLE deflt_ciphers[] = { ALG("SM4-OFB:SM4-OFB128", sm4128ofb128_functions), ALG("SM4-CFB:SM4-CFB128", sm4128cfb128_functions), #endif /* OPENSSL_NO_SM4 */ -#ifndef OPENSSL_NO_RC4 - ALG("RC4", rc4128_functions), - ALG("RC4-40", rc440_functions), -# ifndef OPENSSL_NO_MD5 - ALG("RC4-HMAC-MD5", rc4_hmac_md5_functions), -# endif /* OPENSSL_NO_MD5 */ -#endif /* OPENSSL_NO_RC4 */ -#ifndef OPENSSL_NO_RC5 - ALG("RC5-ECB", rc5128ecb_functions), - ALG("RC5-CBC", rc5128cbc_functions), - ALG("RC5-OFB", rc5128ofb64_functions), - ALG("RC5-CFB", rc5128cfb64_functions), -#endif /* OPENSSL_NO_RC5 */ -#ifndef OPENSSL_NO_RC2 - ALG("RC2-ECB", rc2128ecb_functions), - ALG("RC2-CBC", rc2128cbc_functions), - ALG("RC2-40-CBC", rc240cbc_functions), - ALG("RC2-64-CBC", rc264cbc_functions), - ALG("RC2-CFB", rc2128cfb128_functions), - ALG("RC2-OFB", rc2128ofb128_functions), -#endif /* OPENSSL_NO_RC2 */ #ifndef OPENSSL_NO_CHACHA ALG("ChaCha20", chacha20_functions), # ifndef OPENSSL_NO_POLY1305 @@ -373,7 +330,7 @@ static const OSSL_ALGORITHM deflt_keyexch[] = { { "DH:dhKeyAgreement", "provider=default", dh_keyexch_functions }, #endif #ifndef OPENSSL_NO_EC - { "ECDH:id-ecPublicKey", "provider=default", ecdh_keyexch_functions }, + { "ECDH", "provider=default", ecdh_keyexch_functions }, { "X25519", "provider=default", x25519_keyexch_functions }, { "X448", "provider=default", x448_keyexch_functions }, #endif @@ -384,7 +341,12 @@ static const OSSL_ALGORITHM deflt_signature[] = { #ifndef OPENSSL_NO_DSA { "DSA:dsaEncryption", "provider=default", dsa_signature_functions }, #endif - { "RSA:rsaEncryption", "default=yes", rsa_signature_functions }, + { "RSA:rsaEncryption", "provider=default", rsa_signature_functions }, +#ifndef OPENSSL_NO_EC + { "ED25519:Ed25519", "provider=default", ed25519_signature_functions }, + { "ED448:Ed448", "provider=default", ed448_signature_functions }, + { "ECDSA", "provider=default", ecdsa_signature_functions }, +#endif { NULL, NULL, NULL } }; @@ -401,10 +363,13 @@ static const OSSL_ALGORITHM deflt_keymgmt[] = { { "DSA:dsaEncryption", "provider=default", dsa_keymgmt_functions }, #endif { "RSA:rsaEncryption", "provider=default", rsa_keymgmt_functions }, + { "RSA-PSS:RSASSA-PSS", "provider=default", rsapss_keymgmt_functions }, #ifndef OPENSSL_NO_EC { "EC:id-ecPublicKey", "provider=default", ec_keymgmt_functions }, { "X25519", "provider=default", x25519_keymgmt_functions }, { "X448", "provider=default", x448_keymgmt_functions }, + { "ED25519", "provider=default", ed25519_keymgmt_functions }, + { "ED448", "provider=default", ed448_keymgmt_functions }, #endif { NULL, NULL, NULL } }; @@ -427,6 +392,18 @@ static const OSSL_ALGORITHM deflt_serializer[] = { rsa_priv_pem_serializer_functions }, { "RSA", "provider=default,fips=yes,format=pem,type=public", rsa_pub_pem_serializer_functions }, + { "RSA-PSS", "provider=default,fips=yes,format=text,type=private", + rsa_priv_text_serializer_functions }, + { "RSA-PSS", "provider=default,fips=yes,format=text,type=public", + rsa_pub_text_serializer_functions }, + { "RSA-PSS", "provider=default,fips=yes,format=der,type=private", + rsa_priv_der_serializer_functions }, + { "RSA-PSS", "provider=default,fips=yes,format=der,type=public", + rsa_pub_der_serializer_functions }, + { "RSA-PSS", "provider=default,fips=yes,format=pem,type=private", + rsa_priv_pem_serializer_functions }, + { "RSA-PSS", "provider=default,fips=yes,format=pem,type=public", + rsa_pub_pem_serializer_functions }, #ifndef OPENSSL_NO_DH { "DH", "provider=default,fips=yes,format=text,type=private", @@ -470,11 +447,82 @@ static const OSSL_ALGORITHM deflt_serializer[] = { dsa_param_pem_serializer_functions }, #endif +#ifndef OPENSSL_NO_EC + { "X25519", "provider=default,fips=yes,format=text,type=private", + x25519_priv_print_serializer_functions }, + { "X25519", "provider=default,fips=yes,format=text,type=public", + x25519_pub_print_serializer_functions }, + { "X25519", "provider=default,fips=yes,format=der,type=private", + x25519_priv_der_serializer_functions }, + { "X25519", "provider=default,fips=yes,format=der,type=public", + x25519_pub_der_serializer_functions }, + { "X25519", "provider=default,fips=yes,format=pem,type=private", + x25519_priv_pem_serializer_functions }, + { "X25519", "provider=default,fips=yes,format=pem,type=public", + x25519_pub_pem_serializer_functions }, + + { "X448", "provider=default,format=text,type=private", + x448_priv_print_serializer_functions }, + { "X448", "provider=default,format=text,type=public", + x448_pub_print_serializer_functions }, + { "X448", "provider=default,format=der,type=private", + x448_priv_der_serializer_functions }, + { "X448", "provider=default,format=der,type=public", + x448_pub_der_serializer_functions }, + { "X448", "provider=default,format=pem,type=private", + x448_priv_pem_serializer_functions }, + { "X448", "provider=default,format=pem,type=public", + x448_pub_pem_serializer_functions }, + + { "ED25519", "provider=default,fips=yes,format=text,type=private", + ed25519_priv_print_serializer_functions }, + { "ED25519", "provider=default,fips=yes,format=text,type=public", + ed25519_pub_print_serializer_functions }, + { "ED25519", "provider=default,fips=yes,format=der,type=private", + ed25519_priv_der_serializer_functions }, + { "ED25519", "provider=default,fips=yes,format=der,type=public", + ed25519_pub_der_serializer_functions }, + { "ED25519", "provider=default,fips=yes,format=pem,type=private", + ed25519_priv_pem_serializer_functions }, + { "ED25519", "provider=default,fips=yes,format=pem,type=public", + ed25519_pub_pem_serializer_functions }, + + { "ED448", "provider=default,format=text,type=private", + ed448_priv_print_serializer_functions }, + { "ED448", "provider=default,format=text,type=public", + ed448_pub_print_serializer_functions }, + { "ED448", "provider=default,format=der,type=private", + ed448_priv_der_serializer_functions }, + { "ED448", "provider=default,format=der,type=public", + ed448_pub_der_serializer_functions }, + { "ED448", "provider=default,format=pem,type=private", + ed448_priv_pem_serializer_functions }, + { "ED448", "provider=default,format=pem,type=public", + ed448_pub_pem_serializer_functions }, + + { "EC", "provider=default,fips=yes,format=text,type=private", + ec_priv_text_serializer_functions }, + { "EC", "provider=default,fips=yes,format=text,type=public", + ec_pub_text_serializer_functions }, + { "EC", "provider=default,fips=yes,format=text,type=parameters", + ec_param_text_serializer_functions }, + { "EC", "provider=default,fips=yes,format=der,type=private", + ec_priv_der_serializer_functions }, + { "EC", "provider=default,fips=yes,format=der,type=public", + ec_pub_der_serializer_functions }, + { "EC", "provider=default,fips=yes,format=der,type=parameters", + ec_param_der_serializer_functions }, + { "EC", "provider=default,fips=yes,format=pem,type=private", + ec_priv_pem_serializer_functions }, + { "EC", "provider=default,fips=yes,format=pem,type=public", + ec_pub_pem_serializer_functions }, + { "EC", "provider=default,fips=yes,format=pem,type=parameters", + ec_param_pem_serializer_functions }, +#endif { NULL, NULL, NULL } }; -static const OSSL_ALGORITHM *deflt_query(OSSL_PROVIDER *prov, - int operation_id, +static const OSSL_ALGORITHM *deflt_query(void *provctx, int operation_id, int *no_cache) { *no_cache = 0; @@ -502,8 +550,15 @@ static const OSSL_ALGORITHM *deflt_query(OSSL_PROVIDER *prov, return NULL; } +static void deflt_teardown(void *provctx) +{ + BIO_meth_free(PROV_CTX_get0_core_bio_method(provctx)); + PROV_CTX_free(provctx); +} + /* Functions we provide to the core */ static const OSSL_DISPATCH deflt_dispatch_table[] = { + { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))deflt_teardown }, { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))deflt_gettable_params }, { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))deflt_get_params }, { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))deflt_query }, @@ -512,12 +567,13 @@ static const OSSL_DISPATCH deflt_dispatch_table[] = { OSSL_provider_init_fn ossl_default_provider_init; -int ossl_default_provider_init(const OSSL_PROVIDER *provider, +int ossl_default_provider_init(const OSSL_CORE_HANDLE *handle, const OSSL_DISPATCH *in, const OSSL_DISPATCH **out, void **provctx) { OSSL_core_get_library_context_fn *c_get_libctx = NULL; + BIO_METHOD *corebiometh; if (!ossl_prov_bio_from_dispatch(in)) return 0; @@ -541,13 +597,25 @@ int ossl_default_provider_init(const OSSL_PROVIDER *provider, if (c_get_libctx == NULL) return 0; - *out = deflt_dispatch_table; - /* * We want to make sure that all calls from this provider that requires * a library context use the same context as the one used to call our - * functions. We do that by passing it along as the provider context. + * functions. We do that by passing it along in the provider context. + * + * This only works for built-in providers. Most providers should + * create their own library context. */ - *provctx = c_get_libctx(provider); + if ((*provctx = PROV_CTX_new()) == NULL + || (corebiometh = bio_prov_init_bio_method()) == NULL) { + PROV_CTX_free(*provctx); + *provctx = NULL; + return 0; + } + PROV_CTX_set0_library_context(*provctx, (OPENSSL_CTX *)c_get_libctx(handle)); + PROV_CTX_set0_handle(*provctx, handle); + PROV_CTX_set0_core_bio_method(*provctx, corebiometh); + + *out = deflt_dispatch_table; + return 1; }