SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
Post-quantum cryptography

SharkSSL supports post-quantum cryptography (PQC) for TLS key agreement and application signature verification. Use hybrid TLS 1.3 key exchange to combine classical elliptic-curve cryptography with ML-KEM, and use ML-DSA-65 verification to check signed application data such as firmware before accepting it.

ML-KEM is the key-encapsulation mechanism standardized in NIST FIPS 203. ML-DSA is the signature algorithm standardized in NIST FIPS 204. These algorithms address different tasks. A hybrid key exchange does not change the certificate-signature algorithm, and algorithm support is not a claim of FIPS module validation.

Choose the feature

Task SharkSSL support Starting point
Establish TLS traffic keys with classical and post-quantum contributions X25519MLKEM768, SecP256r1MLKEM768 and, with P-384 enabled, SecP384r1MLKEM1024 SharkSslCon_setPQCPolicy and SharkSslCon_setInitialHybridGroup
Use an ML-KEM-only TLS 1.3 key share Opt-in MLKEM768 and MLKEM1024 Named Groups SHARKSSL_ENABLE_MLKEM_STANDALONE and SharkSslCon_setInitialMLKEMGroup
Verify application signatures Pure ML-DSA-65 over the original message, with an optional context sharkssl_mldsa65_verify
Use the underlying SHA-3/SHAKE sponge Native byte-oriented Keccak API SHA-3 and SHAKE sponge

The standalone ML-KEM switch selects TLS Named Groups; it does not expose a separate public application KEM API. ML-DSA support here is verification only, not a signing API or an ML-DSA certificate-authentication mode for TLS.

Enable hybrid TLS

  1. Enable SHARKSSL_ENABLE_PQC=1 consistently for the library and its callers. Its default is 0. Keep TLS 1.3, ECC and at least X25519 or P-256 enabled. The header checks these dependencies.
  2. Include the native PQC implementation, src/SharkSslCryptoMLKEM.c, in the selected source build. Use the matching build's composition when linking an amalgamated library; do not compile its contents twice. A PSA consumer needs the corresponding ML-KEM capability from its selected provider.
  3. Initialize the RNG, install the local identity and CA trust, and configure peer verification as for any TLS connection. See Configure SharkSSL for Your Build and Certificate Management.
  4. Set the connection's key-exchange policy before starting its handshake. The peer must support an allowed group; a required hybrid exchange fails if no permitted group can be negotiated.

This helper requires a native client connection created by SharkSsl_createCon, with PQC, TLS 1.3 and X25519 enabled. Its required SharkSslCon* con must not have started a handshake. It returns U8: 1 when both settings are accepted, otherwise 0. If setup fails, stop before I/O.

#include <SharkSSL.h>
U8 configureHybridClient(SharkSslCon* con)
{
/* Offer this compiled hybrid group first, before requiring hybrid-only use. */
{
return 0;
}
/* Reject classical-only negotiation for this connection. */
}
TLS objects, certificate/session operations, and public-key interfaces.
#define SHARKSSL_PQC_REQUIRE_HYBRID
Permit only compiled hybrid classical/ML-KEM groups.
Definition: SharkSSL.h:1767
SHARKSSL_API U8 SharkSslCon_setInitialHybridGroup(SharkSslCon *o, U16 group)
Selects the first advertised hybrid group for this client connection.
SHARKSSL_API U8 SharkSslCon_setPQCPolicy(SharkSslCon *o, U8 policy)
Selects the TLS 1.3 key agreement policy for this client or server connection before the handshake st...
struct SharkSslCon SharkSslCon
SharkSslCon is an opaque handle returned by function SharkSsl_createCon.
Definition: SharkSSL.h:514
#define SHARKSSL_GROUP_X25519MLKEM768
X25519 with ML-KEM-768.
Definition: SharkSSL.h:242

SHARKSSL_PQC_ALLOW_X25519 permits compiled PQC groups and classical X25519 when available. SHARKSSL_PQC_REQUIRE_HYBRID accepts only compiled hybrid groups. SHARKSSL_PQC_REQUIRE_PQC also permits compiled ML-KEM-only groups, but no classical-only exchange. Enabling those groups additionally requires SHARKSSL_ENABLE_MLKEM_STANDALONE=1, whose default is 0.

Without an explicit policy call, the configured defaults apply. Clients prefer X25519MLKEM768 when compiled, otherwise SecP256r1MLKEM768. The API reference describes selection conflicts, resumption policy and the order of per-connection calls.

Plan handshake resources

Post-quantum key shares need more handshake storage and transmitted bytes than classical shares. Size buffers and stack for the selected groups, certificate chain and backend, using Configure SharkSSL for Your Build and the matching port guide.

SHARKSSL_PQC_DEFER_INITIAL_SHARE=1 defers the client's key-share generation until a HelloRetryRequest, saving the initial work at the cost of another round trip. It requires PQC and HelloRetryRequest support. The default 0 sends an initial hybrid share. Choose according to connection latency and memory needs.

Verify an ML-DSA signature

Enable SHARKSSL_USE_MLDSA=1 and include src/SharkSslCryptoMLDSA.c together with the Keccak implementation in src/SharkSslCryptoMLKEM.c. The default is 0. Call sharkssl_mldsa65_verify with the original message, a trusted raw 1952-byte public key, a 3309-byte signature and the signer's context, which may be empty and must not exceed 255 bytes. DER keys and a prehashed message are not accepted by this API.

Only a return value of 0 means valid. The function distinguishes invalid input/signatures from allocation failure and releases its temporary workspace. Verify before using the signed data, and provision the verifying key through your application's trust process. The complete parameter and ownership contract is in the function reference.

Accelerate PQC on your target

Native PQC supports optional assembly for Keccak and ML-KEM polynomial arithmetic. Select them independently with SHARKSSL_OPTIMIZED_KECCAK_ASM and SHARKSSL_OPTIMIZED_MLKEM_ASM, then add the matching port files. Available kernels cover Arm Cortex-M, AArch64, RISC-V, ESP32-S3 Xtensa, Renesas RX and MIPS; x64 supplies a Keccak kernel while polynomial arithmetic uses C. Exact operations and fallbacks depend on the processor and toolchain.

Start with Constant-time cryptography and assembly acceleration, then choose the source/option table in Ports. An optimization switch selects a backend; it does not enable the algorithm or supply missing assembly objects.