ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
rsa.h File Reference

RSA-2048 PKCS#1 v1.5 signature primitive (RFC 8017) - verify + software sign. More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Macros

#define PC_RSA_KEY_BYTES   256
 RSA modulus / signature size in bytes (RSA-2048).
 
#define PC_RSA_SIG_BYTES   256
 PKCS#1 v1.5 signature size for RSA-2048 in bytes.
 
#define PC_PKCS1_DIGESTINFO_LEN   19
 Length of the DER DigestInfo wrapper for SHA-256 (RFC 8017 / RFC 5754).
 
#define PC_PKCS1_SHA512_DIGESTINFO_LEN   19
 Length of the DER DigestInfo wrapper for SHA-512.
 

Enumerations

enum class  pc_rsa_hash : uint8_t { SHA256 = 0 , SHA512 = 1 }
 Hash algorithm selecting the RSA signature scheme (RFC 8017 §9.2). More...
 

Functions

int pc_rsa_verify (const uint8_t n_be[PC_RSA_KEY_BYTES], const uint8_t e_be4[4], const uint8_t *msg, size_t msg_len, const uint8_t *sig, size_t sig_len, pc_rsa_hash hash)
 Verify an RSA-2048 PKCS#1 v1.5 signature over msg.
 

Variables

const uint8_t pc_pkcs1_sha256_digestinfo [PC_PKCS1_DIGESTINFO_LEN]
 The DER-encoded DigestInfo wrapper for SHA-256 (prepend to the 32-byte digest).
 
const uint8_t pc_pkcs1_sha512_digestinfo [PC_PKCS1_SHA512_DIGESTINFO_LEN]
 The DER-encoded DigestInfo wrapper for SHA-512 (prepend to the 64-byte digest).
 

Detailed Description

RSA-2048 PKCS#1 v1.5 signature primitive (RFC 8017) - verify + software sign.

The shared, protocol-agnostic RSA primitive: it takes raw big-endian key material (modulus n, exponent) and a message, and does the RSASSA-PKCS1-v1.5 math with a SHA-256 or SHA-512 digest. It knows nothing about SSH key blobs, host-key storage, or the "ssh-rsa" / "rsa-sha2-256" wire names - that layer lives in network_drivers/presentation/ssh/crypto/ssh_rsa and calls into this primitive.

Verify runs on both platforms (mbedtls on Arduino/ESP32, software on native). The software sign (pc_rsa_sign_sw, raw n/d) is the native-only reference path used by the tests; on-device signing with a cached host-key context is the SSH layer's job.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file rsa.h.

Macro Definition Documentation

◆ PC_RSA_KEY_BYTES

#define PC_RSA_KEY_BYTES   256

RSA modulus / signature size in bytes (RSA-2048).

Definition at line 28 of file rsa.h.

◆ PC_RSA_SIG_BYTES

#define PC_RSA_SIG_BYTES   256

PKCS#1 v1.5 signature size for RSA-2048 in bytes.

Definition at line 31 of file rsa.h.

◆ PC_PKCS1_DIGESTINFO_LEN

#define PC_PKCS1_DIGESTINFO_LEN   19

Length of the DER DigestInfo wrapper for SHA-256 (RFC 8017 / RFC 5754).

Definition at line 45 of file rsa.h.

◆ PC_PKCS1_SHA512_DIGESTINFO_LEN

#define PC_PKCS1_SHA512_DIGESTINFO_LEN   19

Length of the DER DigestInfo wrapper for SHA-512.

Definition at line 48 of file rsa.h.

Enumeration Type Documentation

◆ pc_rsa_hash

enum class pc_rsa_hash : uint8_t
strong

Hash algorithm selecting the RSA signature scheme (RFC 8017 §9.2).

Only the message hash and its DigestInfo OID differ between the two.

Enumerator
SHA256 

RSASSA-PKCS1-v1.5 with SHA-256.

SHA512 

RSASSA-PKCS1-v1.5 with SHA-512.

Definition at line 38 of file rsa.h.

Function Documentation

◆ pc_rsa_verify()

int pc_rsa_verify ( const uint8_t  n_be[PC_RSA_KEY_BYTES],
const uint8_t  e_be4[4],
const uint8_t *  msg,
size_t  msg_len,
const uint8_t *  sig,
size_t  sig_len,
pc_rsa_hash  hash 
)

Verify an RSA-2048 PKCS#1 v1.5 signature over msg.

Parameters
n_beModulus n, 256 bytes big-endian.
e_be4Public exponent e, 4 bytes big-endian (typically 65537).
msgMessage that was signed (this hashes it; do not pre-hash).
msg_lenMessage length.
sigSignature, big-endian.
sig_lenSignature length (must equal PC_RSA_KEY_BYTES).
hashDigest algorithm (SHA-256 / SHA-512).
Returns
0 if the signature is valid, -1 otherwise.

Definition at line 55 of file rsa.cpp.

References PC_RSA_KEY_BYTES, pc_sha256(), PC_SHA256_DIGEST_LEN, pc_sha512(), PC_SHA512_DIGEST_LEN, and SHA512.

Variable Documentation

◆ pc_pkcs1_sha256_digestinfo

const uint8_t pc_pkcs1_sha256_digestinfo[PC_PKCS1_DIGESTINFO_LEN]
extern

The DER-encoded DigestInfo wrapper for SHA-256 (prepend to the 32-byte digest).

Definition at line 31 of file rsa.cpp.

◆ pc_pkcs1_sha512_digestinfo

const uint8_t pc_pkcs1_sha512_digestinfo[PC_PKCS1_SHA512_DIGESTINFO_LEN]
extern

The DER-encoded DigestInfo wrapper for SHA-512 (prepend to the 64-byte digest).

Definition at line 40 of file rsa.cpp.