# CMakeLists.txt — ESP-IDF component for PQClean post-quantum algorithms.
#
# Compiles the three PQ algorithms (ML-DSA-65, SLH-DSA-128s, ML-KEM-768)
# from the shared resources/pqclean/ source tree, using the mbedtls
# crypto backend (crypto_backend_mbedtls.c) for SHA-2/SHA3/SHAKE.
#
# The source files are referenced via relative paths back to the shared
# resources/pqclean/ directory so there is a single source of truth.
#
# mbedtls requirements:
#   CONFIG_MBEDTLS_SHA3_C=y  (for SHA3-256, SHA3-512)
#   CONFIG_MBEDTLS_SHAKE_C=y (for SHAKE-128, SHAKE-256)
# Enable these in menuconfig under Component config -> mbedTLS ->
#   Hash functions -> SHA-3 and SHAKE.

set(PQCLEAN_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../../../resources/pqclean")

idf_component_register(
    SRCS
        "${PQCLEAN_ROOT}/crypto_sign/ml-dsa-65/sign.c"
        "${PQCLEAN_ROOT}/crypto_sign/ml-dsa-65/poly.c"
        "${PQCLEAN_ROOT}/crypto_sign/ml-dsa-65/ntt.c"
        "${PQCLEAN_ROOT}/crypto_sign/slh-dsa-128s/sign.c"
        "${PQCLEAN_ROOT}/crypto_sign/slh-dsa-128s/fors.c"
        "${PQCLEAN_ROOT}/crypto_sign/slh-dsa-128s/wots.c"
        "${PQCLEAN_ROOT}/crypto_sign/slh-dsa-128s/hash.c"
        "${PQCLEAN_ROOT}/crypto_sign/slh-dsa-128s/thash.c"
        "${PQCLEAN_ROOT}/crypto_sign/slh-dsa-128s/address.c"
        "${PQCLEAN_ROOT}/crypto_sign/slh-dsa-128s/utils.c"
        "${PQCLEAN_ROOT}/crypto_kem/ml-kem-768/kem.c"
        "${PQCLEAN_ROOT}/crypto_kem/ml-kem-768/indcpa.c"
        "${PQCLEAN_ROOT}/crypto_kem/ml-kem-768/poly.c"
        "${PQCLEAN_ROOT}/crypto_kem/ml-kem-768/ntt.c"
        "${PQCLEAN_ROOT}/crypto_kem/ml-kem-768/cbd.c"
        "${PQCLEAN_ROOT}/crypto_kem/ml-kem-768/reduce.c"
        "${PQCLEAN_ROOT}/crypto_kem/ml-kem-768/symmetric.c"
        "${PQCLEAN_ROOT}/crypto_kem/ml-kem-768/verify.c"
        "${PQCLEAN_ROOT}/common/fips202.c"
        "${PQCLEAN_ROOT}/common/sha2.c"
        "${PQCLEAN_ROOT}/common/crypto_backend_mbedtls.c"
        "randombytes_mbedtls.c"
        "pq_drbg_firmware.c"
    INCLUDE_DIRS
        "include"
        "${PQCLEAN_ROOT}/common"
        "${PQCLEAN_ROOT}/crypto_sign/ml-dsa-65"
        "${PQCLEAN_ROOT}/crypto_sign/slh-dsa-128s"
        "${PQCLEAN_ROOT}/crypto_kem/ml-kem-768"
    REQUIRES
        mbedtls
)

# Suppress warnings from the PQClean code (it uses C99 patterns that
# trigger -Wextra warnings under ESP-IDF's default flags).
target_compile_options(${COMPONENT_LIB} PRIVATE
    -Wno-unused-parameter
    -Wno-sign-compare
    -Wno-unused-variable
    -Wno-unused-but-set-variable
)
