/* Copyright 2026 Afchine Madjlessi <afchine.mad@gmail.com> */
/* SPDX-License-Identifier: Apache-2.0                       */
/* AUTO-GENERATED by scripts/gen_p11_thunks.py --- DO NOT EDIT. */
/* Profile : fips-strict */

#include "fhsm_pkcs11_mechanisms.h"
#include "fhsm_audit.h"
#include "fhsm_mode.h"

#include <stddef.h>

/* Forward decl : legacy dispatcher (weak symbol). */
__attribute__((weak)) fhsm_rv_t fhsm_legacy_dispatch(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen);

/* Default reject handler --- runtime mode-sensitive.
 *  - FIPS strict : FHSM_RV_FIPS_NOT_APPROVED
 *  - Legacy mode : delegate to fhsm_legacy_dispatch if present. */
fhsm_rv_t dispatch_reject_fips(unsigned long session, unsigned long key,
                                const void *params, size_t plen,
                                fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    if (fhsm_mode_is_fips()) {
        (void)session; (void)key; (void)params; (void)plen;
        (void)in; (void)out; (void)outlen;
        return FHSM_RV_FIPS_NOT_APPROVED;
    }
    if (fhsm_legacy_dispatch != NULL) {
        return fhsm_legacy_dispatch(session, key, params, plen,
                                      in, out, outlen);
    }
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FIPS_NOT_APPROVED;
}

/* ---- Weak stubs for every approved handler -----------------
 *
 * Each handler below is declared __attribute__((weak)) so the
 * concrete implementation (e.g. src/dispatch/fhsm_dispatch_aes.c)
 * can override it at link time. While that file is missing, the
 * stub returns FHSM_RV_FUNCTION_FAILED so the linker still
 * resolves the dispatch table. This lets the project build and
 * the smoke tests run before every mechanism has its production
 * implementation in place.                                       */

__attribute__((weak)) fhsm_rv_t dispatch_aes_cbc(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_aes_cbc_pad(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_aes_ccm(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_aes_cmac(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_aes_ctr(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_aes_gcm(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_aes_keygen(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_aes_kw(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_aes_kwp(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_concat_base_and_data(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_concat_base_and_key(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_concat_data_and_base(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_ec_keypair(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_ecdh1(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_ecdh1_cofactor(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_ecdsa(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_ecdsa_sha256(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_ecdsa_sha384(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_ecdsa_sha512(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_ecm_keypair(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_eddsa(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_eddsa_keypair(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_generic_secret_keygen(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_hash_ml_dsa_sha256(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_hash_ml_dsa_sha512(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_hkdf(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_hkdf_data(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_hkdf_keygen(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_hmac_sha256(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_hmac_sha384(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_hmac_sha3_256(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_hmac_sha3_384(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_hmac_sha3_512(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_hmac_sha512(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_hybrid_ed25519_ml_dsa_65(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_hybrid_x25519_ml_kem_768(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_kmac128(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_kmac256(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_ml_dsa(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_ml_dsa_keypair(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_ml_kem_encap(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_ml_kem_keypair(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_nist_prf_kdf(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_pbkdf2(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_rsa_keypair(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_rsa_oaep(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_rsa_pss(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_rsa_pss_sha256(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_rsa_pss_sha384(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_rsa_pss_sha512(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_sha224(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_sha256(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_sha384(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_sha3_256(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_sha3_384(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_sha3_512(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_sha512(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_sha512_224(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_sha512_256(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_shake128(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_shake256(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_slh_dsa(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_slh_dsa_keypair(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_x25519(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_x448(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

__attribute__((weak)) fhsm_rv_t dispatch_xor_base_and_data(
    unsigned long session, unsigned long key,
    const void *params, size_t plen,
    fhsm_slice_t in, uint8_t *out, size_t *outlen)
{
    (void)session; (void)key; (void)params; (void)plen;
    (void)in; (void)out; (void)outlen;
    return FHSM_RV_FUNCTION_FAILED;
}

const fhsm_mech_entry_t fhsm_mechanism_table[] = {
    { 0x00000000u, "CKM_RSA_PKCS_KEY_PAIR_GEN", "RSA", "keypair", 1, dispatch_rsa_keypair },
    { 0x00000001u, "CKM_RSA_PKCS", "RSA", "encrypt", 0, dispatch_reject_fips },
    { 0x00000003u, "CKM_RSA_X_509", "RSA", "encrypt", 0, dispatch_reject_fips },
    { 0x00000006u, "CKM_SHA1_RSA_PKCS", "RSA", "sign", 0, dispatch_reject_fips },
    { 0x00000009u, "CKM_RSA_PKCS_OAEP", "RSA", "encrypt", 1, dispatch_rsa_oaep },
    { 0x0000000Du, "CKM_RSA_PKCS_PSS", "RSA", "sign", 1, dispatch_rsa_pss },
    { 0x00000010u, "CKM_DSA_KEY_PAIR_GEN", "DSA", "keypair", 0, dispatch_reject_fips },
    { 0x00000020u, "CKM_DH_PKCS_KEY_PAIR_GEN", "DH", "keypair", 0, dispatch_reject_fips },
    { 0x00000043u, "CKM_SHA256_RSA_PKCS_PSS", "RSA", "sign", 1, dispatch_rsa_pss_sha256 },
    { 0x00000044u, "CKM_SHA384_RSA_PKCS_PSS", "RSA", "sign", 1, dispatch_rsa_pss_sha384 },
    { 0x00000045u, "CKM_SHA512_RSA_PKCS_PSS", "RSA", "sign", 1, dispatch_rsa_pss_sha512 },
    { 0x00000048u, "CKM_SHA512_224", "SHA2", "digest", 1, dispatch_sha512_224 },
    { 0x0000004Cu, "CKM_SHA512_256", "SHA2", "digest", 1, dispatch_sha512_256 },
    { 0x00000111u, "CKM_RC4", "RC4", "encrypt", 0, dispatch_reject_fips },
    { 0x00000120u, "CKM_DES_KEY_GEN", "DES", "keygen", 0, dispatch_reject_fips },
    { 0x00000130u, "CKM_DES3_KEY_GEN", "TDES", "keygen", 0, dispatch_reject_fips },
    { 0x00000133u, "CKM_DES3_CBC", "TDES", "encrypt", 0, dispatch_reject_fips },
    { 0x00000210u, "CKM_MD5", "MD5", "digest", 0, dispatch_reject_fips },
    { 0x00000220u, "CKM_SHA_1", "SHA1", "digest", 0, dispatch_reject_fips },
    { 0x00000250u, "CKM_SHA256", "SHA2", "digest", 1, dispatch_sha256 },
    { 0x00000251u, "CKM_SHA256_HMAC", "HMAC", "sign", 1, dispatch_hmac_sha256 },
    { 0x00000255u, "CKM_SHA224", "SHA2", "digest", 1, dispatch_sha224 },
    { 0x00000260u, "CKM_SHA384", "SHA2", "digest", 1, dispatch_sha384 },
    { 0x00000261u, "CKM_SHA384_HMAC", "HMAC", "sign", 1, dispatch_hmac_sha384 },
    { 0x00000270u, "CKM_SHA512", "SHA2", "digest", 1, dispatch_sha512 },
    { 0x00000271u, "CKM_SHA512_HMAC", "HMAC", "sign", 1, dispatch_hmac_sha512 },
    { 0x000002B0u, "CKM_SHA3_256", "SHA3", "digest", 1, dispatch_sha3_256 },
    { 0x000002B1u, "CKM_SHA3_256_HMAC", "HMAC", "sign", 1, dispatch_hmac_sha3_256 },
    { 0x000002B8u, "CKM_SHAKE128", "SHA3", "digest", 1, dispatch_shake128 },
    { 0x000002B9u, "CKM_SHAKE256", "SHA3", "digest", 1, dispatch_shake256 },
    { 0x000002C0u, "CKM_SHA3_384", "SHA3", "digest", 1, dispatch_sha3_384 },
    { 0x000002C1u, "CKM_SHA3_384_HMAC", "HMAC", "sign", 1, dispatch_hmac_sha3_384 },
    { 0x000002D0u, "CKM_SHA3_512", "SHA3", "digest", 1, dispatch_sha3_512 },
    { 0x000002D1u, "CKM_SHA3_512_HMAC", "HMAC", "sign", 1, dispatch_hmac_sha3_512 },
    { 0x00000350u, "CKM_GENERIC_SECRET_KEY_GEN", "GENERIC", "keygen", 1, dispatch_generic_secret_keygen },
    { 0x00000360u, "CKM_CONCATENATE_BASE_AND_KEY", "KDF-concat", "derive", 1, dispatch_concat_base_and_key },
    { 0x00000362u, "CKM_CONCATENATE_BASE_AND_DATA", "KDF-concat", "derive", 1, dispatch_concat_base_and_data },
    { 0x00000363u, "CKM_CONCATENATE_DATA_AND_BASE", "KDF-concat", "derive", 1, dispatch_concat_data_and_base },
    { 0x00000364u, "CKM_XOR_BASE_AND_DATA", "KDF-concat", "derive", 1, dispatch_xor_base_and_data },
    { 0x00000384u, "CKM_NIST_PRF_KDF", "KDF", "derive", 1, dispatch_nist_prf_kdf },
    { 0x000003B0u, "CKM_PKCS5_PBKD2", "PBKDF2", "derive", 1, dispatch_pbkdf2 },
    { 0x00001040u, "CKM_EC_KEY_PAIR_GEN", "EC", "keypair", 1, dispatch_ec_keypair },
    { 0x00001041u, "CKM_ECDSA", "EC", "sign", 1, dispatch_ecdsa },
    { 0x00001044u, "CKM_ECDSA_SHA256", "EC", "sign", 1, dispatch_ecdsa_sha256 },
    { 0x00001045u, "CKM_ECDSA_SHA384", "EC", "sign", 1, dispatch_ecdsa_sha384 },
    { 0x00001046u, "CKM_ECDSA_SHA512", "EC", "sign", 1, dispatch_ecdsa_sha512 },
    { 0x00001050u, "CKM_ECDH1_DERIVE", "EC", "derive", 1, dispatch_ecdh1 },
    { 0x00001051u, "CKM_ECDH1_COFACTOR_DERIVE", "EC", "derive", 1, dispatch_ecdh1_cofactor },
    { 0x00001052u, "CKM_X25519_DERIVE", "ECM", "derive", 1, dispatch_x25519 },
    { 0x00001054u, "CKM_X448_DERIVE", "ECM", "derive", 1, dispatch_x448 },
    { 0x00001055u, "CKM_EC_EDWARDS_KEY_PAIR_GEN", "EdDSA", "keypair", 1, dispatch_eddsa_keypair },
    { 0x00001056u, "CKM_EC_MONTGOMERY_KEY_PAIR_GEN", "ECM", "keypair", 1, dispatch_ecm_keypair },
    { 0x00001057u, "CKM_EDDSA", "EdDSA", "sign", 1, dispatch_eddsa },
    { 0x00001080u, "CKM_AES_KEY_GEN", "AES", "keygen", 1, dispatch_aes_keygen },
    { 0x00001081u, "CKM_AES_ECB", "AES", "encrypt", 0, dispatch_reject_fips },
    { 0x00001082u, "CKM_AES_CBC", "AES", "encrypt", 1, dispatch_aes_cbc },
    { 0x00001085u, "CKM_AES_CBC_PAD", "AES", "encrypt", 1, dispatch_aes_cbc_pad },
    { 0x00001086u, "CKM_AES_CTR", "AES", "encrypt", 1, dispatch_aes_ctr },
    { 0x00001087u, "CKM_AES_GCM", "AES", "encrypt", 1, dispatch_aes_gcm },
    { 0x00001088u, "CKM_AES_CCM", "AES", "encrypt", 1, dispatch_aes_ccm },
    { 0x0000108Cu, "CKM_AES_CMAC", "AES", "sign", 1, dispatch_aes_cmac },
    { 0x00002109u, "CKM_AES_KEY_WRAP", "AES", "wrap", 1, dispatch_aes_kw },
    { 0x0000210Bu, "CKM_AES_KEY_WRAP_KWP", "AES", "wrap", 1, dispatch_aes_kwp },
    { 0x00004021u, "CKM_ML_KEM_KEY_PAIR_GEN", "ML-KEM", "keypair", 1, dispatch_ml_kem_keypair },
    { 0x00004022u, "CKM_ML_KEM", "ML-KEM", "encap", 1, dispatch_ml_kem_encap },
    { 0x00004023u, "CKM_ML_DSA_KEY_PAIR_GEN", "ML-DSA", "keypair", 1, dispatch_ml_dsa_keypair },
    { 0x00004024u, "CKM_ML_DSA", "ML-DSA", "sign", 1, dispatch_ml_dsa },
    { 0x00004025u, "CKM_SLH_DSA_KEY_PAIR_GEN", "SLH-DSA", "keypair", 1, dispatch_slh_dsa_keypair },
    { 0x00004026u, "CKM_SLH_DSA", "SLH-DSA", "sign", 1, dispatch_slh_dsa },
    { 0x00004027u, "CKM_HASH_ML_DSA_SHA256", "ML-DSA", "sign", 1, dispatch_hash_ml_dsa_sha256 },
    { 0x00004029u, "CKM_HASH_ML_DSA_SHA512", "ML-DSA", "sign", 1, dispatch_hash_ml_dsa_sha512 },
    { 0x0000402Au, "CKM_HKDF_DERIVE", "HKDF", "derive", 1, dispatch_hkdf },
    { 0x0000402Bu, "CKM_HKDF_DATA", "HKDF", "derive", 1, dispatch_hkdf_data },
    { 0x0000402Cu, "CKM_HKDF_KEY_GEN", "HKDF", "keygen", 1, dispatch_hkdf_keygen },
    { 0x00004080u, "CKM_KMAC128", "KMAC", "sign", 1, dispatch_kmac128 },
    { 0x00004081u, "CKM_KMAC256", "KMAC", "sign", 1, dispatch_kmac256 },
    { 0x80004200u, "CKM_HYBRID_X25519_ML_KEM_768", "Hybrid-KEM", "encap", 1, dispatch_hybrid_x25519_ml_kem_768 },
    { 0x80004201u, "CKM_HYBRID_ED25519_ML_DSA_65", "Hybrid-Sig", "sign", 1, dispatch_hybrid_ed25519_ml_dsa_65 },
};

const size_t fhsm_mechanism_count =
    sizeof(fhsm_mechanism_table) / sizeof(fhsm_mechanism_table[0]);

/* Binary search over the (already-sorted) table. */
const fhsm_mech_entry_t *fhsm_mechanism_lookup(uint32_t ckm)
{
    size_t lo = 0, hi = fhsm_mechanism_count;
    while (lo < hi) {
        size_t mid = (lo + hi) / 2;
        uint32_t v = fhsm_mechanism_table[mid].ckm_value;
        if      (v == ckm) return &fhsm_mechanism_table[mid];
        else if (v <  ckm) lo = mid + 1;
        else               hi = mid;
    }
    return NULL;
}
