90#ifndef DETERMINISTICESPASYNCWEBSERVER_SSH_RSA_H
91#define DETERMINISTICESPASYNCWEBSERVER_SSH_RSA_H
116#define SSH_RSA_KEY_DER_MAX 1700
119#define SSH_RSA_KEY_BYTES 256
122#define SSH_RSA_SIG_BYTES 256
134#define SSH_RSA_PUBKEY_ALG "ssh-rsa"
137#define SSH_RSA_PUBKEY_ALG_LEN 7
140static constexpr char SSH_RSA_SIG_ALG_SHA256[] =
"rsa-sha2-256";
143static constexpr char SSH_RSA_SIG_ALG_SHA512[] =
"rsa-sha2-512";
152static constexpr size_t SSH_PKCS1_DIGESTINFO_LEN = 19;
155static constexpr size_t SSH_PKCS1_SHA512_DIGESTINFO_LEN = 19;
293 const uint8_t *sig,
size_t sig_len,
SshRsaHash hash);
301#define SSH_RSA_PUBKEY_BLOB_MAX (4 + 7 + 4 + 1 + 4 + 4 + 1 + 256)
2048-bit big-integer arithmetic for DH-group14 and RSA-2048.
int ssh_rsa_verify(const uint8_t n_be[SSH_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, SshRsaHash hash)
Verify an RSA PKCS#1 v1.5 signature (rsa-sha2-256/512) with a public key.
SshRsaHash
Hash algorithm selecting the RSA signature scheme (RFC 8332).
int ssh_rsa_sign(const uint8_t *msg, size_t msg_len, SshRsaHash hash, uint8_t sig[SSH_RSA_SIG_BYTES])
Sign msg using the RSA host key (PKCS#1 v1.5, rsa-sha2-256/512).
SshRsaPubKey ssh_host_pubkey
Static host public key (BSS). Set by ssh_rsa_load_pubkey().
const uint8_t ssh_pkcs1_sha512_digestinfo[SSH_PKCS1_SHA512_DIGESTINFO_LEN]
The DER-encoded DigestInfo wrapper for SHA-512.
#define SSH_RSA_SIG_BYTES
PKCS#1 v1.5 signature size for RSA-2048 in bytes.
int ssh_rsa_load_pubkey(void)
Load the public portion of the RSA host key into ssh_host_pubkey.
#define SSH_RSA_KEY_BYTES
RSA modulus and private exponent size in bytes (RSA-2048).
int ssh_rsa_encode_pubkey(uint8_t *out, size_t *out_len, size_t out_cap)
Serialize the RSA public host key into an SSH "ssh-rsa" key blob.
const uint8_t ssh_pkcs1_sha256_digestinfo[SSH_PKCS1_DIGESTINFO_LEN]
The DER-encoded DigestInfo wrapper for SHA-256.
SHA-256 (FIPS 180-4) - streaming context and one-shot API.
SHA-512 (FIPS 180-4) - streaming context and one-shot API.
RSA-2048 private key parameters.
uint8_t e_bytes[4]
Public exponent e (typically 65537).
uint8_t d[SSH_RSA_KEY_BYTES]
Private exponent d (SENSITIVE).
uint8_t n[SSH_RSA_KEY_BYTES]
Modulus n (256 bytes, big-endian).
RSA-2048 public key parameters for the host key blob.
bool loaded
True after ssh_rsa_load_pubkey() succeeds.
uint8_t n[SSH_RSA_KEY_BYTES]
Modulus n (256 bytes, big-endian).
uint8_t e_bytes[4]
Public exponent e (big-endian uint32).