SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
SharkSSL RV32IM cryptography (GCC)

Use this backend to select BigInt and elliptic-curve assembly for a 32-bit RISC-V SharkSSL application. ESP32-P4 applications can also select the PIE BigInt extension.

Requirements

Use GCC for 32-bit RISC-V with the integer multiplication extension (RV32IM), 32-bit BigInt words and a matching target configuration. Instruction timing and multiplier behavior depend on the particular core.

Build integration

Keep SharkSslBigInt.c and, for elliptic curves, SharkSslECC.c. Add the selected files and apply the same feature definitions to C and preprocessed assembly:

Operation Files Integer switches set to 1
BigInt add/subtract/shift/multiply/Montgomery product SharkSslBigInt_RISCV.S SHARKSSL_OPTIMIZED_BIGINT_ASM
P-256 field arithmetic SharkSslP256_RISCV.S SHARKSSL_ECC_USE_SECP256R1, SHARKSSL_ECC_P256_ASM
Dedicated X25519 SharkSslX25519_RISCV.S, SharkSslX25519_RISCV.c SHARKSSL_ECC_USE_CURVE25519, SHARKSSL_X25519_DEDICATED, SHARKSSL_X25519_ASM

Assemble uppercase .S files through GCC with the application's target, ABI, include paths and configuration. Link only one full BigInt backend.

Configuration

Keep SHARKSSL_OPTIMIZED_BIGINT_WORD_ASM=0 when selecting the full backend. Enable curve and algorithm options as needed; set an unwanted assembly selector to 0 to retain the corresponding C implementation.

P-256 and X25519

P-256 assembly replaces multiplication, addition and subtraction modulo the field prime. Scalar-order arithmetic remains in C. X25519 uses assembly field routines with a C ladder and inversion. Its assembly selection need not improve performance on every core; choose it for the application's target and workload.

The ESP32-P4 extension keeps SharkSslBigInt_RISCV.S in the build for its fallback operations.

Behavior and limitations

Timing and fallback

BigInt branch conditions and addresses depend on public operand lengths and alias relationships. A fixed instruction sequence does not establish fixed timing on every RV32 multiplier. Keep SHARKSSL_BIGINT_TIMING_RESISTANT enabled for private-key operations; the generic SharkSslBigInt_expmod routine is not a constant-time private-key interface.

ChaCha20, Poly1305, SHA-2 and P-384 use the portable C paths.

AES-GCM and the AES block API use the bitsliced C AES in SharkSslAesGcmCT.h. Keep SHARKSSL_OPTIMIZED_AES_ASM, SHARKSSL_OPTIMIZED_GCM_ASM and SHARKSSL_OPTIMIZED_GHASH_ASM at 0: the generic crypto implementation rejects these options on this target.

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.