crypto.bend relies on unsafe/foreign
raw source on the hub · import bend-kit-crypto@0.1.0.0/crypto.bend as Crypto
Hashes, HMAC, HKDF, and secure random bytes through OpenSSL 3 libcrypto. Source: https://github.com/paymog/bend-kit/tree/main/crypto
1 import
import Base
Definitions
def sha256.words source · line 13 · raw
@len:U32 -> @words:Array<U32> -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>)
def sha512.words source · line 16 · raw
@len:U32 -> @words:Array<U32> -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>)
def sha1.words source · line 20 · raw
@len:U32 -> @words:Array<U32> -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>)
Legacy: SHA-1 is broken for collisions. Use it only where a protocol needs it, such as the WebSocket handshake.
Effects (foreign code)
effect digest.words source · line 8 · raw
@alg:String -> @len:U32 -> @words:Array<U32> -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>)
alg is an OpenSSL digest name, such as "SHA256" or "SHA3-256". Fails with EINVAL for an unknown name.
foreign: effs/crypto.c, effs/crypto.js
effect hmac.words source · line 24 · raw
@alg:String -> @klen:U32 -> @key:Array<U32> -> @dlen:U32 -> @data:Array<U32> -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>)
HMAC (RFC 2104) of data under key, with the digest alg.
foreign: effs/crypto.c, effs/crypto.js
effect hkdf.words source · line 30 · raw
@alg:String -> @slen:U32 -> @salt:Array<U32> -> @klen:U32 -> @ikm:Array<U32> -> @ilen:U32 -> @info:Array<U32> -> @n:U32 -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>)
HKDF (RFC 5869): n octets from ikm, salt, and info. Fails with EINVAL when n is 0 or more than 255 digest lengths.
foreign: effs/crypto.c, effs/crypto.js
effect random.words source · line 36 · raw
@n:U32 -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>)
n octets from the OS secure random source (getentropy, crypto.getRandomValues). Needs no libcrypto.
foreign: effs/crypto.c, effs/crypto.js
effect eq.ct.words source · line 41 · raw
@alen:U32 -> @a:Array<U32> -> @blen:U32 -> @b:Array<U32> -> IO(Bool)
Equal octets, in time that depends only on the lengths. Use it to compare MACs.
foreign: effs/crypto.c, effs/crypto.js