1 1.1 christos /* 2 1.1 christos * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved. 3 1.1 christos * 4 1.1 christos * Licensed under the Apache License 2.0 (the "License"). You may not use 5 1.1 christos * this file except in compliance with the License. You can obtain a copy 6 1.1 christos * in the file LICENSE in the source distribution or at 7 1.1 christos * https://www.openssl.org/source/license.html 8 1.1 christos */ 9 1.1 christos 10 1.1 christos #include <string.h> 11 1.1 christos #include <stdio.h> 12 1.1 christos #include <openssl/opensslconf.h> 13 1.1 christos #include <openssl/core.h> 14 1.1 christos #include <openssl/core_dispatch.h> 15 1.1 christos #include <openssl/core_names.h> 16 1.1 christos #include <openssl/params.h> 17 1.1 christos #include "prov/bio.h" 18 1.1 christos #include "prov/provider_ctx.h" 19 1.1 christos #include "prov/providercommon.h" 20 1.1 christos #include "prov/implementations.h" 21 1.1 christos #include "prov/names.h" 22 1.1 christos #include "prov/provider_util.h" 23 1.1 christos #include "prov/seeding.h" 24 1.1 christos #include "internal/nelem.h" 25 1.1 christos 26 1.1 christos /* 27 1.1 christos * Forward declarations to ensure that interface functions are correctly 28 1.1 christos * defined. 29 1.1 christos */ 30 1.1 christos static OSSL_FUNC_provider_gettable_params_fn deflt_gettable_params; 31 1.1 christos static OSSL_FUNC_provider_get_params_fn deflt_get_params; 32 1.1 christos static OSSL_FUNC_provider_query_operation_fn deflt_query; 33 1.1 christos 34 1.1 christos #define ALGC(NAMES, FUNC, CHECK) { { NAMES, "provider=default", FUNC }, CHECK } 35 1.1 christos #define ALG(NAMES, FUNC) ALGC(NAMES, FUNC, NULL) 36 1.1 christos 37 1.1 christos /* Functions provided by the core */ 38 1.1 christos static OSSL_FUNC_core_gettable_params_fn *c_gettable_params = NULL; 39 1.1 christos static OSSL_FUNC_core_get_params_fn *c_get_params = NULL; 40 1.1 christos 41 1.1 christos /* Parameters we provide to the core */ 42 1.1 christos static const OSSL_PARAM deflt_param_types[] = { 43 1.1 christos OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0), 44 1.1 christos OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0), 45 1.1 christos OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR, NULL, 0), 46 1.1 christos OSSL_PARAM_DEFN(OSSL_PROV_PARAM_STATUS, OSSL_PARAM_INTEGER, NULL, 0), 47 1.1 christos OSSL_PARAM_END 48 1.1 christos }; 49 1.1 christos 50 1.1 christos static const OSSL_PARAM *deflt_gettable_params(void *provctx) 51 1.1 christos { 52 1.1 christos return deflt_param_types; 53 1.1 christos } 54 1.1 christos 55 1.1 christos static int deflt_get_params(void *provctx, OSSL_PARAM params[]) 56 1.1 christos { 57 1.1 christos OSSL_PARAM *p; 58 1.1 christos 59 1.1 christos p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME); 60 1.1 christos if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Default Provider")) 61 1.1 christos return 0; 62 1.1 christos p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION); 63 1.1 christos if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR)) 64 1.1 christos return 0; 65 1.1 christos p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO); 66 1.1 christos if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR)) 67 1.1 christos return 0; 68 1.1 christos p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_STATUS); 69 1.1 christos if (p != NULL && !OSSL_PARAM_set_int(p, ossl_prov_is_running())) 70 1.1 christos return 0; 71 1.1 christos return 1; 72 1.1 christos } 73 1.1 christos 74 1.1 christos /* 75 1.1 christos * For the algorithm names, we use the following formula for our primary 76 1.1 christos * names: 77 1.1 christos * 78 1.1 christos * ALGNAME[VERSION?][-SUBNAME[VERSION?]?][-SIZE?][-MODE?] 79 1.1 christos * 80 1.1 christos * VERSION is only present if there are multiple versions of 81 1.1 christos * an alg (MD2, MD4, MD5). It may be omitted if there is only 82 1.1 christos * one version (if a subsequent version is released in the future, 83 1.1 christos * we can always change the canonical name, and add the old name 84 1.1 christos * as an alias). 85 1.1 christos * 86 1.1 christos * SUBNAME may be present where we are combining multiple 87 1.1 christos * algorithms together, e.g. MD5-SHA1. 88 1.1 christos * 89 1.1 christos * SIZE is only present if multiple versions of an algorithm exist 90 1.1 christos * with different sizes (e.g. AES-128-CBC, AES-256-CBC) 91 1.1 christos * 92 1.1 christos * MODE is only present where applicable. 93 1.1 christos * 94 1.1 christos * We add diverse other names where applicable, such as the names that 95 1.1 christos * NIST uses, or that are used for ASN.1 OBJECT IDENTIFIERs, or names 96 1.1 christos * we have used historically. 97 1.1 christos * 98 1.1 christos * Algorithm names are case insensitive, but we use all caps in our "canonical" 99 1.1 christos * names for consistency. 100 1.1 christos */ 101 1.1 christos static const OSSL_ALGORITHM deflt_digests[] = { 102 1.1 christos /* Our primary name:NIST name[:our older names] */ 103 1.1 christos { PROV_NAMES_SHA1, "provider=default", ossl_sha1_functions }, 104 1.1 christos { PROV_NAMES_SHA2_224, "provider=default", ossl_sha224_functions }, 105 1.1 christos { PROV_NAMES_SHA2_256, "provider=default", ossl_sha256_functions }, 106 1.1 christos { PROV_NAMES_SHA2_384, "provider=default", ossl_sha384_functions }, 107 1.1 christos { PROV_NAMES_SHA2_512, "provider=default", ossl_sha512_functions }, 108 1.1 christos { PROV_NAMES_SHA2_512_224, "provider=default", ossl_sha512_224_functions }, 109 1.1 christos { PROV_NAMES_SHA2_512_256, "provider=default", ossl_sha512_256_functions }, 110 1.1 christos 111 1.1 christos /* We agree with NIST here, so one name only */ 112 1.1 christos { PROV_NAMES_SHA3_224, "provider=default", ossl_sha3_224_functions }, 113 1.1 christos { PROV_NAMES_SHA3_256, "provider=default", ossl_sha3_256_functions }, 114 1.1 christos { PROV_NAMES_SHA3_384, "provider=default", ossl_sha3_384_functions }, 115 1.1 christos { PROV_NAMES_SHA3_512, "provider=default", ossl_sha3_512_functions }, 116 1.1 christos 117 1.1 christos /* 118 1.1 christos * KECCAK-KMAC-128 and KECCAK-KMAC-256 as hashes are mostly useful for 119 1.1 christos * the KMAC-128 and KMAC-256. 120 1.1 christos */ 121 1.1 christos { PROV_NAMES_KECCAK_KMAC_128, "provider=default", 122 1.1 christos ossl_keccak_kmac_128_functions }, 123 1.1 christos { PROV_NAMES_KECCAK_KMAC_256, "provider=default", 124 1.1 christos ossl_keccak_kmac_256_functions }, 125 1.1 christos 126 1.1 christos /* Our primary name:NIST name */ 127 1.1 christos { PROV_NAMES_SHAKE_128, "provider=default", ossl_shake_128_functions }, 128 1.1 christos { PROV_NAMES_SHAKE_256, "provider=default", ossl_shake_256_functions }, 129 1.1 christos 130 1.1 christos #ifndef OPENSSL_NO_BLAKE2 131 1.1 christos /* 132 1.1 christos * https://blake2.net/ doesn't specify size variants, 133 1.1 christos * but mentions that Bouncy Castle uses the names 134 1.1 christos * BLAKE2b-160, BLAKE2b-256, BLAKE2b-384, and BLAKE2b-512 135 1.1 christos * If we assume that "2b" and "2s" are versions, that pattern 136 1.1 christos * fits with ours. We also add our historical names. 137 1.1 christos */ 138 1.1 christos { PROV_NAMES_BLAKE2S_256, "provider=default", ossl_blake2s256_functions }, 139 1.1 christos { PROV_NAMES_BLAKE2B_512, "provider=default", ossl_blake2b512_functions }, 140 1.1 christos #endif /* OPENSSL_NO_BLAKE2 */ 141 1.1 christos 142 1.1 christos #ifndef OPENSSL_NO_SM3 143 1.1 christos { PROV_NAMES_SM3, "provider=default", ossl_sm3_functions }, 144 1.1 christos #endif /* OPENSSL_NO_SM3 */ 145 1.1 christos 146 1.1 christos #ifndef OPENSSL_NO_MD5 147 1.1 christos { PROV_NAMES_MD5, "provider=default", ossl_md5_functions }, 148 1.1 christos { PROV_NAMES_MD5_SHA1, "provider=default", ossl_md5_sha1_functions }, 149 1.1 christos #endif /* OPENSSL_NO_MD5 */ 150 1.1 christos 151 1.1 christos #ifndef OPENSSL_NO_RMD160 152 1.1 christos { PROV_NAMES_RIPEMD_160, "provider=default", ossl_ripemd160_functions }, 153 1.1 christos #endif /* OPENSSL_NO_RMD160 */ 154 1.1 christos 155 1.1 christos { PROV_NAMES_NULL, "provider=default", ossl_nullmd_functions }, 156 1.1 christos { NULL, NULL, NULL } 157 1.1 christos }; 158 1.1 christos 159 1.1 christos static const OSSL_ALGORITHM_CAPABLE deflt_ciphers[] = { 160 1.1 christos ALG(PROV_NAMES_NULL, ossl_null_functions), 161 1.1 christos ALG(PROV_NAMES_AES_256_ECB, ossl_aes256ecb_functions), 162 1.1 christos ALG(PROV_NAMES_AES_192_ECB, ossl_aes192ecb_functions), 163 1.1 christos ALG(PROV_NAMES_AES_128_ECB, ossl_aes128ecb_functions), 164 1.1 christos ALG(PROV_NAMES_AES_256_CBC, ossl_aes256cbc_functions), 165 1.1 christos ALG(PROV_NAMES_AES_192_CBC, ossl_aes192cbc_functions), 166 1.1 christos ALG(PROV_NAMES_AES_128_CBC, ossl_aes128cbc_functions), 167 1.1 christos ALG(PROV_NAMES_AES_128_CBC_CTS, ossl_aes128cbc_cts_functions), 168 1.1 christos ALG(PROV_NAMES_AES_192_CBC_CTS, ossl_aes192cbc_cts_functions), 169 1.1 christos ALG(PROV_NAMES_AES_256_CBC_CTS, ossl_aes256cbc_cts_functions), 170 1.1 christos ALG(PROV_NAMES_AES_256_OFB, ossl_aes256ofb_functions), 171 1.1 christos ALG(PROV_NAMES_AES_192_OFB, ossl_aes192ofb_functions), 172 1.1 christos ALG(PROV_NAMES_AES_128_OFB, ossl_aes128ofb_functions), 173 1.1 christos ALG(PROV_NAMES_AES_256_CFB, ossl_aes256cfb_functions), 174 1.1 christos ALG(PROV_NAMES_AES_192_CFB, ossl_aes192cfb_functions), 175 1.1 christos ALG(PROV_NAMES_AES_128_CFB, ossl_aes128cfb_functions), 176 1.1 christos ALG(PROV_NAMES_AES_256_CFB1, ossl_aes256cfb1_functions), 177 1.1 christos ALG(PROV_NAMES_AES_192_CFB1, ossl_aes192cfb1_functions), 178 1.1 christos ALG(PROV_NAMES_AES_128_CFB1, ossl_aes128cfb1_functions), 179 1.1 christos ALG(PROV_NAMES_AES_256_CFB8, ossl_aes256cfb8_functions), 180 1.1 christos ALG(PROV_NAMES_AES_192_CFB8, ossl_aes192cfb8_functions), 181 1.1 christos ALG(PROV_NAMES_AES_128_CFB8, ossl_aes128cfb8_functions), 182 1.1 christos ALG(PROV_NAMES_AES_256_CTR, ossl_aes256ctr_functions), 183 1.1 christos ALG(PROV_NAMES_AES_192_CTR, ossl_aes192ctr_functions), 184 1.1 christos ALG(PROV_NAMES_AES_128_CTR, ossl_aes128ctr_functions), 185 1.1 christos ALG(PROV_NAMES_AES_256_XTS, ossl_aes256xts_functions), 186 1.1 christos ALG(PROV_NAMES_AES_128_XTS, ossl_aes128xts_functions), 187 1.1 christos #ifndef OPENSSL_NO_OCB 188 1.1 christos ALG(PROV_NAMES_AES_256_OCB, ossl_aes256ocb_functions), 189 1.1 christos ALG(PROV_NAMES_AES_192_OCB, ossl_aes192ocb_functions), 190 1.1 christos ALG(PROV_NAMES_AES_128_OCB, ossl_aes128ocb_functions), 191 1.1 christos #endif /* OPENSSL_NO_OCB */ 192 1.1 christos #ifndef OPENSSL_NO_SIV 193 1.1 christos ALG(PROV_NAMES_AES_128_SIV, ossl_aes128siv_functions), 194 1.1 christos ALG(PROV_NAMES_AES_192_SIV, ossl_aes192siv_functions), 195 1.1 christos ALG(PROV_NAMES_AES_256_SIV, ossl_aes256siv_functions), 196 1.1 christos #endif /* OPENSSL_NO_SIV */ 197 1.1 christos ALG(PROV_NAMES_AES_256_GCM, ossl_aes256gcm_functions), 198 1.1 christos ALG(PROV_NAMES_AES_192_GCM, ossl_aes192gcm_functions), 199 1.1 christos ALG(PROV_NAMES_AES_128_GCM, ossl_aes128gcm_functions), 200 1.1 christos ALG(PROV_NAMES_AES_256_CCM, ossl_aes256ccm_functions), 201 1.1 christos ALG(PROV_NAMES_AES_192_CCM, ossl_aes192ccm_functions), 202 1.1 christos ALG(PROV_NAMES_AES_128_CCM, ossl_aes128ccm_functions), 203 1.1 christos ALG(PROV_NAMES_AES_256_WRAP, ossl_aes256wrap_functions), 204 1.1 christos ALG(PROV_NAMES_AES_192_WRAP, ossl_aes192wrap_functions), 205 1.1 christos ALG(PROV_NAMES_AES_128_WRAP, ossl_aes128wrap_functions), 206 1.1 christos ALG(PROV_NAMES_AES_256_WRAP_PAD, ossl_aes256wrappad_functions), 207 1.1 christos ALG(PROV_NAMES_AES_192_WRAP_PAD, ossl_aes192wrappad_functions), 208 1.1 christos ALG(PROV_NAMES_AES_128_WRAP_PAD, ossl_aes128wrappad_functions), 209 1.1 christos ALG(PROV_NAMES_AES_256_WRAP_INV, ossl_aes256wrapinv_functions), 210 1.1 christos ALG(PROV_NAMES_AES_192_WRAP_INV, ossl_aes192wrapinv_functions), 211 1.1 christos ALG(PROV_NAMES_AES_128_WRAP_INV, ossl_aes128wrapinv_functions), 212 1.1 christos ALG(PROV_NAMES_AES_256_WRAP_PAD_INV, ossl_aes256wrappadinv_functions), 213 1.1 christos ALG(PROV_NAMES_AES_192_WRAP_PAD_INV, ossl_aes192wrappadinv_functions), 214 1.1 christos ALG(PROV_NAMES_AES_128_WRAP_PAD_INV, ossl_aes128wrappadinv_functions), 215 1.1 christos ALGC(PROV_NAMES_AES_128_CBC_HMAC_SHA1, ossl_aes128cbc_hmac_sha1_functions, 216 1.1 christos ossl_cipher_capable_aes_cbc_hmac_sha1), 217 1.1 christos ALGC(PROV_NAMES_AES_256_CBC_HMAC_SHA1, ossl_aes256cbc_hmac_sha1_functions, 218 1.1 christos ossl_cipher_capable_aes_cbc_hmac_sha1), 219 1.1 christos ALGC(PROV_NAMES_AES_128_CBC_HMAC_SHA256, ossl_aes128cbc_hmac_sha256_functions, 220 1.1 christos ossl_cipher_capable_aes_cbc_hmac_sha256), 221 1.1 christos ALGC(PROV_NAMES_AES_256_CBC_HMAC_SHA256, ossl_aes256cbc_hmac_sha256_functions, 222 1.1 christos ossl_cipher_capable_aes_cbc_hmac_sha256), 223 1.1 christos #ifndef OPENSSL_NO_ARIA 224 1.1 christos ALG(PROV_NAMES_ARIA_256_GCM, ossl_aria256gcm_functions), 225 1.1 christos ALG(PROV_NAMES_ARIA_192_GCM, ossl_aria192gcm_functions), 226 1.1 christos ALG(PROV_NAMES_ARIA_128_GCM, ossl_aria128gcm_functions), 227 1.1 christos ALG(PROV_NAMES_ARIA_256_CCM, ossl_aria256ccm_functions), 228 1.1 christos ALG(PROV_NAMES_ARIA_192_CCM, ossl_aria192ccm_functions), 229 1.1 christos ALG(PROV_NAMES_ARIA_128_CCM, ossl_aria128ccm_functions), 230 1.1 christos ALG(PROV_NAMES_ARIA_256_ECB, ossl_aria256ecb_functions), 231 1.1 christos ALG(PROV_NAMES_ARIA_192_ECB, ossl_aria192ecb_functions), 232 1.1 christos ALG(PROV_NAMES_ARIA_128_ECB, ossl_aria128ecb_functions), 233 1.1 christos ALG(PROV_NAMES_ARIA_256_CBC, ossl_aria256cbc_functions), 234 1.1 christos ALG(PROV_NAMES_ARIA_192_CBC, ossl_aria192cbc_functions), 235 1.1 christos ALG(PROV_NAMES_ARIA_128_CBC, ossl_aria128cbc_functions), 236 1.1 christos ALG(PROV_NAMES_ARIA_256_OFB, ossl_aria256ofb_functions), 237 1.1 christos ALG(PROV_NAMES_ARIA_192_OFB, ossl_aria192ofb_functions), 238 1.1 christos ALG(PROV_NAMES_ARIA_128_OFB, ossl_aria128ofb_functions), 239 1.1 christos ALG(PROV_NAMES_ARIA_256_CFB, ossl_aria256cfb_functions), 240 1.1 christos ALG(PROV_NAMES_ARIA_192_CFB, ossl_aria192cfb_functions), 241 1.1 christos ALG(PROV_NAMES_ARIA_128_CFB, ossl_aria128cfb_functions), 242 1.1 christos ALG(PROV_NAMES_ARIA_256_CFB1, ossl_aria256cfb1_functions), 243 1.1 christos ALG(PROV_NAMES_ARIA_192_CFB1, ossl_aria192cfb1_functions), 244 1.1 christos ALG(PROV_NAMES_ARIA_128_CFB1, ossl_aria128cfb1_functions), 245 1.1 christos ALG(PROV_NAMES_ARIA_256_CFB8, ossl_aria256cfb8_functions), 246 1.1 christos ALG(PROV_NAMES_ARIA_192_CFB8, ossl_aria192cfb8_functions), 247 1.1 christos ALG(PROV_NAMES_ARIA_128_CFB8, ossl_aria128cfb8_functions), 248 1.1 christos ALG(PROV_NAMES_ARIA_256_CTR, ossl_aria256ctr_functions), 249 1.1 christos ALG(PROV_NAMES_ARIA_192_CTR, ossl_aria192ctr_functions), 250 1.1 christos ALG(PROV_NAMES_ARIA_128_CTR, ossl_aria128ctr_functions), 251 1.1 christos #endif /* OPENSSL_NO_ARIA */ 252 1.1 christos #ifndef OPENSSL_NO_CAMELLIA 253 1.1 christos ALG(PROV_NAMES_CAMELLIA_256_ECB, ossl_camellia256ecb_functions), 254 1.1 christos ALG(PROV_NAMES_CAMELLIA_192_ECB, ossl_camellia192ecb_functions), 255 1.1 christos ALG(PROV_NAMES_CAMELLIA_128_ECB, ossl_camellia128ecb_functions), 256 1.1 christos ALG(PROV_NAMES_CAMELLIA_256_CBC, ossl_camellia256cbc_functions), 257 1.1 christos ALG(PROV_NAMES_CAMELLIA_192_CBC, ossl_camellia192cbc_functions), 258 1.1 christos ALG(PROV_NAMES_CAMELLIA_128_CBC, ossl_camellia128cbc_functions), 259 1.1 christos ALG(PROV_NAMES_CAMELLIA_128_CBC_CTS, ossl_camellia128cbc_cts_functions), 260 1.1 christos ALG(PROV_NAMES_CAMELLIA_192_CBC_CTS, ossl_camellia192cbc_cts_functions), 261 1.1 christos ALG(PROV_NAMES_CAMELLIA_256_CBC_CTS, ossl_camellia256cbc_cts_functions), 262 1.1 christos ALG(PROV_NAMES_CAMELLIA_256_OFB, ossl_camellia256ofb_functions), 263 1.1 christos ALG(PROV_NAMES_CAMELLIA_192_OFB, ossl_camellia192ofb_functions), 264 1.1 christos ALG(PROV_NAMES_CAMELLIA_128_OFB, ossl_camellia128ofb_functions), 265 1.1 christos ALG(PROV_NAMES_CAMELLIA_256_CFB, ossl_camellia256cfb_functions), 266 1.1 christos ALG(PROV_NAMES_CAMELLIA_192_CFB, ossl_camellia192cfb_functions), 267 1.1 christos ALG(PROV_NAMES_CAMELLIA_128_CFB, ossl_camellia128cfb_functions), 268 1.1 christos ALG(PROV_NAMES_CAMELLIA_256_CFB1, ossl_camellia256cfb1_functions), 269 1.1 christos ALG(PROV_NAMES_CAMELLIA_192_CFB1, ossl_camellia192cfb1_functions), 270 1.1 christos ALG(PROV_NAMES_CAMELLIA_128_CFB1, ossl_camellia128cfb1_functions), 271 1.1 christos ALG(PROV_NAMES_CAMELLIA_256_CFB8, ossl_camellia256cfb8_functions), 272 1.1 christos ALG(PROV_NAMES_CAMELLIA_192_CFB8, ossl_camellia192cfb8_functions), 273 1.1 christos ALG(PROV_NAMES_CAMELLIA_128_CFB8, ossl_camellia128cfb8_functions), 274 1.1 christos ALG(PROV_NAMES_CAMELLIA_256_CTR, ossl_camellia256ctr_functions), 275 1.1 christos ALG(PROV_NAMES_CAMELLIA_192_CTR, ossl_camellia192ctr_functions), 276 1.1 christos ALG(PROV_NAMES_CAMELLIA_128_CTR, ossl_camellia128ctr_functions), 277 1.1 christos #endif /* OPENSSL_NO_CAMELLIA */ 278 1.1 christos #ifndef OPENSSL_NO_DES 279 1.1 christos ALG(PROV_NAMES_DES_EDE3_ECB, ossl_tdes_ede3_ecb_functions), 280 1.1 christos ALG(PROV_NAMES_DES_EDE3_CBC, ossl_tdes_ede3_cbc_functions), 281 1.1 christos ALG(PROV_NAMES_DES_EDE3_OFB, ossl_tdes_ede3_ofb_functions), 282 1.1 christos ALG(PROV_NAMES_DES_EDE3_CFB, ossl_tdes_ede3_cfb_functions), 283 1.1 christos ALG(PROV_NAMES_DES_EDE3_CFB8, ossl_tdes_ede3_cfb8_functions), 284 1.1 christos ALG(PROV_NAMES_DES_EDE3_CFB1, ossl_tdes_ede3_cfb1_functions), 285 1.1 christos ALG(PROV_NAMES_DES3_WRAP, ossl_tdes_wrap_cbc_functions), 286 1.1 christos ALG(PROV_NAMES_DES_EDE_ECB, ossl_tdes_ede2_ecb_functions), 287 1.1 christos ALG(PROV_NAMES_DES_EDE_CBC, ossl_tdes_ede2_cbc_functions), 288 1.1 christos ALG(PROV_NAMES_DES_EDE_OFB, ossl_tdes_ede2_ofb_functions), 289 1.1 christos ALG(PROV_NAMES_DES_EDE_CFB, ossl_tdes_ede2_cfb_functions), 290 1.1 christos #endif /* OPENSSL_NO_DES */ 291 1.1 christos #ifndef OPENSSL_NO_SM4 292 1.1 christos ALG(PROV_NAMES_SM4_ECB, ossl_sm4128ecb_functions), 293 1.1 christos ALG(PROV_NAMES_SM4_CBC, ossl_sm4128cbc_functions), 294 1.1 christos ALG(PROV_NAMES_SM4_CTR, ossl_sm4128ctr_functions), 295 1.1 christos ALG(PROV_NAMES_SM4_OFB, ossl_sm4128ofb128_functions), 296 1.1 christos ALG(PROV_NAMES_SM4_CFB, ossl_sm4128cfb128_functions), 297 1.1 christos #endif /* OPENSSL_NO_SM4 */ 298 1.1 christos #ifndef OPENSSL_NO_CHACHA 299 1.1 christos ALG(PROV_NAMES_ChaCha20, ossl_chacha20_functions), 300 1.1 christos # ifndef OPENSSL_NO_POLY1305 301 1.1 christos ALG(PROV_NAMES_ChaCha20_Poly1305, ossl_chacha20_ossl_poly1305_functions), 302 1.1 christos # endif /* OPENSSL_NO_POLY1305 */ 303 1.1 christos #endif /* OPENSSL_NO_CHACHA */ 304 1.1 christos { { NULL, NULL, NULL }, NULL } 305 1.1 christos }; 306 1.1 christos static OSSL_ALGORITHM exported_ciphers[OSSL_NELEM(deflt_ciphers)]; 307 1.1 christos 308 1.1 christos static const OSSL_ALGORITHM deflt_macs[] = { 309 1.1 christos #ifndef OPENSSL_NO_BLAKE2 310 1.1 christos { PROV_NAMES_BLAKE2BMAC, "provider=default", ossl_blake2bmac_functions }, 311 1.1 christos { PROV_NAMES_BLAKE2SMAC, "provider=default", ossl_blake2smac_functions }, 312 1.1 christos #endif 313 1.1 christos #ifndef OPENSSL_NO_CMAC 314 1.1 christos { PROV_NAMES_CMAC, "provider=default", ossl_cmac_functions }, 315 1.1 christos #endif 316 1.1 christos { PROV_NAMES_GMAC, "provider=default", ossl_gmac_functions }, 317 1.1 christos { PROV_NAMES_HMAC, "provider=default", ossl_hmac_functions }, 318 1.1 christos { PROV_NAMES_KMAC_128, "provider=default", ossl_kmac128_functions }, 319 1.1 christos { PROV_NAMES_KMAC_256, "provider=default", ossl_kmac256_functions }, 320 1.1 christos #ifndef OPENSSL_NO_SIPHASH 321 1.1 christos { PROV_NAMES_SIPHASH, "provider=default", ossl_siphash_functions }, 322 1.1 christos #endif 323 1.1 christos #ifndef OPENSSL_NO_POLY1305 324 1.1 christos { PROV_NAMES_POLY1305, "provider=default", ossl_poly1305_functions }, 325 1.1 christos #endif 326 1.1 christos { NULL, NULL, NULL } 327 1.1 christos }; 328 1.1 christos 329 1.1 christos static const OSSL_ALGORITHM deflt_kdfs[] = { 330 1.1 christos { PROV_NAMES_HKDF, "provider=default", ossl_kdf_hkdf_functions }, 331 1.1 christos { PROV_NAMES_TLS1_3_KDF, "provider=default", 332 1.1 christos ossl_kdf_tls1_3_kdf_functions }, 333 1.1 christos { PROV_NAMES_SSKDF, "provider=default", ossl_kdf_sskdf_functions }, 334 1.1 christos { PROV_NAMES_PBKDF2, "provider=default", ossl_kdf_pbkdf2_functions }, 335 1.1 christos { PROV_NAMES_PKCS12KDF, "provider=default", ossl_kdf_pkcs12_functions }, 336 1.1 christos { PROV_NAMES_SSHKDF, "provider=default", ossl_kdf_sshkdf_functions }, 337 1.1 christos { PROV_NAMES_X963KDF, "provider=default", ossl_kdf_x963_kdf_functions }, 338 1.1 christos { PROV_NAMES_TLS1_PRF, "provider=default", ossl_kdf_tls1_prf_functions }, 339 1.1 christos { PROV_NAMES_KBKDF, "provider=default", ossl_kdf_kbkdf_functions }, 340 1.1 christos { PROV_NAMES_X942KDF_ASN1, "provider=default", ossl_kdf_x942_kdf_functions }, 341 1.1 christos #ifndef OPENSSL_NO_SCRYPT 342 1.1 christos { PROV_NAMES_SCRYPT, "provider=default", ossl_kdf_scrypt_functions }, 343 1.1 christos #endif 344 1.1 christos { PROV_NAMES_KRB5KDF, "provider=default", ossl_kdf_krb5kdf_functions }, 345 1.1 christos { NULL, NULL, NULL } 346 1.1 christos }; 347 1.1 christos 348 1.1 christos static const OSSL_ALGORITHM deflt_keyexch[] = { 349 1.1 christos #ifndef OPENSSL_NO_DH 350 1.1 christos { PROV_NAMES_DH, "provider=default", ossl_dh_keyexch_functions }, 351 1.1 christos #endif 352 1.1 christos #ifndef OPENSSL_NO_EC 353 1.1 christos { PROV_NAMES_ECDH, "provider=default", ossl_ecdh_keyexch_functions }, 354 1.1 christos { PROV_NAMES_X25519, "provider=default", ossl_x25519_keyexch_functions }, 355 1.1 christos { PROV_NAMES_X448, "provider=default", ossl_x448_keyexch_functions }, 356 1.1 christos #endif 357 1.1 christos { PROV_NAMES_TLS1_PRF, "provider=default", ossl_kdf_tls1_prf_keyexch_functions }, 358 1.1 christos { PROV_NAMES_HKDF, "provider=default", ossl_kdf_hkdf_keyexch_functions }, 359 1.1 christos { PROV_NAMES_SCRYPT, "provider=default", 360 1.1 christos ossl_kdf_scrypt_keyexch_functions }, 361 1.1 christos { NULL, NULL, NULL } 362 1.1 christos }; 363 1.1 christos 364 1.1 christos static const OSSL_ALGORITHM deflt_rands[] = { 365 1.1 christos { PROV_NAMES_CTR_DRBG, "provider=default", ossl_drbg_ctr_functions }, 366 1.1 christos { PROV_NAMES_HASH_DRBG, "provider=default", ossl_drbg_hash_functions }, 367 1.1 christos { PROV_NAMES_HMAC_DRBG, "provider=default", ossl_drbg_ossl_hmac_functions }, 368 1.1 christos { PROV_NAMES_SEED_SRC, "provider=default", ossl_seed_src_functions }, 369 1.1 christos { PROV_NAMES_TEST_RAND, "provider=default", ossl_test_rng_functions }, 370 1.1 christos { NULL, NULL, NULL } 371 1.1 christos }; 372 1.1 christos 373 1.1 christos static const OSSL_ALGORITHM deflt_signature[] = { 374 1.1 christos #ifndef OPENSSL_NO_DSA 375 1.1 christos { PROV_NAMES_DSA, "provider=default", ossl_dsa_signature_functions }, 376 1.1 christos #endif 377 1.1 christos { PROV_NAMES_RSA, "provider=default", ossl_rsa_signature_functions }, 378 1.1 christos #ifndef OPENSSL_NO_EC 379 1.1 christos { PROV_NAMES_ED25519, "provider=default", ossl_ed25519_signature_functions }, 380 1.1 christos { PROV_NAMES_ED448, "provider=default", ossl_ed448_signature_functions }, 381 1.1 christos { PROV_NAMES_ECDSA, "provider=default", ossl_ecdsa_signature_functions }, 382 1.1 christos # ifndef OPENSSL_NO_SM2 383 1.1 christos { PROV_NAMES_SM2, "provider=default", ossl_sm2_signature_functions }, 384 1.1 christos # endif 385 1.1 christos #endif 386 1.1 christos { PROV_NAMES_HMAC, "provider=default", ossl_mac_legacy_hmac_signature_functions }, 387 1.1 christos { PROV_NAMES_SIPHASH, "provider=default", 388 1.1 christos ossl_mac_legacy_siphash_signature_functions }, 389 1.1 christos #ifndef OPENSSL_NO_POLY1305 390 1.1 christos { PROV_NAMES_POLY1305, "provider=default", 391 1.1 christos ossl_mac_legacy_poly1305_signature_functions }, 392 1.1 christos #endif 393 1.1 christos #ifndef OPENSSL_NO_CMAC 394 1.1 christos { PROV_NAMES_CMAC, "provider=default", ossl_mac_legacy_cmac_signature_functions }, 395 1.1 christos #endif 396 1.1 christos { NULL, NULL, NULL } 397 1.1 christos }; 398 1.1 christos 399 1.1 christos static const OSSL_ALGORITHM deflt_asym_cipher[] = { 400 1.1 christos { PROV_NAMES_RSA, "provider=default", ossl_rsa_asym_cipher_functions }, 401 1.1 christos #ifndef OPENSSL_NO_SM2 402 1.1 christos { PROV_NAMES_SM2, "provider=default", ossl_sm2_asym_cipher_functions }, 403 1.1 christos #endif 404 1.1 christos { NULL, NULL, NULL } 405 1.1 christos }; 406 1.1 christos 407 1.1 christos static const OSSL_ALGORITHM deflt_asym_kem[] = { 408 1.1 christos { PROV_NAMES_RSA, "provider=default", ossl_rsa_asym_kem_functions }, 409 1.1 christos { NULL, NULL, NULL } 410 1.1 christos }; 411 1.1 christos 412 1.1 christos static const OSSL_ALGORITHM deflt_keymgmt[] = { 413 1.1 christos #ifndef OPENSSL_NO_DH 414 1.1 christos { PROV_NAMES_DH, "provider=default", ossl_dh_keymgmt_functions, 415 1.1 christos PROV_DESCS_DH }, 416 1.1 christos { PROV_NAMES_DHX, "provider=default", ossl_dhx_keymgmt_functions, 417 1.1 christos PROV_DESCS_DHX }, 418 1.1 christos #endif 419 1.1 christos #ifndef OPENSSL_NO_DSA 420 1.1 christos { PROV_NAMES_DSA, "provider=default", ossl_dsa_keymgmt_functions, 421 1.1 christos PROV_DESCS_DSA}, 422 1.1 christos #endif 423 1.1 christos { PROV_NAMES_RSA, "provider=default", ossl_rsa_keymgmt_functions, 424 1.1 christos PROV_DESCS_RSA }, 425 1.1 christos { PROV_NAMES_RSA_PSS, "provider=default", ossl_rsapss_keymgmt_functions, 426 1.1 christos PROV_DESCS_RSA_PSS }, 427 1.1 christos #ifndef OPENSSL_NO_EC 428 1.1 christos { PROV_NAMES_EC, "provider=default", ossl_ec_keymgmt_functions, 429 1.1 christos PROV_DESCS_EC }, 430 1.1 christos { PROV_NAMES_X25519, "provider=default", ossl_x25519_keymgmt_functions, 431 1.1 christos PROV_DESCS_X25519 }, 432 1.1 christos { PROV_NAMES_X448, "provider=default", ossl_x448_keymgmt_functions, 433 1.1 christos PROV_DESCS_X448 }, 434 1.1 christos { PROV_NAMES_ED25519, "provider=default", ossl_ed25519_keymgmt_functions, 435 1.1 christos PROV_DESCS_ED25519 }, 436 1.1 christos { PROV_NAMES_ED448, "provider=default", ossl_ed448_keymgmt_functions, 437 1.1 christos PROV_DESCS_ED448 }, 438 1.1 christos #endif 439 1.1 christos { PROV_NAMES_TLS1_PRF, "provider=default", ossl_kdf_keymgmt_functions, 440 1.1 christos PROV_DESCS_TLS1_PRF_SIGN }, 441 1.1 christos { PROV_NAMES_HKDF, "provider=default", ossl_kdf_keymgmt_functions, 442 1.1 christos PROV_DESCS_HKDF_SIGN }, 443 1.1 christos { PROV_NAMES_SCRYPT, "provider=default", ossl_kdf_keymgmt_functions, 444 1.1 christos PROV_DESCS_SCRYPT_SIGN }, 445 1.1 christos { PROV_NAMES_HMAC, "provider=default", ossl_mac_legacy_keymgmt_functions, 446 1.1 christos PROV_DESCS_HMAC_SIGN }, 447 1.1 christos { PROV_NAMES_SIPHASH, "provider=default", ossl_mac_legacy_keymgmt_functions, 448 1.1 christos PROV_DESCS_SIPHASH_SIGN }, 449 1.1 christos #ifndef OPENSSL_NO_POLY1305 450 1.1 christos { PROV_NAMES_POLY1305, "provider=default", ossl_mac_legacy_keymgmt_functions, 451 1.1 christos PROV_DESCS_POLY1305_SIGN }, 452 1.1 christos #endif 453 1.1 christos #ifndef OPENSSL_NO_CMAC 454 1.1 christos { PROV_NAMES_CMAC, "provider=default", ossl_cmac_legacy_keymgmt_functions, 455 1.1 christos PROV_DESCS_CMAC_SIGN }, 456 1.1 christos #endif 457 1.1 christos #ifndef OPENSSL_NO_SM2 458 1.1 christos { PROV_NAMES_SM2, "provider=default", ossl_sm2_keymgmt_functions, 459 1.1 christos PROV_DESCS_SM2 }, 460 1.1 christos #endif 461 1.1 christos { NULL, NULL, NULL } 462 1.1 christos }; 463 1.1 christos 464 1.1 christos static const OSSL_ALGORITHM deflt_encoder[] = { 465 1.1 christos #define ENCODER_PROVIDER "default" 466 1.1 christos #include "encoders.inc" 467 1.1 christos { NULL, NULL, NULL } 468 1.1 christos #undef ENCODER_PROVIDER 469 1.1 christos }; 470 1.1 christos 471 1.1 christos static const OSSL_ALGORITHM deflt_decoder[] = { 472 1.1 christos #define DECODER_PROVIDER "default" 473 1.1 christos #include "decoders.inc" 474 1.1 christos { NULL, NULL, NULL } 475 1.1 christos #undef DECODER_PROVIDER 476 1.1 christos }; 477 1.1 christos 478 1.1 christos static const OSSL_ALGORITHM deflt_store[] = { 479 1.1 christos #define STORE(name, _fips, func_table) \ 480 1.1 christos { name, "provider=default,fips=" _fips, (func_table) }, 481 1.1 christos 482 1.1 christos #include "stores.inc" 483 1.1 christos { NULL, NULL, NULL } 484 1.1 christos #undef STORE 485 1.1 christos }; 486 1.1 christos 487 1.1 christos static const OSSL_ALGORITHM *deflt_query(void *provctx, int operation_id, 488 1.1 christos int *no_cache) 489 1.1 christos { 490 1.1 christos *no_cache = 0; 491 1.1 christos switch (operation_id) { 492 1.1 christos case OSSL_OP_DIGEST: 493 1.1 christos return deflt_digests; 494 1.1 christos case OSSL_OP_CIPHER: 495 1.1 christos return exported_ciphers; 496 1.1 christos case OSSL_OP_MAC: 497 1.1 christos return deflt_macs; 498 1.1 christos case OSSL_OP_KDF: 499 1.1 christos return deflt_kdfs; 500 1.1 christos case OSSL_OP_RAND: 501 1.1 christos return deflt_rands; 502 1.1 christos case OSSL_OP_KEYMGMT: 503 1.1 christos return deflt_keymgmt; 504 1.1 christos case OSSL_OP_KEYEXCH: 505 1.1 christos return deflt_keyexch; 506 1.1 christos case OSSL_OP_SIGNATURE: 507 1.1 christos return deflt_signature; 508 1.1 christos case OSSL_OP_ASYM_CIPHER: 509 1.1 christos return deflt_asym_cipher; 510 1.1 christos case OSSL_OP_KEM: 511 1.1 christos return deflt_asym_kem; 512 1.1 christos case OSSL_OP_ENCODER: 513 1.1 christos return deflt_encoder; 514 1.1 christos case OSSL_OP_DECODER: 515 1.1 christos return deflt_decoder; 516 1.1 christos case OSSL_OP_STORE: 517 1.1 christos return deflt_store; 518 1.1 christos } 519 1.1 christos return NULL; 520 1.1 christos } 521 1.1 christos 522 1.1 christos 523 1.1 christos static void deflt_teardown(void *provctx) 524 1.1 christos { 525 1.1 christos BIO_meth_free(ossl_prov_ctx_get0_core_bio_method(provctx)); 526 1.1 christos ossl_prov_ctx_free(provctx); 527 1.1 christos } 528 1.1 christos 529 1.1 christos /* Functions we provide to the core */ 530 1.1 christos static const OSSL_DISPATCH deflt_dispatch_table[] = { 531 1.1 christos { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))deflt_teardown }, 532 1.1 christos { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))deflt_gettable_params }, 533 1.1 christos { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))deflt_get_params }, 534 1.1 christos { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))deflt_query }, 535 1.1 christos { OSSL_FUNC_PROVIDER_GET_CAPABILITIES, 536 1.1 christos (void (*)(void))ossl_prov_get_capabilities }, 537 1.1 christos { 0, NULL } 538 1.1 christos }; 539 1.1 christos 540 1.1 christos OSSL_provider_init_fn ossl_default_provider_init; 541 1.1 christos 542 1.1 christos int ossl_default_provider_init(const OSSL_CORE_HANDLE *handle, 543 1.1 christos const OSSL_DISPATCH *in, 544 1.1 christos const OSSL_DISPATCH **out, 545 1.1 christos void **provctx) 546 1.1 christos { 547 1.1 christos OSSL_FUNC_core_get_libctx_fn *c_get_libctx = NULL; 548 1.1 christos BIO_METHOD *corebiometh; 549 1.1 christos 550 1.1 christos if (!ossl_prov_bio_from_dispatch(in) 551 1.1 christos || !ossl_prov_seeding_from_dispatch(in)) 552 1.1 christos return 0; 553 1.1 christos for (; in->function_id != 0; in++) { 554 1.1 christos switch (in->function_id) { 555 1.1 christos case OSSL_FUNC_CORE_GETTABLE_PARAMS: 556 1.1 christos c_gettable_params = OSSL_FUNC_core_gettable_params(in); 557 1.1 christos break; 558 1.1 christos case OSSL_FUNC_CORE_GET_PARAMS: 559 1.1 christos c_get_params = OSSL_FUNC_core_get_params(in); 560 1.1 christos break; 561 1.1 christos case OSSL_FUNC_CORE_GET_LIBCTX: 562 1.1 christos c_get_libctx = OSSL_FUNC_core_get_libctx(in); 563 1.1 christos break; 564 1.1 christos default: 565 1.1 christos /* Just ignore anything we don't understand */ 566 1.1 christos break; 567 1.1 christos } 568 1.1 christos } 569 1.1 christos 570 1.1 christos if (c_get_libctx == NULL) 571 1.1 christos return 0; 572 1.1 christos 573 1.1 christos /* 574 1.1 christos * We want to make sure that all calls from this provider that requires 575 1.1 christos * a library context use the same context as the one used to call our 576 1.1 christos * functions. We do that by passing it along in the provider context. 577 1.1 christos * 578 1.1 christos * This only works for built-in providers. Most providers should 579 1.1 christos * create their own library context. 580 1.1 christos */ 581 1.1 christos if ((*provctx = ossl_prov_ctx_new()) == NULL 582 1.1 christos || (corebiometh = ossl_bio_prov_init_bio_method()) == NULL) { 583 1.1 christos ossl_prov_ctx_free(*provctx); 584 1.1 christos *provctx = NULL; 585 1.1 christos return 0; 586 1.1 christos } 587 1.1 christos ossl_prov_ctx_set0_libctx(*provctx, 588 1.1 christos (OSSL_LIB_CTX *)c_get_libctx(handle)); 589 1.1 christos ossl_prov_ctx_set0_handle(*provctx, handle); 590 1.1 christos ossl_prov_ctx_set0_core_bio_method(*provctx, corebiometh); 591 1.1 christos 592 1.1 christos *out = deflt_dispatch_table; 593 1.1 christos ossl_prov_cache_exported_algorithms(deflt_ciphers, exported_ciphers); 594 1.1 christos 595 1.1 christos return 1; 596 1.1 christos } 597