+#endif
+
+struct provider_group_data_st {
+ SSL_CTX *ctx;
+ OSSL_PROVIDER *provider;
+};
+
+#define TLS_GROUP_LIST_MALLOC_BLOCK_SIZE 10
+static OSSL_CALLBACK add_provider_groups;
+static int add_provider_groups(const OSSL_PARAM params[], void *data)
+{
+ struct provider_group_data_st *pgd = data;
+ SSL_CTX *ctx = pgd->ctx;
+ OSSL_PROVIDER *provider = pgd->provider;
+ const OSSL_PARAM *p;
+ TLS_GROUP_INFO *ginf = NULL;
+ EVP_KEYMGMT *keymgmt;
+ unsigned int gid;
+ int ret = 0;
+
+ if (ctx->group_list_max_len == ctx->group_list_len) {
+ TLS_GROUP_INFO *tmp = NULL;
+
+ if (ctx->group_list_max_len == 0)
+ tmp = OPENSSL_malloc(sizeof(TLS_GROUP_INFO)
+ * TLS_GROUP_LIST_MALLOC_BLOCK_SIZE);
+ else
+ tmp = OPENSSL_realloc(ctx->group_list,
+ (ctx->group_list_max_len
+ + TLS_GROUP_LIST_MALLOC_BLOCK_SIZE)
+ * sizeof(TLS_GROUP_INFO));
+ if (tmp == NULL) {
+ SSLerr(0, ERR_R_MALLOC_FAILURE);
+ return 0;
+ }
+ ctx->group_list = tmp;
+ memset(tmp + ctx->group_list_max_len,
+ 0,
+ sizeof(TLS_GROUP_INFO) * TLS_GROUP_LIST_MALLOC_BLOCK_SIZE);
+ ctx->group_list_max_len += TLS_GROUP_LIST_MALLOC_BLOCK_SIZE;
+ }
+
+ ginf = &ctx->group_list[ctx->group_list_len];
+
+ p = OSSL_PARAM_locate_const(params, OSSL_CAPABILITY_TLS_GROUP_NAME);
+ if (p == NULL || p->data_type != OSSL_PARAM_UTF8_STRING) {
+ SSLerr(0, ERR_R_PASSED_INVALID_ARGUMENT);
+ goto err;
+ }
+ ginf->tlsname = OPENSSL_strdup(p->data);
+ if (ginf->tlsname == NULL) {
+ SSLerr(0, ERR_R_MALLOC_FAILURE);
+ goto err;
+ }
+
+ p = OSSL_PARAM_locate_const(params, OSSL_CAPABILITY_TLS_GROUP_NAME_INTERNAL);
+ if (p == NULL || p->data_type != OSSL_PARAM_UTF8_STRING) {
+ SSLerr(0, ERR_R_PASSED_INVALID_ARGUMENT);
+ goto err;
+ }
+ ginf->realname = OPENSSL_strdup(p->data);
+ if (ginf->realname == NULL) {
+ SSLerr(0, ERR_R_MALLOC_FAILURE);
+ goto err;
+ }
+
+ p = OSSL_PARAM_locate_const(params, OSSL_CAPABILITY_TLS_GROUP_ID);
+ if (p == NULL || !OSSL_PARAM_get_uint(p, &gid) || gid > UINT16_MAX) {
+ SSLerr(0, ERR_R_PASSED_INVALID_ARGUMENT);
+ goto err;
+ }
+ ginf->group_id = (uint16_t)gid;
+
+ p = OSSL_PARAM_locate_const(params, OSSL_CAPABILITY_TLS_GROUP_ALG);
+ if (p == NULL || p->data_type != OSSL_PARAM_UTF8_STRING) {
+ SSLerr(0, ERR_R_PASSED_INVALID_ARGUMENT);
+ goto err;
+ }
+ ginf->algorithm = OPENSSL_strdup(p->data);
+ if (ginf->algorithm == NULL) {
+ SSLerr(0, ERR_R_MALLOC_FAILURE);
+ goto err;
+ }
+
+ p = OSSL_PARAM_locate_const(params, OSSL_CAPABILITY_TLS_GROUP_SECURITY_BITS);
+ if (p == NULL || !OSSL_PARAM_get_uint(p, &ginf->secbits)) {
+ SSLerr(0, ERR_R_PASSED_INVALID_ARGUMENT);
+ goto err;
+ }
+
+ p = OSSL_PARAM_locate_const(params, OSSL_CAPABILITY_TLS_GROUP_MIN_TLS);
+ if (p == NULL || !OSSL_PARAM_get_int(p, &ginf->mintls)) {
+ SSLerr(0, ERR_R_PASSED_INVALID_ARGUMENT);
+ goto err;
+ }
+
+ p = OSSL_PARAM_locate_const(params, OSSL_CAPABILITY_TLS_GROUP_MAX_TLS);
+ if (p == NULL || !OSSL_PARAM_get_int(p, &ginf->maxtls)) {
+ SSLerr(0, ERR_R_PASSED_INVALID_ARGUMENT);
+ return 0;
+ }
+
+ p = OSSL_PARAM_locate_const(params, OSSL_CAPABILITY_TLS_GROUP_MIN_DTLS);
+ if (p == NULL || !OSSL_PARAM_get_int(p, &ginf->mindtls)) {
+ SSLerr(0, ERR_R_PASSED_INVALID_ARGUMENT);
+ goto err;
+ }
+
+ p = OSSL_PARAM_locate_const(params, OSSL_CAPABILITY_TLS_GROUP_MAX_DTLS);
+ if (p == NULL || !OSSL_PARAM_get_int(p, &ginf->maxdtls)) {
+ SSLerr(0, ERR_R_PASSED_INVALID_ARGUMENT);
+ goto err;
+ }
+ /*
+ * Now check that the algorithm is actually usable for our property query
+ * string. Regardless of the result we still return success because we have
+ * successfully processed this group, even though we may decide not to use
+ * it.
+ */
+ ret = 1;
+ keymgmt = EVP_KEYMGMT_fetch(ctx->libctx, ginf->algorithm, ctx->propq);
+ if (keymgmt != NULL) {
+ /*
+ * We have successfully fetched the algorithm - however if the provider
+ * doesn't match this one then we ignore it.
+ *
+ * Note: We're cheating a little here. Technically if the same algorithm
+ * is available from more than one provider then it is undefined which
+ * implementation you will get back. Theoretically this could be
+ * different every time...we assume here that you'll always get the
+ * same one back if you repeat the exact same fetch. Is this a reasonable
+ * assumption to make (in which case perhaps we should document this
+ * behaviour)?
+ */
+ if (EVP_KEYMGMT_provider(keymgmt) == provider) {
+ /* We have a match - so we will use this group */
+ ctx->group_list_len++;
+ ginf = NULL;
+ }
+ EVP_KEYMGMT_free(keymgmt);
+ }
+ err:
+ if (ginf != NULL) {
+ OPENSSL_free(ginf->tlsname);
+ OPENSSL_free(ginf->realname);
+ OPENSSL_free(ginf->algorithm);
+ ginf->tlsname = ginf->realname = NULL;
+ }
+ return ret;
+}