Skip to content
FutureBlitz

    Install

    Import std.crypto.derive

    std.crypto.derive

    Hmac, Hkdf, and Pbkdf2, over mbedTLS: a MAC, which a key makes and checks, a key from other key material, and a key from a password: HMAC and PBKDF2 by SHA-1, SHA-256, or SHA-512, and HKDF by SHA-256 or SHA-512.

    std/crypto/derive.fb

    Types

    Hmac struct

    Public Struct Hmac

    HMAC (RFC 2104) of data with key, of any length: a MAC as long as its hash, which only who has the key can make. Check one with ConstantTimeEquals.

    std/crypto/derive.fb, line 22

    • Public Static Method Sha1(key: UInt8[], data: UInt8[]): UInt8[] static method #

      HMAC-SHA1's 20 bytes, for the formats that ask for it.

    • Public Static Method Sha1(key: UInt8[], text: String): UInt8[] static method #

      HMAC-SHA1 of text's UTF-8 bytes with key.

    • Public Static Method Sha256(key: UInt8[], data: UInt8[]): UInt8[] static method #

      HMAC-SHA256's 32 bytes.

    • Public Static Method Sha256(key: UInt8[], text: String): UInt8[] static method #

      HMAC-SHA256 of text's UTF-8 bytes with key.

    • Public Static Method Sha512(key: UInt8[], data: UInt8[]): UInt8[] static method #

      HMAC-SHA512's 64 bytes.

    • Public Static Method Sha512(key: UInt8[], text: String): UInt8[] static method #

      HMAC-SHA512 of text's UTF-8 bytes with key.

    Hkdf struct

    Public Struct Hkdf

    HKDF (RFC 5869): length bytes of new key from material, a secret like a shared one from X25519, with salt, which can be empty, and info, which says what the key is for, so keys for different uses differ.

    std/crypto/derive.fb, line 50

    • @PanicsAtCaller Public Static Method Sha256(material: UInt8[], salt: UInt8[], info: UInt8[], length: Int): UInt8[] static method #

      By SHA-256. Panics unless length is from 0 to 8160, 255 hashes.

    • @PanicsAtCaller Public Static Method Sha512(material: UInt8[], salt: UInt8[], info: UInt8[], length: Int): UInt8[] static method #

      By SHA-512. Panics unless length is from 0 to 16320, 255 hashes.

    Pbkdf2 struct

    Public Struct Pbkdf2

    PBKDF2 (RFC 8018) with HMAC: length bytes of key from password and salt, in iterations rounds, which make a guess at the password cost that many. For keeping passwords, Argon2id is stronger, since it needs memory too. Each panics unless iterations is 1 or more and length isn't negative.

    std/crypto/derive.fb, line 74

    • @PanicsAtCaller Public Static Method Sha1(password: String, salt: UInt8[], iterations: Int, length: Int): UInt8[] static method #

      By SHA-1, for the formats that ask for it.

    • @PanicsAtCaller Public Static Method Sha1(password: UInt8[], salt: UInt8[], iterations: Int, length: Int): UInt8[] static method #

      A key derived from the bytes of password by SHA-1, as the one that takes a String does.

    • @PanicsAtCaller Public Static Method Sha256(password: String, salt: UInt8[], iterations: Int, length: Int): UInt8[] static method #

      By SHA-256.

    • @PanicsAtCaller Public Static Method Sha256(password: UInt8[], salt: UInt8[], iterations: Int, length: Int): UInt8[] static method #

      A key derived from the bytes of password by SHA-256, as the one that takes a String does.

    • @PanicsAtCaller Public Static Method Sha512(password: String, salt: UInt8[], iterations: Int, length: Int): UInt8[] static method #

      By SHA-512.

    • @PanicsAtCaller Public Static Method Sha512(password: UInt8[], salt: UInt8[], iterations: Int, length: Int): UInt8[] static method #

      A key derived from the bytes of password by SHA-512, as the one that takes a String does.

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