silk/rsa
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc.
Bounded RSA public-key admission and SHA-256 signature verification.
When to use
Use RsaPublicKey for the selected 2048..4096-bit RSA profile with exponent 65537.
Use verifyPss for the selected PSS profile and verifyCertificate for certificate signature algorithms.
Details
Keys own bounded public data. Verification borrows inputs, requires no provider and performs no signing. Certificate operations consume the original algorithm DER and BIT STRING metadata from a container decoder.
Gotchas
A valid signature does not establish certificate trust, service identity or a valid certificate path. Arithmetic processes public values with bounded variable work. This module contains no private-key operation.
Import as RsaPublicKey with import silk.rsa { RsaPublicKey }.
Public declarations: 2.
RsaError
pub enum RsaErrorA bounded RSA admission or verification failure without caller-owned byte data.
InvalidKey
InvalidKey = 0The modulus or exponent is outside the selected public-key profile.
InvalidEncoding
InvalidEncoding = 1A DER value has invalid, nonminimal or trailing encoding.
InvalidParameters
InvalidParameters = 2An algorithm identifier or effective parameter is outside the selected profile.
InvalidLength
InvalidLength = 3The signature width or BIT STRING alignment is invalid.
MessageTooLong
MessageTooLong = 4The message exceeds the SHA-256 input domain.
InvalidSignature
InvalidSignature = 5The representative, padding or digest does not verify.
RsaPublicKey
pub struct RsaPublicKeyAn admitted RSA public key with bounded owned storage and exponent 65537.
Associated function RsaPublicKey.fromComponents
pub fn fromComponents<'life0, 'life1>(modulus: &'life0 [u8], exponent: &'life1 [u8]) -> silk/result.Result<silk/rsa.RsaPublicKey, silk/rsa.RsaError>Admits canonical unsigned modulus bytes and exponent 65537 into an owned public key.
Details
The modulus must be odd and contain 2048 through 4096 significant bits. Leading zero bytes are rejected. The exponent must be exactly the three bytes 01 00 01. Rejection returns InvalidKey without retaining input.
Method RsaPublicKey.verifyPss
pub fn verifyPss<'life0, 'life1, 'life2>(self: &'life0 silk/rsa.RsaPublicKey, message: &'life1 [u8], signature: &'life2 [u8]) -> silk/result.Result<(), silk/rsa.RsaError>Verifies the selected SHA-256 PSS profile against the exact borrowed message bytes.
Details
Requires signature width ceil(modulusBits/8), a representative below the modulus, MGF1-SHA-256, salt length 32 and trailer 1. The message is hashed once. Inputs are borrowed without retention. InvalidLength, MessageTooLong or InvalidSignature identifies rejection; no input is changed.
Gotchas
This operation does not establish certificate trust or service identity. It requires no entropy provider.
Associated function RsaPublicKey.fromCertificateKey
pub fn fromCertificateKey<'life0, 'life1>(algorithmDer: &'life0 [u8], keyDer: &'life1 [u8], unusedBits: u8) -> silk/result.Result<silk/rsa.RsaPublicKey, silk/rsa.RsaError>Admits certificate RSA key DER after checking its original AlgorithmIdentifier and BIT STRING alignment.
Details
Pass the decoder's algorithm DER, key BIT STRING bytes and unused-bit count unchanged. Requires rsaEncryption with absent or NULL parameters and a minimal positive RSAPublicKey DER sequence. The modulus and exponent then pass the same bounded profile as fromComponents. Malformed DER returns InvalidEncoding; wrong algorithm parameters return InvalidParameters. Nonzero unused bits return InvalidLength. No borrowed bytes are retained.
Method RsaPublicKey.verifyCertificate
pub fn verifyCertificate<'life0, 'life1, 'life2, 'life3>(self: &'life0 silk/rsa.RsaPublicKey, message: &'life1 [u8], algorithmDer: &'life2 [u8], signature: &'life3 [u8], unusedBits: u8) -> silk/result.Result<(), silk/rsa.RsaError>Verifies a certificate signature using admitted SHA-256 PSS or PKCS#1 v1.5 metadata.
Details
Pass the original signature AlgorithmIdentifier DER and BIT STRING unused-bit count. PSS requires effective SHA-256, MGF1-SHA-256, salt32 and trailer1 parameters. sha256WithRSAEncryption accepts absent or NULL parameters and strict DigestInfo padding. The message is hashed once. Metadata rejection precedes public exponentiation. Nonzero unused bits return InvalidLength; unsupported parameters return InvalidParameters. Other failures match verifyPss. No provider, allocation or mutation is required.
Gotchas
Signature validity does not establish certificate trust, path validity or service identity.