SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
SharkSSL ESP32-P4 PIE cryptography (GCC)

Use this extension to offload BigInt multiplication and Montgomery products to the ESP32-P4 Parallel Instruction Extension (PIE) vector unit. It supplements the RV32IM backend.

Requirements

  • ESP32-P4 with the xespv2p1 instruction extension and a matching GCC toolchain. The integration scope is chip revision v1.3; compatibility with later revisions must be established before deployment.
  • An ESP-IDF task context. PIE use in an interrupt service routine is unsupported. A different runtime must enable PIE and preserve its state on task switches.
  • Stack space for operand-dependent temporary storage. The Montgomery path requires up to 1248 additional bytes at 64 words.

Build integration

Keep the normal SharkSSL C sources and compile both SharkSslBigInt_P4.c and ../RISCV_GCC/SharkSslBigInt_RISCV.S. Apply these definitions to C and assembly:

/* Select PIE for eligible products and retain RV32IM fallback. */
#define SHARKSSL_OPTIMIZED_BIGINT_ASM 1
#define SHARKSSL_BIGINT_P4_PIE 1

Compile the .S file through GCC with the application's configuration and include paths. Link both objects; the P4 file calls the renamed RV32IM functions for operations outside its supported sizes.

Configuration

Keep SHARKSSL_OPTIMIZED_BIGINT_WORD_ASM=0. The PIE selectors do not enable curve assembly. Use the RISC-V curve options for P-256 or X25519. Keep the target and ABI options consistent across C and assembly.

Behavior and limitations

Operand limits

The backend uses RV32IM for multiplication below 16 words, squaring below 32 words, operands above 64 words, and operands longer than the modulus in Montgomery products. Consequently, the PIE path does not accelerate every key size or elliptic-curve operation.

Temporary buffers, vector registers and the extended accumulator are cleared before returning. The remaining alignment state depends on public lengths. See the RISC-V timing considerations.

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. This backend does not use the ESP32-P4 AES peripheral.

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.