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

RSA-2048 PKCS#1 v1.5 verify + software sign (see rsa.h). More...

#include "crypto/asymmetric/rsa.h"
#include "crypto/crypto_opt.h"
#include "crypto/crypto_scratch.h"
#include "crypto/hash/sha256.h"
#include "crypto/hash/sha512.h"
#include "server/mmgr/secure.h"
#include <string.h>
#include <mbedtls/md.h>
#include <mbedtls/rsa.h>

Go to the source code of this file.

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

PC_CRYPTO_HOT 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 verify + software sign (see rsa.h).

Verify: mbedtls on Arduino (hardware/mbedTLS), software full-width modexp on native. Software sign (native) is the test reference path. Protocol-agnostic - raw big-endian key material in, no SSH.

Definition in file rsa.cpp.

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

PC_CRYPTO_HOT const uint8_t pc_pkcs1_sha256_digestinfo[PC_PKCS1_DIGESTINFO_LEN]
Initial value:
= {
0x30, 0x31,
0x30, 0x0d,
0x06, 0x09,
0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01,
0x05, 0x00,
0x04, 0x20
}

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]
Initial value:
= {
0x30, 0x51,
0x30, 0x0d,
0x06, 0x09,
0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03,
0x05, 0x00,
0x04, 0x40
}

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

Definition at line 40 of file rsa.cpp.