ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_rsip_rsa.c File Reference

RSIP-E50D RSA sign / verify / encrypt / decrypt path. More...

#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_log.h"
#include "ra8_rsip.h"
#include "ra8_rsip_asym_internal.h"
#include "ra8_rsip_internal.h"
#include "ra8_rsip_regs.h"
Include dependency graph for ra8_rsip_rsa.c:

Go to the source code of this file.

Functions

ra8_err_t ra8_rsip_rsa_sign (const ra8_rsip_key_handle_t *key, ra8_rsip_rsa_size_t size, const uint8_t *digest, uint32_t digest_len, uint8_t *signature)
 RSA sign a digest with a wrapped private key.
ra8_err_t ra8_rsip_rsa_verify (const ra8_rsip_key_handle_t *key, ra8_rsip_rsa_size_t size, const uint8_t *digest, uint32_t digest_len, const uint8_t *signature)
 RSA verify a signature against a digest using a wrapped pubkey.
ra8_err_t ra8_rsip_rsa_encrypt (const ra8_rsip_key_handle_t *key, ra8_rsip_rsa_size_t size, ra8_rsip_rsa_pad_t pad, const uint8_t *plaintext, uint32_t plaintext_len, uint8_t *ciphertext)
 RSA public-key encrypt a short message (RSAES-OAEP / PKCS1).
ra8_err_t ra8_rsip_rsa_decrypt (const ra8_rsip_key_handle_t *key, ra8_rsip_rsa_size_t size, ra8_rsip_rsa_pad_t pad, const uint8_t *ciphertext, uint8_t *plaintext, uint32_t plaintext_cap, uint32_t *recovered_len)
 RSA private-key decrypt a ciphertext (RSAES-OAEP / PKCS1).

Variables

static const char * s_tag = "RSIP"
 Logger tag used by every ra8_log_* call in this TU.

Detailed Description

RSIP-E50D RSA sign / verify / encrypt / decrypt path.

Tag
[Ring 3 / HAL] {World: S}

RSA slice of the RA8D2 RSIP-E50D asymmetric HAL driver, split out of ra8_rsip_asym.c to keep every translation unit under the file-size budget. Exposes:

  • RSASSA sign / verify over a pre-computed digest;
  • RSAES encrypt / decrypt with OAEP / PKCS1 padding.

All four entry points are FAIL-CLOSED in production: HUM Ch 52 documents no asymmetric command-register map for the RSIP-E50D, so the off-target-only command path is gated behind the stub-crypto guard and a production build returns k_ra8_err_not_supported (issues #214 + #187).

The byte-lane streaming primitives internal_asym_push / internal_asym_pull are defined in ra8_rsip_asym.c and shared with the ECDSA / ECDH / EdDSA code there; their declarations live in ra8_rsip_asym_internal.h. The remaining cross-TU primitives (priv_load_handle, priv_complete) are declared in ra8_rsip_internal.h. The RSIP engine exposes no documented asymmetric register interface (HUM Ch 52 is a feature overview, p 3302-3307), so the fake command path here is a modelled fiction, not a real hardware sequence.

Since
0.1.0

Definition in file ra8_rsip_rsa.c.

Function Documentation

◆ ra8_rsip_rsa_decrypt()

ra8_err_t ra8_rsip_rsa_decrypt ( const ra8_rsip_key_handle_t * key,
ra8_rsip_rsa_size_t size,
ra8_rsip_rsa_pad_t pad,
const uint8_t * ciphertext,
uint8_t * plaintext,
uint32_t plaintext_cap,
uint32_t * recovered_len )
nodiscard

RSA private-key decrypt a ciphertext (RSAES-OAEP / PKCS1).

Drives the RSIP asymmetric engine's private-decrypt opcode (k_ra8_rsip_asym_op_rsa_decrypt): the modulus-width ciphertext is raised to the private exponent and the pad padding is removed inside the secure boundary, leaving the recovered message. The recovered length (shorter than the modulus for OAEP / PKCS1) is reported through recovered_len.

Parameters
[in]keyWrapped RSA private-key handle.
[in]sizeRSA modulus selector (1024 / 2048 / 3072 / 4096).
[in]padPadding scheme (OAEP or PKCS1).
[in]ciphertextCiphertext to decrypt (modulus / 8 bytes); never NULL.
[out]plaintextRecovered-message buffer; never NULL.
[in]plaintext_capCapacity of plaintext in bytes.
[out]recovered_lenReceives the recovered-message length; never NULL.
Returns
ra8_err_t error code.
Return values
k_ra8_okMessage recovered.
k_ra8_err_not_supportedProduction build fail-closed; no RSIP backend, use tf-psa-crypto.
k_ra8_err_null_ptrAny pointer was NULL.
k_ra8_err_invalid_argBad size / pad, or recovered message exceeds plaintext_cap.
k_ra8_err_hw_timeoutEngine never signalled DONE.
k_ra8_err_hw_errorPadding check failed (corrupt ciphertext).
Precondition
key->alg is an RSA private install opcode.
ciphertext, plaintext and recovered_len are non-NULL.
Postcondition
On success, plaintext[0..*recovered_len-1] is the message.
On success, *recovered_len <= plaintext_cap.
Note
Thread safety: not thread-safe.
Fail-closed in production (HUM Ch 52 documents no RSIP backend); the fake/stub command path never ships. Real crypto: tf-psa-crypto (issues #214 / #187 / #181).
See also
ra8_rsip_rsa_encrypt
Since
0.1.0

Definition at line 408 of file ra8_rsip_rsa.c.

References k_ra8_err_not_supported, RA8_CHECK_NULL_PTR, and s_tag.

◆ ra8_rsip_rsa_encrypt()

ra8_err_t ra8_rsip_rsa_encrypt ( const ra8_rsip_key_handle_t * key,
ra8_rsip_rsa_size_t size,
ra8_rsip_rsa_pad_t pad,
const uint8_t * plaintext,
uint32_t plaintext_len,
uint8_t * ciphertext )
nodiscard

RSA public-key encrypt a short message (RSAES-OAEP / PKCS1).

Drives the RSIP asymmetric engine's public-encrypt opcode (k_ra8_rsip_asym_op_rsa_encrypt) so RSA-OAEP key transport works: the plaintext (typically a wrapped content-encryption key) is padded per pad and raised to the public exponent, yielding a modulus-width ciphertext. The engine performs the padding inside the secure boundary; the caller supplies only the raw message bytes.

Parameters
[in]keyWrapped RSA public-key handle.
[in]sizeRSA modulus selector (1024 / 2048 / 3072 / 4096).
[in]padPadding scheme (OAEP or PKCS1).
[in]plaintextMessage to encrypt; never NULL.
[in]plaintext_lenMessage length in bytes; 1 .. modulus / 8.
[out]ciphertextOutput ciphertext (modulus / 8 bytes); never NULL.
Returns
ra8_err_t error code.
Return values
k_ra8_okCiphertext produced.
k_ra8_err_not_supportedProduction build fail-closed; no RSIP backend, use tf-psa-crypto.
k_ra8_err_null_ptrAny pointer was NULL.
k_ra8_err_invalid_argBad size / pad, or plaintext_len out of range.
k_ra8_err_hw_timeoutEngine never signalled DONE.
k_ra8_err_hw_errorMessage too long for the padding scheme.
Precondition
key->alg is an RSA install opcode.
plaintext and ciphertext are non-NULL.
Postcondition
On success, ciphertext[0..modulus_bytes-1] is the RSAES blob.
No engine key state persists beyond the call.
Note
Thread safety: not thread-safe.
Fail-closed in production (HUM Ch 52 documents no RSIP backend); the fake/stub command path never ships. Real crypto: tf-psa-crypto (issues #214 / #187 / #181).
See also
ra8_rsip_rsa_decrypt
Since
0.1.0

Definition at line 392 of file ra8_rsip_rsa.c.

References k_ra8_err_not_supported, RA8_CHECK_NULL_PTR, and s_tag.

◆ ra8_rsip_rsa_sign()

ra8_err_t ra8_rsip_rsa_sign ( const ra8_rsip_key_handle_t * key,
ra8_rsip_rsa_size_t size,
const uint8_t * digest,
uint32_t digest_len,
uint8_t * signature )
nodiscard

RSA sign a digest with a wrapped private key.

Parameters
[in]keyWrapped RSA private-key handle.
[in]sizeRSA modulus selector (1024 / 2048 / 3072 / 4096).
[in]digestPre-computed message digest.
[in]digest_lenDigest length in bytes.
[out]signatureOutput signature (modulus / 8 bytes).
Returns
ra8_err_t error code.
Return values
k_ra8_okSignature produced.
k_ra8_err_not_supportedProduction build fail-closed; no RSIP backend, use tf-psa-crypto.
k_ra8_err_null_ptrAny pointer was NULL.
k_ra8_err_invalid_argBad size.
k_ra8_err_hw_timeoutEngine never signalled DONE.
Precondition
key->alg is an RSA install opcode.
digest and signature are non-NULL.
Postcondition
On success, signature[0..modulus_bytes-1] is the RSA sig.
Note
Thread safety: not thread-safe.
Fail-closed in production (HUM Ch 52 documents no RSIP backend); the fake/stub command path never ships. Real crypto: tf-psa-crypto (issues #214 / #187 / #181).
Since
0.1.0

Definition at line 364 of file ra8_rsip_rsa.c.

References k_ra8_err_not_supported, RA8_CHECK_NULL_PTR, and s_tag.

Referenced by ra8_rsip_protected_rsa_decrypt().

◆ ra8_rsip_rsa_verify()

ra8_err_t ra8_rsip_rsa_verify ( const ra8_rsip_key_handle_t * key,
ra8_rsip_rsa_size_t size,
const uint8_t * digest,
uint32_t digest_len,
const uint8_t * signature )
nodiscard

RSA verify a signature against a digest using a wrapped pubkey.

Parameters
[in]keyWrapped RSA public-key handle.
[in]sizeRSA modulus selector.
[in]digestPre-computed message digest.
[in]digest_lenDigest length.
[in]signatureSignature (modulus / 8 bytes).
Returns
ra8_err_t error code.
Return values
k_ra8_okSignature valid.
k_ra8_err_not_supportedProduction build fail-closed; no RSIP backend, use tf-psa-crypto.
k_ra8_err_null_ptrAny pointer was NULL.
k_ra8_err_invalid_argBad size.
k_ra8_err_hw_timeoutEngine never signalled DONE.
k_ra8_err_hw_errorSignature did not verify.
Precondition
key->alg is an RSA install opcode.
digest and signature are non-NULL.
Postcondition
On success, the signature has been validated by the engine.
Note
Thread safety: not thread-safe.
Fail-closed in production (HUM Ch 52 documents no RSIP backend); the fake/stub command path never ships. Real crypto: tf-psa-crypto (issues #214 / #187 / #181).
Since
0.1.0

Definition at line 378 of file ra8_rsip_rsa.c.

References k_ra8_err_not_supported, RA8_CHECK_NULL_PTR, and s_tag.

Variable Documentation

◆ s_tag

const char* s_tag = "RSIP"
static

Logger tag used by every ra8_log_* call in this TU.

Kept short ("RSIP") so it fits in the fixed-width log prefix without truncation. Each RSIP translation unit keeps its own private copy.

Note
Static, file-scope.
Since
0.1.0

Definition at line 57 of file ra8_rsip_rsa.c.