Commit bd6352ec06 for openssl.org
commit bd6352ec062f23e8a1588ad7bf36f2cf4093e8a0
Author: Daiki Ueno <dueno@redhat.com>
Date: Mon Jul 13 12:01:08 2026 +0900
crypto: instrument X25519/X448 key derivation for crypto-auditing
This adds crypto-auditing instrumentation around X25519/X448 key
derivation, according to the definition:
https://github.com/latchset/crypto-auditing/blob/main/docs/registry.md#public-key-cryptography
Signed-off-by: Daiki Ueno <dueno@redhat.com>
Reviewed-by: Mounir Idrassi <mounir.idrassi@idrix.fr>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
MergeDate: Sat Nov 21 14:48:30 2026
(Merged from https://github.com/openssl/openssl/pull/32538)
diff --git a/crypto/evp/exchange.c b/crypto/evp/exchange.c
index 23c838d43a..8599d6c141 100644
--- a/crypto/evp/exchange.c
+++ b/crypto/evp/exchange.c
@@ -16,6 +16,7 @@
#include "internal/provider.h"
#include "internal/core.h"
#include "internal/numbers.h" /* includes SIZE_MAX */
+#include "internal/usdt.h"
#include "crypto/evp.h"
#include "evp_local.h"
@@ -371,6 +372,9 @@ int EVP_PKEY_derive_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[])
ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
goto err;
}
+
+ OSSL_USDT_new_child(ctx, ctx->op.kex.algctx);
+
ret = exchange->init(ctx->op.kex.algctx, provkey, params);
EVP_KEYMGMT_free(tmp_keymgmt);
diff --git a/crypto/evp/kem.c b/crypto/evp/kem.c
index 8ae968d5a5..dde59eb0fe 100644
--- a/crypto/evp/kem.c
+++ b/crypto/evp/kem.c
@@ -14,6 +14,7 @@
#include "internal/cryptlib.h"
#include "internal/provider.h"
#include "internal/core.h"
+#include "internal/usdt.h"
#include "crypto/evp.h"
#include "evp_local.h"
@@ -181,6 +182,8 @@ static int evp_kem_init(EVP_PKEY_CTX *ctx, int operation,
goto err;
}
+ OSSL_USDT_new_child(ctx, ctx->op.encap.algctx);
+
switch (operation) {
case EVP_PKEY_OP_ENCAPSULATE:
if (provauthkey != NULL && kem->auth_encapsulate_init != NULL) {
diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c
index 3ffe51d822..98fd3401af 100644
--- a/crypto/evp/pmeth_lib.c
+++ b/crypto/evp/pmeth_lib.c
@@ -31,6 +31,7 @@
#include "internal/numbers.h"
#include "internal/provider.h"
#include "internal/common.h"
+#include "internal/usdt.h"
#include "evp_local.h"
#ifndef FIPS_MODULE
@@ -210,14 +211,18 @@ void evp_pkey_ctx_free_old_ops(EVP_PKEY_CTX *ctx)
ctx->op.sig.algctx = NULL;
ctx->op.sig.signature = NULL;
} else if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)) {
- if (ctx->op.kex.algctx != NULL && ctx->op.kex.exchange != NULL)
+ if (ctx->op.kex.algctx != NULL && ctx->op.kex.exchange != NULL) {
+ OSSL_USDT_release_context(ctx->op.kex.algctx);
ctx->op.kex.exchange->freectx(ctx->op.kex.algctx);
+ }
EVP_KEYEXCH_free(ctx->op.kex.exchange);
ctx->op.kex.algctx = NULL;
ctx->op.kex.exchange = NULL;
} else if (EVP_PKEY_CTX_IS_KEM_OP(ctx)) {
- if (ctx->op.encap.algctx != NULL && ctx->op.encap.kem != NULL)
+ if (ctx->op.encap.algctx != NULL && ctx->op.encap.kem != NULL) {
+ OSSL_USDT_release_context(ctx->op.encap.algctx);
ctx->op.encap.kem->freectx(ctx->op.encap.algctx);
+ }
EVP_KEM_free(ctx->op.encap.kem);
ctx->op.encap.algctx = NULL;
ctx->op.encap.kem = NULL;
diff --git a/providers/implementations/exchange/ecx_exch.c b/providers/implementations/exchange/ecx_exch.c
index c97786a9dc..08f3e6655e 100644
--- a/providers/implementations/exchange/ecx_exch.c
+++ b/providers/implementations/exchange/ecx_exch.c
@@ -14,6 +14,7 @@
#include <openssl/err.h>
#include <openssl/proverr.h>
#include "internal/cryptlib.h"
+#include "internal/usdt.h"
#include "crypto/ecx.h"
#include "prov/implementations.h"
#include "prov/providercommon.h"
@@ -91,6 +92,8 @@ static int ecx_init(void *vecxctx, void *vkey, const char *algname)
ossl_ecx_key_free(ecxctx->key);
ecxctx->key = key;
+ OSSL_USDT_new_context_with_data(vecxctx, "pk::derive", { "pk::curve", OSSL_USDT_STRING(algname) });
+
#ifdef FIPS_MODULE
if (!ossl_FIPS_IND_callback(key->libctx, algname, "Init"))
return 0;
diff --git a/providers/implementations/kem/mlx_kem.c b/providers/implementations/kem/mlx_kem.c
index 61b061c46f..5ba5595e52 100644
--- a/providers/implementations/kem/mlx_kem.c
+++ b/providers/implementations/kem/mlx_kem.c
@@ -22,6 +22,7 @@
#include "prov/provider_ctx.h"
#include "prov/providercommon.h"
#include "providers/implementations/kem/mlx_kem.inc"
+#include "internal/usdt.h"
static OSSL_FUNC_kem_newctx_fn mlx_kem_newctx;
static OSSL_FUNC_kem_freectx_fn mlx_kem_freectx;
@@ -202,6 +203,7 @@ static int mlx_kem_encapsulate(void *vctx, unsigned char *ctext, size_t *clen,
cbuf = ctext + ml_kem_slot * key->xinfo->pubkey_bytes;
sbuf = shsec + ml_kem_slot * key->xinfo->shsec_bytes;
ctx = EVP_PKEY_CTX_new_from_pkey(key->libctx, key->mkey, key->propq);
+ OSSL_USDT_new_child(vctx, ctx);
if (ctx == NULL
|| EVP_PKEY_encapsulate_init(ctx, NULL) <= 0
|| EVP_PKEY_encapsulate(ctx, cbuf, &encap_clen, sbuf, &encap_slen) <= 0)
@@ -237,6 +239,7 @@ static int mlx_kem_encapsulate(void *vctx, unsigned char *ctext, size_t *clen,
cbuf = ctext + (1 - ml_kem_slot) * key->minfo->ctext_bytes;
encap_clen = key->xinfo->pubkey_bytes;
ctx = EVP_PKEY_CTX_new_from_pkey(key->libctx, key->xkey, key->propq);
+ OSSL_USDT_new_child(vctx, ctx);
if (ctx == NULL
|| EVP_PKEY_keygen_init(ctx) <= 0
|| EVP_PKEY_keygen(ctx, &xkey) <= 0
@@ -256,6 +259,7 @@ static int mlx_kem_encapsulate(void *vctx, unsigned char *ctext, size_t *clen,
encap_slen = key->xinfo->shsec_bytes;
sbuf = shsec + (1 - ml_kem_slot) * ML_KEM_SHARED_SECRET_BYTES;
ctx = EVP_PKEY_CTX_new_from_pkey(key->libctx, xkey, key->propq);
+ OSSL_USDT_new_child(vctx, ctx);
if (ctx == NULL
|| EVP_PKEY_derive_init(ctx) <= 0
|| EVP_PKEY_derive_set_peer(ctx, key->xkey) <= 0
@@ -327,6 +331,7 @@ static int mlx_kem_decapsulate(void *vctx, uint8_t *shsec, size_t *slen,
cbuf = ctext + ml_kem_slot * key->xinfo->pubkey_bytes;
sbuf = shsec + ml_kem_slot * key->xinfo->shsec_bytes;
ctx = EVP_PKEY_CTX_new_from_pkey(key->libctx, key->mkey, key->propq);
+ OSSL_USDT_new_child(vctx, ctx);
if (ctx == NULL
|| EVP_PKEY_decapsulate_init(ctx, NULL) <= 0
|| EVP_PKEY_decapsulate(ctx, sbuf, &decap_slen, cbuf, decap_clen) <= 0)
@@ -345,6 +350,7 @@ static int mlx_kem_decapsulate(void *vctx, uint8_t *shsec, size_t *slen,
cbuf = ctext + (1 - ml_kem_slot) * key->minfo->ctext_bytes;
sbuf = shsec + (1 - ml_kem_slot) * ML_KEM_SHARED_SECRET_BYTES;
ctx = EVP_PKEY_CTX_new_from_pkey(key->libctx, key->xkey, key->propq);
+ OSSL_USDT_new_child(vctx, ctx);
if (ctx == NULL
|| (xkey = EVP_PKEY_new()) == NULL
|| EVP_PKEY_copy_parameters(xkey, key->xkey) <= 0