Skip to content
FutureBlitz

    Install

    Import std.crypto.signatures

    std.crypto.signatures

    Ed25519, over Monocypher, and EcdsaP256, Rsa, and X25519, over mbedTLS: signatures, which a private key makes and its public key checks, and key exchange, which gives two sides one secret from their own private keys and each other's public ones. Keys are bytes, as each one's Methods say; Key reads and writes them as PEM. A key or signature that isn't one verifies nothing.

    std/crypto/signatures.fb

    Types

    Ed25519 struct

    Public Struct Ed25519

    Ed25519 (RFC 8032), EdDSA on Curve25519 with SHA-512: a private key is a 32-byte seed, a public key 32 bytes, and a signature 64 bytes, deterministic, so signing needs no random number.

    std/crypto/signatures.fb, line 32

    • Public Static Method NewPrivateKey(): UInt8[] static method #

      A new random private key.

    • @PanicsAtCaller Public Static Method PublicKeyOf(privateKey: UInt8[]): UInt8[] static method #

      privateKey's public key. Panics unless privateKey is 32 bytes.

    • @PanicsAtCaller Public Static Method Sign(privateKey: UInt8[], message: UInt8[]): UInt8[] static method #

      message's signature with privateKey. Panics unless privateKey is 32 bytes.

    • @PanicsAtCaller Public Static Method Sign(privateKey: UInt8[], text: String): UInt8[] static method #

      text's signature, by its UTF-8 bytes, with privateKey. Panics unless privateKey is 32 bytes.

    • Public Static Method Verify(publicKey: UInt8[], message: UInt8[], signature: UInt8[]): Bool static method #

      Whether signature is publicKey's of message.

    • Public Static Method Verify(publicKey: UInt8[], text: String, signature: UInt8[]): Bool static method #

      Whether signature is publicKey's of text's UTF-8 bytes.

    EcdsaP256 struct

    Public Struct EcdsaP256

    ECDSA on NIST's P-256 with SHA-256 (ES256): a private key is 32 bytes, a public key its point, uncompressed, 65 bytes, and a signature r then s, 64 bytes.

    std/crypto/signatures.fb, line 78

    • Public Static Method NewPrivateKey(): UInt8[] static method #

      A new random private key.

    • @PanicsAtCaller Public Static Method PublicKeyOf(privateKey: UInt8[]): UInt8[] static method #

      privateKey's public key. Panics unless privateKey is a P-256 private key.

    • @PanicsAtCaller Public Static Method Sign(privateKey: UInt8[], message: UInt8[]): UInt8[] static method #

      message's signature with privateKey, deterministic, as RFC 6979 makes it, so it needs no random number. Panics unless privateKey is a P-256 private key.

    • @PanicsAtCaller Public Static Method Sign(privateKey: UInt8[], text: String): UInt8[] static method #

      text's signature, by its UTF-8 bytes, with privateKey. Panics unless privateKey is 32 bytes, a number from 1 up to the curve's order.

    • Public Static Method Verify(publicKey: UInt8[], message: UInt8[], signature: UInt8[]): Bool static method #

      Whether signature is publicKey's of message.

    • Public Static Method Verify(publicKey: UInt8[], text: String, signature: UInt8[]): Bool static method #

      Whether signature is publicKey's of text's UTF-8 bytes.

    Rsa struct

    Public Struct Rsa

    RSA signatures, to verify, with SHA-256: a public key is PKCS #1's DER of its modulus and exponent, which PublicKey makes from them, or Key reads from PEM. A modulus has up to 8192 bits, of any number, and a key with a larger one verifies nothing.

    std/crypto/signatures.fb, line 134

    • Public Static Method PublicKey(modulus: UInt8[], exponent: UInt8[]): UInt8[] static method #

      The public key of modulus and exponent, big-endian bytes, as JWK's "n" and "e" are.

    • Public Static Method Verify(publicKey: UInt8[], message: UInt8[], signature: UInt8[]): Bool static method #

      Whether signature is publicKey's of message by RSASSA-PKCS1-v1_5 (RS256).

    • Public Static Method Verify(publicKey: UInt8[], text: String, signature: UInt8[]): Bool static method #

      Whether signature is publicKey's of text's UTF-8 bytes, by RSASSA-PKCS1-v1_5 (RS256).

    • Public Static Method VerifyPss(publicKey: UInt8[], message: UInt8[], signature: UInt8[]): Bool static method #

      Whether signature is publicKey's of message by RSASSA-PSS, with MGF1 by SHA-256 and a salt of 32 bytes, as long as the hash (PS256).

    • Public Static Method VerifyPss(publicKey: UInt8[], text: String, signature: UInt8[]): Bool static method #

      Whether signature is publicKey's of text's UTF-8 bytes, by RSASSA-PSS (PS256).

    X25519 struct

    Public Struct X25519

    X25519 key exchange (RFC 7748): private and public keys are 32 bytes each, and so is the secret two sides share, which a KDF, like Hkdf, makes keys from.

    std/crypto/signatures.fb, line 170

    • Public Static Method NewPrivateKey(): UInt8[] static method #

      A new random private key.

    • @PanicsAtCaller Public Static Method PublicKeyOf(privateKey: UInt8[]): UInt8[] static method #

      privateKey's public key, to give the other side. Panics unless privateKey is 32 bytes.

    • @PanicsAtCaller Public Static Method SharedSecret(privateKey: UInt8[], publicKey: UInt8[]): UInt8[]? static method #

      The secret of privateKey and the other side's publicKey, or Null when publicKey is one of the few that make every secret 0. Panics unless both are 32 bytes.

    Report an issue with this page or with FutureBlitz on GitHub.