/* 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. */
/* Edit scripts/gen_p11_thunks.py and rerun `make generate`.   */

#ifndef FHSM_PKCS11_MECHANISMS_H
#define FHSM_PKCS11_MECHANISMS_H

#include "fhsm_common.h"

#ifdef __cplusplus
extern "C" {
#endif

/* ---- CKM_* mechanism identifiers (PKCS#11 v3.2 §6.3) ---- */
/* --- AES --- */
#define CKM_AES_KEY_GEN                      0x00001080u
#define CKM_AES_CBC                          0x00001082u
#define CKM_AES_CBC_PAD                      0x00001085u
#define CKM_AES_GCM                          0x00001087u
#define CKM_AES_CCM                          0x00001088u
#define CKM_AES_CTR                          0x00001086u
#define CKM_AES_KEY_WRAP                     0x00002109u
#define CKM_AES_KEY_WRAP_KWP                 0x0000210Bu
#define CKM_AES_CMAC                         0x0000108Cu
#define CKM_AES_ECB                          0x00001081u

/* --- SHA2 --- */
#define CKM_SHA256                           0x00000250u
#define CKM_SHA384                           0x00000260u
#define CKM_SHA512                           0x00000270u
#define CKM_SHA224                           0x00000255u
#define CKM_SHA512_224                       0x00000048u
#define CKM_SHA512_256                       0x0000004Cu

/* --- SHA3 --- */
#define CKM_SHA3_256                         0x000002B0u
#define CKM_SHA3_384                         0x000002C0u
#define CKM_SHA3_512                         0x000002D0u
#define CKM_SHAKE128                         0x000002B8u
#define CKM_SHAKE256                         0x000002B9u

/* --- HMAC --- */
#define CKM_SHA256_HMAC                      0x00000251u
#define CKM_SHA384_HMAC                      0x00000261u
#define CKM_SHA512_HMAC                      0x00000271u
#define CKM_SHA3_256_HMAC                    0x000002B1u
#define CKM_SHA3_384_HMAC                    0x000002C1u
#define CKM_SHA3_512_HMAC                    0x000002D1u

/* --- RSA --- */
#define CKM_RSA_PKCS_KEY_PAIR_GEN            0x00000000u
#define CKM_RSA_PKCS_PSS                     0x0000000Du
#define CKM_SHA256_RSA_PKCS_PSS              0x00000043u
#define CKM_SHA384_RSA_PKCS_PSS              0x00000044u
#define CKM_SHA512_RSA_PKCS_PSS              0x00000045u
#define CKM_RSA_PKCS_OAEP                    0x00000009u
#define CKM_RSA_PKCS                         0x00000001u
#define CKM_RSA_X_509                        0x00000003u
#define CKM_SHA1_RSA_PKCS                    0x00000006u

/* --- EC --- */
#define CKM_EC_KEY_PAIR_GEN                  0x00001040u
#define CKM_ECDSA                            0x00001041u
#define CKM_ECDSA_SHA256                     0x00001044u
#define CKM_ECDSA_SHA384                     0x00001045u
#define CKM_ECDSA_SHA512                     0x00001046u
#define CKM_ECDH1_DERIVE                     0x00001050u
#define CKM_ECDH1_COFACTOR_DERIVE            0x00001051u

/* --- EdDSA --- */
#define CKM_EC_EDWARDS_KEY_PAIR_GEN          0x00001055u
#define CKM_EDDSA                            0x00001057u

/* --- ECM --- */
#define CKM_EC_MONTGOMERY_KEY_PAIR_GEN       0x00001056u
#define CKM_X25519_DERIVE                    0x00001052u
#define CKM_X448_DERIVE                      0x00001054u

/* --- ML-KEM --- */
#define CKM_ML_KEM_KEY_PAIR_GEN              0x00004021u
#define CKM_ML_KEM                           0x00004022u

/* --- ML-DSA --- */
#define CKM_ML_DSA_KEY_PAIR_GEN              0x00004023u
#define CKM_ML_DSA                           0x00004024u
#define CKM_HASH_ML_DSA_SHA256               0x00004027u
#define CKM_HASH_ML_DSA_SHA512               0x00004029u

/* --- SLH-DSA --- */
#define CKM_SLH_DSA_KEY_PAIR_GEN             0x00004025u
#define CKM_SLH_DSA                          0x00004026u

/* --- HKDF --- */
#define CKM_HKDF_DERIVE                      0x0000402Au
#define CKM_HKDF_DATA                        0x0000402Bu
#define CKM_HKDF_KEY_GEN                     0x0000402Cu

/* --- PBKDF2 --- */
#define CKM_PKCS5_PBKD2                      0x000003B0u

/* --- KDF --- */
#define CKM_NIST_PRF_KDF                     0x00000384u

/* --- GENERIC --- */
#define CKM_GENERIC_SECRET_KEY_GEN           0x00000350u

/* --- KDF-concat --- */
#define CKM_CONCATENATE_BASE_AND_KEY         0x00000360u
#define CKM_CONCATENATE_BASE_AND_DATA        0x00000362u
#define CKM_CONCATENATE_DATA_AND_BASE        0x00000363u
#define CKM_XOR_BASE_AND_DATA                0x00000364u

/* --- KMAC --- */
#define CKM_KMAC128                          0x00004080u
#define CKM_KMAC256                          0x00004081u

/* --- Hybrid-KEM --- */
#define CKM_HYBRID_X25519_ML_KEM_768         0x80004200u

/* --- Hybrid-Sig --- */
#define CKM_HYBRID_ED25519_ML_DSA_65         0x80004201u

/* --- MD5 --- */
#define CKM_MD5                              0x00000210u

/* --- SHA1 --- */
#define CKM_SHA_1                            0x00000220u

/* --- DES --- */
#define CKM_DES_KEY_GEN                      0x00000120u

/* --- TDES --- */
#define CKM_DES3_KEY_GEN                     0x00000130u
#define CKM_DES3_CBC                         0x00000133u

/* --- RC4 --- */
#define CKM_RC4                              0x00000111u

/* --- DH --- */
#define CKM_DH_PKCS_KEY_PAIR_GEN             0x00000020u

/* --- DSA --- */
#define CKM_DSA_KEY_PAIR_GEN                 0x00000010u

/* ---- Dispatch handler signature ---- */
/*
 * Every CKM_* points to a handler with this signature. Concrete
 * handlers live in src/fhsm_dispatch_*.c (or are stubs in src/gen/
 * fhsm_dispatch.c for unimplemented mechanisms).
 *
 *   session_handle  --- caller's PKCS#11 session
 *   key_handle      --- input key handle (0 if N/A for digest)
 *   params, plen    --- mechanism-specific parameters (e.g.
 *                       CK_GCM_PARAMS, CK_RSA_PKCS_OAEP_PARAMS)
 *   in, inlen       --- input data slice
 *   out, *outlen    --- output buffer (in/out length)
 */
typedef fhsm_rv_t (*fhsm_mech_handler_t)(
    unsigned long  session_handle,
    unsigned long  key_handle,
    const void    *params,
    size_t         plen,
    fhsm_slice_t   in,
    uint8_t       *out,
    size_t        *outlen);

/* Forward declarations of every handler symbol --- ordered by family. */
extern fhsm_rv_t dispatch_aes_keygen(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_aes_cbc(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_aes_cbc_pad(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_aes_gcm(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_aes_ccm(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_aes_ctr(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_aes_kw(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_aes_kwp(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_aes_cmac(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_sha256(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_sha384(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_sha512(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_sha224(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_sha512_224(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_sha512_256(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_sha3_256(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_sha3_384(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_sha3_512(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_shake128(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_shake256(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_hmac_sha256(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_hmac_sha384(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_hmac_sha512(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_hmac_sha3_256(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_hmac_sha3_384(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_hmac_sha3_512(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_rsa_keypair(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_rsa_pss(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_rsa_pss_sha256(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_rsa_pss_sha384(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_rsa_pss_sha512(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_rsa_oaep(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_ec_keypair(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_ecdsa(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_ecdsa_sha256(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_ecdsa_sha384(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_ecdsa_sha512(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_ecdh1(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_ecdh1_cofactor(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_eddsa_keypair(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_eddsa(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_ecm_keypair(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_x25519(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_x448(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_ml_kem_keypair(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_ml_kem_encap(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_ml_dsa_keypair(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_ml_dsa(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_hash_ml_dsa_sha256(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_hash_ml_dsa_sha512(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_slh_dsa_keypair(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_slh_dsa(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_hkdf(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_hkdf_data(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_hkdf_keygen(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_pbkdf2(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_nist_prf_kdf(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_generic_secret_keygen(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_concat_base_and_key(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_concat_base_and_data(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_concat_data_and_base(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_xor_base_and_data(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_kmac128(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_kmac256(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_hybrid_x25519_ml_kem_768(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);
extern fhsm_rv_t dispatch_hybrid_ed25519_ml_dsa_65(unsigned long, unsigned long, const void*, size_t, fhsm_slice_t, uint8_t*, size_t*);

/* ---- Dispatch table ---- */
typedef struct fhsm_mech_entry_s {
    uint32_t              ckm_value;
    const char           *name;
    const char           *family;
    const char           *operation;
    int                   fips_approved;   /* 0/1 */
    fhsm_mech_handler_t   handler;
} fhsm_mech_entry_t;

extern const fhsm_mech_entry_t fhsm_mechanism_table[];
extern const size_t            fhsm_mechanism_count;

/* Lookup --- O(log N), table is sorted by ckm_value. Returns NULL
 * if the mechanism is unknown. */
const fhsm_mech_entry_t *fhsm_mechanism_lookup(uint32_t ckm);

/* Standard reject handler --- returns FHSM_RV_FIPS_NOT_APPROVED.
 * Used as the handler for every non-approved CKM in the strict
 * profile build. */
fhsm_rv_t dispatch_reject_fips(unsigned long, unsigned long,
                                const void*, size_t, fhsm_slice_t,
                                uint8_t*, size_t*);

#ifdef __cplusplus
}
#endif

#endif /* FHSM_PKCS11_MECHANISMS_H */
