abla/crypto/rsa

Generated from source.

Import with import "abla/crypto/rsa".

Source: abla/crypto/rsa/entry.ab

Re-exports abla/crypto/result.

Re-exports abla/crypto/pbe.

cryptoRandomIsSet (var)

var cryptoRandomIsSet

Indicates whether a caller installed a random-byte provider.

cryptoRandomSource (var)

var cryptoRandomSource: (int) -> string

The caller-supplied random-byte provider used when installed.

cryptoSetRandom (fun)

fun cryptoSetRandom(source: (int) -> string): void

What gives count random bytes on a target with no getrandom here: Wasm (a host's crypto.getRandomValues), an ESP32's hardware RNG. Its quality is yours to answer for.

cryptoRandomBytes (fun)

fun cryptoRandomBytes(count: int): string

Returns count bytes from the configured random provider or the system source. A provider length mismatch or system entropy failure returns an empty string.

RsaPublicKey (class)

class RsaPublicKey(val modulus: string, val exponent: string, val bits: int, val error: string)

A public key: the modulus, big-endian without leading zeros, and the exponent. Check error or ok().

RsaPublicKey.ok (method)

fun ok(): bool

Returns true if constructing the public key reported no error.

rsaPublicFailed (fun)

fun rsaPublicFailed(error: string): RsaPublicKey

Returns an unusable public key carrying the supplied error.

RsaPrivateKey (class)

resource class RsaPrivateKey(
    val modulus: string, val publicExponent: string, val bits: int, val error: string,
    val memory: int, val primeWords: int, val fieldWords: int
)

A private key, its numbers in memory wiped when dropped. Check error or ok().

RsaPrivateKey.drop (method)

trusted fun drop(): void

Wipes and releases the owned private-key limbs, if present.

RsaPrivateKey.ok (method)

fun ok(): bool

Returns true when a private-key allocation is present.

RsaPrivateKey.primeP (method)

fun primeP(): int

Each is primeWords limbs in the key's memory.

RsaPrivateKey.primeQ (method)

fun primeQ(): int

Returns the borrowed address of the second prime's limbs in a valid key.

RsaPrivateKey.exponentP (method)

fun exponentP(): int

Returns the borrowed address of the exponent modulo p - 1 in a valid key.

RsaPrivateKey.exponentQ (method)

fun exponentQ(): int

Returns the borrowed address of the exponent modulo q - 1 in a valid key.

RsaPrivateKey.inverseQ (method)

fun inverseQ(): int

Returns the borrowed address of the CRT coefficient q inverse modulo p in a valid key.

RsaPrivateKey.rejectionKey (method)

fun rejectionKey(): int

Returns the borrowed address of the implicit rejection key bytes for a valid RSA key.

rsaPrivateFailed (fun)

trusted fun rsaPrivateFailed(error: string): RsaPrivateKey

Returns an unusable private key with the supplied error and no key storage.

rsaBitLength (fun)

fun rsaBitLength(value: string): int

Returns the bit length of a big-endian magnitude without leading zero bytes, or zero for empty input.

rsaPublicFromNumbers (fun)

fun rsaPublicFromNumbers(modulus: string, exponent: string, unreadable: string): RsaPublicKey

Returns a public key from big-endian modulus and exponent bytes, or an error key when the numbers are missing or invalid.

rsaPublicFromPkcs1 (fun)

fun rsaPublicFromPkcs1(der: string, begin: int, end: int, unreadable: string): RsaPublicKey

RSAPublicKey: SEQUENCE { modulus, exponent }

rsaAlgorithmIsRsa (fun)

fun rsaAlgorithmIsRsa(der: string, algorithm: DerItem): bool

Whether an AlgorithmIdentifier says rsaEncryption, with NULL or absent parameters.

rsaPublicFromSpki (fun)

fun rsaPublicFromSpki(der: string, begin: int, end: int, unreadable: string): RsaPublicKey

SubjectPublicKeyInfo at begin, which must end at end.

rsaPublicKeyFromDer (fun)

fun rsaPublicKeyFromDer(der: string): RsaPublicKey

SubjectPublicKeyInfo, or what hosted also reads there, in DER.

rsaPublicKeyFromCertificateDer (fun)

fun rsaPublicKeyFromCertificateDer(der: string): RsaPublicKey

The key of an X.509 certificate in DER. Neither its chain, its dates nor its signature is checked.

rsaPublicKeyFromPem (fun)

fun rsaPublicKeyFromPem(pem: string): RsaPublicKey

PUBLIC KEY (SubjectPublicKeyInfo), RSA PUBLIC KEY, or the key of a CERTIFICATE.

rsaPrivateFromPkcs1 (fun)

trusted fun rsaPrivateFromPkcs1(der: string, begin: int, end: int,
    unreadable: string): RsaPrivateKey

RSAPrivateKey, in PKCS#1. Its numbers go into raw memory; der itself remains a string, which nothing wipes: see the docs.

rsaPrivateFromNumbers (fun)

trusted fun rsaPrivateFromNumbers(
    modulus: string, exponent: string, p: string, q: string, dp: string, dq: string,
    qInverse: string,
    privateExponent: string = ""
): RsaPrivateKey

Returns an owned private key from the supplied big-endian RSA numbers, or an error key if the consistency checks fail.

rsaPrivateIsConsistent (fun)

trusted fun rsaPrivateIsConsistent(key: RsaPrivateKey): bool

p * q is the modulus, and the key takes a number to its power and back.

rsaPrivateFromPkcs8 (fun)

trusted fun rsaPrivateFromPkcs8(der: string, unreadable: string): RsaPrivateKey

PrivateKeyInfo: SEQUENCE { version, AlgorithmIdentifier, OCTET STRING { RSAPrivateKey }, ... }

rsaPrivateKeyFromDer (fun)

trusted fun rsaPrivateKeyFromDer(der: string): RsaPrivateKey

Unencrypted PKCS#8 or PKCS#1 DER.

rsaPrivateKeyFromPem (fun)

trusted fun rsaPrivateKeyFromPem(pem: string): RsaPrivateKey

Unencrypted PRIVATE KEY (PKCS#8) or RSA PRIVATE KEY (PKCS#1). Use the CryptoPassword overload for PBES2. RSA-PSS remains hosted-only.

bodyHasHeaders (fun)

fun bodyHasHeaders(body: string): bool

Returns true if the PEM body contains a legacy Proc-Type header.

rsaPrivateOperation (fun)

trusted fun rsaPrivateOperation(key: RsaPrivateKey, value: string): CryptoResult

value, bytes of the modulus's length below it, to the private exponent: blinded, by CRT, in constant time, and checked with the public exponent before it's returned.

rsaEncodedSignature (fun)

fun rsaEncodedSignature(size: int, digestInfo: string, digest: string): string

Returns a PKCS#1 v1.5 encoded digest block, or empty text when fewer than eight padding bytes fit.

rsaPublicOperation (fun)

trusted fun rsaPublicOperation(key: RsaPublicKey, value: string): string

value ^ e mod n, as size bytes, or "" if value isn't a number below n of that length.

rsaVerifyWith (fun)

fun rsaVerifyWith(key: RsaPublicKey, digestInfo: string, digest: string, signature: string): bool

Returns true when the recovered signature exactly matches the encoded digest, or false for a mismatch or unusable key.

rsaSignWith (fun)

trusted fun rsaSignWith(key: RsaPrivateKey, digestInfo: string, digest: string): CryptoResult

Returns a PKCS#1 v1.5 signature or an error if the key is too small or the private operation fails.

RsaPrivateKey.signPkcs1Sha256 (extension fun)

trusted fun RsaPrivateKey.signPkcs1Sha256(message: string): CryptoResult

RSASSA-PKCS1-v1_5 with SHA-256, on a key of 2048 bits or more: deterministic, whatever the blinding.

RsaPublicKey.verifyPkcs1Sha256 (extension fun)

fun RsaPublicKey.verifyPkcs1Sha256(message: string, signature: string): bool

Returns true for a valid SHA-256 PKCS#1 v1.5 signature under an accepted key of at least 2048 bits.

RsaPrivateKey.signPkcs1Sha1Legacy (extension fun)

trusted fun RsaPrivateKey.signPkcs1Sha1Legacy(message: string): CryptoResult

SHA-1 collisions are practical, and 1024-bit RSA is within reach of a well-funded attacker, so nothing new should use this. It exists for what mandates it, as Portugal's Despacho 8632/2014 does for invoices.

RsaPublicKey.verifyPkcs1Sha1Legacy (extension fun)

fun RsaPublicKey.verifyPkcs1Sha1Legacy(message: string, signature: string): bool

Returns true for a valid legacy SHA-1 PKCS#1 v1.5 signature under an accepted key of at least 1024 bits.

rsaMgf1 (fun)

fun rsaMgf1(seed: string, size: int, hash: (string) -> string): string

Returns the requested number of MGF1 mask bytes using a digest function that produces a nonempty result.

rsaByte (fun)

fun rsaByte(value: int): string

Returns the low eight bits as a one-byte string.

rsaEncryptOaep (fun)

fun rsaEncryptOaep(key: RsaPublicKey, plaintext: string, hash: (string) -> string,
    hashSize: int): CryptoResult

Returns OAEP ciphertext or an error if the plaintext cannot fit, randomness is unavailable, or the public operation fails.

RsaPublicKey.encryptOaepSha256 (extension fun)

fun RsaPublicKey.encryptOaepSha256(plaintext: string): CryptoResult

OAEP with SHA-256 for both hashes, on 2048 bits or more: what new designs use.

RsaPublicKey.encryptOaepSha1Legacy (extension fun)

fun RsaPublicKey.encryptOaepSha1Legacy(plaintext: string): CryptoResult

OAEP with SHA-1 for both hashes, the default of Java's OAEPPadding and .NET's fOAEP.

RsaPublicKey.encryptPkcs1Legacy (extension fun)

fun RsaPublicKey.encryptPkcs1Legacy(plaintext: string): CryptoResult

RSAES-PKCS1-v1_5, which AT's clients use for the WS-Security Nonce. Use it only where the protocol leaves no choice; exposing decryption success can create a padding oracle. Randomized.

rsaDecryptBlock (fun)

trusted fun rsaDecryptBlock(key: RsaPrivateKey, ciphertext: string): CryptoResult

Ciphertext is public; reject non-canonical representatives before the private operation.

rsaDecryptOaep (fun)

trusted fun rsaDecryptOaep(key: RsaPrivateKey, ciphertext: string, hash: (string) -> string,
    hashSize: int): CryptoResult

Returns OAEP plaintext or a failure result if the private operation or encoded block validation fails.

RsaPrivateKey.decryptOaepSha256 (extension fun)

trusted fun RsaPrivateKey.decryptOaepSha256(ciphertext: string): CryptoResult

RSAES-OAEP with SHA-256 and an empty label, on a key of at least 2048 bits.

RsaPrivateKey.decryptOaepSha1Legacy (extension fun)

trusted fun RsaPrivateKey.decryptOaepSha1Legacy(ciphertext: string): CryptoResult

RSAES-OAEP with SHA-1 and an empty label, for legacy interoperability.

rsaImplicitPrf (fun)

fun rsaImplicitPrf(kdk: string, label: string, size: int): string

draft-irtf-cfrg-rsa-guidance-10 section 7: OpenSSL-compatible IRPRF, HMAC-SHA256(KDK, uint16(counter) || label || uint16(bits)).

RsaPrivateKey.decryptPkcs1Legacy (extension fun)

trusted fun RsaPrivateKey.decryptPkcs1Legacy(ciphertext: string): CryptoResult

RSAES-PKCS1-v1_5 with deterministic implicit rejection. Successful output still needs protocol validation.

rsaGeneratePrivateKey (fun)

trusted fun rsaGeneratePrivateKey(bits: int = 2048): RsaPrivateKey

Generate a 2048-, 3072-, or 4096-bit RSA key using e=65537.

RsaPrivateKey.toPkcs8Der (extension fun)

trusted fun RsaPrivateKey.toPkcs8Der(): CryptoResult

Export an unencrypted PKCS#8 PrivateKeyInfo.

RsaPrivateKey.toPkcs8Pem (extension fun)

trusted fun RsaPrivateKey.toPkcs8Pem(): CryptoResult

Export an unencrypted PKCS#8 PRIVATE KEY PEM.

rsaPrivateKeyFromDer (fun)

trusted fun rsaPrivateKeyFromDer(der: string, password: CryptoPassword,
    limits: RsaKeyReadLimits = rsaKeyReadLimits()): RsaPrivateKey

Reads PBES2-encrypted PKCS#8 using an owned password copy.

rsaPrivateKeyFromPem (fun)

trusted fun rsaPrivateKeyFromPem(pem: string, password: CryptoPassword,
    limits: RsaKeyReadLimits = rsaKeyReadLimits()): RsaPrivateKey

Reads an RSA private key from pem using password for encrypted PKCS#8 and limits to bound processing. Check ok and error on the returned key.

rsaPrivateKeyFromPkcs12 (fun)

trusted fun rsaPrivateKeyFromPkcs12(der: string, password: CryptoPassword,
    limits: RsaKeyReadLimits = rsaKeyReadLimits()): RsaPrivateKey

Reads one RSA key from a bounded, MAC-verified modern PKCS#12 container.

Built from Abla v0.2.79 source ba5d6b7d. Examples and generated signatures follow that source revision.