|
SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
|
Use this backend to select ESP32-S3 hardware hashing and AES, plus Xtensa assembly for post-quantum cryptography (PQC). Your application keeps the normal SharkSSL APIs; each option selects the implementation behind them.
CONFIG_MBEDTLS_HARDWARE_SHA=y for hashing and CONFIG_MBEDTLS_HARDWARE_AES=y for AES.CONFIG_APP_BUILD_TYPE_PURE_RAM_APP: the adapter requires DMA allocations.Keep the normal SharkSSL C sources. Add the files for the options you need and apply the same feature definitions to all SharkSSL translation units. Compile uppercase .S files through the compiler driver so they are preprocessed. Paths in the table are relative to this directory.
| Operation | Additional file | Switch set to 1 |
|---|---|---|
| SHA-1 | SharkSslSha1_ESP32S3.c | SHARKSSL_ESP32S3_HW_SHA1 |
| SHA-256 | SharkSslSha256_ESP32S3.c | SHARKSSL_ESP32S3_HW_SHA256 |
| SHA-384 | SharkSslSha384_ESP32S3.c | SHARKSSL_ESP32S3_HW_SHA384 |
| SHA-512 | SharkSslSha512_ESP32S3.c | SHARKSSL_ESP32S3_HW_SHA512 |
| AES-CBC | SharkSslAes_ESP32S3.c | SHARKSSL_ESP32S3_HW_AES_CBC |
| AES block encryption/decryption | SharkSslAes_ESP32S3.c | SHARKSSL_ESP32S3_HW_AES_ECB |
| AES-GCM | SharkSslAes_ESP32S3.c | SHARKSSL_ESP32S3_HW_GCM |
| SHA-3/SHAKE | SharkSslKeccak_ESP32S3.S | SHARKSSL_OPTIMIZED_KECCAK_ASM |
| ML-KEM polynomial multiplication and accumulation | SharkSslMLKEM_ESP32S3.S | SHARKSSL_OPTIMIZED_MLKEM_ASM |
Compile SharkSslAes_ESP32S3.c once, even when selecting several AES options. The headers in this directory declare internal adapter hooks; application code should continue using the public SharkSSL interfaces.
Each option above accepts 0 or 1 and defaults to 0. Enable the required algorithm as well as its hardware or assembly selector. For example, SHA-512 needs SHARKSSL_USE_SHA_512=1. SHA-1 requires SHARKSSL_USE_SHA1=1 and remains disabled by default; enable it only for an application or compatibility requirement that needs it.
The SHA adapters preserve the native context layout, partial updates, context copying, padding and HMAC behavior. Complete blocks in one update share a peripheral lock and state transfer. Unaligned input is copied to aligned temporary storage, which is cleared before return.
Keep SHARKSSL_OPTIMIZED_SHA256_ASM=0 when selecting the SHA-256 peripheral. For the SHA-384 or SHA-512 peripheral, keep SHARKSSL_OPTIMIZED_SHA384_ASM=0. Each hash has its own peripheral selector.
The CBC adapter uses hardware for AES-128/256 calls of at least 256 bytes when input and output are separate, nonoverlapping, word-aligned, DMA-capable buffers. Smaller, unaligned, in-place and AES-192 calls use the software CBC loop. On a driver error, the adapter recomputes from the unchanged input and IV in software.
The independent ECB selector enables hardware for single-block AES-128/256 encryption and decryption. It copies each block to aligned temporary storage and clears that storage after use. AES-192 retains the software path. Enabling ECB also affects software CBC fallback calls that invoke the public block operation.
The adapter retains the raw AES key beside the software schedule and clears it in SharkSslAesCtx_destructor.
The GCM selector is independent of the CBC and ECB options. For AES-128/256 messages of at least 256 bytes, it uses the DMA peripheral for AES-CTR while retaining SharkSSL's fixed-access software GHASH.
Separate, nonoverlapping, word-aligned DMA buffers can be used directly. In-place, unaligned or non-DMA buffers require two temporary DMA buffers, each as large as the message. The adapter copies the result back after the driver call succeeds. Allocation or driver failure falls back to software using the unchanged input. Smaller messages and AES-192 use the native software path. The GCM destructor clears the retained raw key.
Set SHARKSSL_ENABLE_PQC=1, then select Keccak and ML-KEM assembly independently with the options in the table. Keccak uses Xtensa LX7 integer instructions for SHA-3/SHAKE. ML-KEM uses assembly for polynomial multiplication and accumulation; the forward and inverse number-theoretic transforms remain in C. Keep the shared assembly include files in their supplied relative locations.
The hardware selectors cover SHA-1, SHA-256, SHA-384, SHA-512 and AES-128/256 CBC, ECB and GCM. AES-192 uses software. Native CTR and CCM retain their native implementations; the ESP-IDF CTR driver uses a different counter byte order from SharkSSL's native CTR API.
This port supplies no MPI, ECC or ChaCha20/Poly1305 peripheral adapter. The eFuse-key HMAC and digital-signature peripherals do not replace SharkSSL's arbitrary-key HMAC or RSA APIs.
The native random generator remains SHA-256 Hash_DRBG. Supply hardware entropy through sharkssl_entropyEx and follow the random-generator configuration for initialization and seed requirements. PSA consumers use their provider's random generator.
The AES block API, CBC, CTR and CCM use SharkSslAesCtx. These application APIs do not add TLS cipher suites. SharkSSL TLS uses AES-GCM or ChaCha20-Poly1305 for record protection.