No matching definitions.

secret/core

src/secret/core.tur

an owned, page-locked, linearly-typed secret buffer.

Since: 0.1.0

defopaque

Secret

(Secret)

an owned, locked, linear buffer of key material.

Since: 0.1.0

defn

secret-random!

(secret-random! [n : int])

mint an n-byte secret from the OS CSPRNG.

nbyte length; must be positive

(Result Secret cstr) -- ok carries a live, locked Secret the caller must eventually consume with secret-wipe!; err carries a static description. A secret that could not be filled is released here rather than handed back, so the error path leaks neither memory nor a locked page and never yields a zero-filled "key".

(let [r (secret-random! 32)]
    (if (ok? r)
      (let [k (ok-val r)] (do (use k) (secret-wipe! k)))
      0))

Since: 0.1.0

defn

secret-of-bytes

(secret-of-bytes [p ptr<void> n : int] :)

copy `n` bytes into a fresh secret, wiping the source.

psource bytes; wiped in place before this returns
nbyte count; must be positive

(Result Secret cstr) -- ok carries a live, locked Secret.

(let [r (secret-of-bytes raw 32)]   ; raw is zeroed on return
    (if (ok? r) (ok-val r) ...))

Since: 0.1.0

defn

secret-wipe!

(secret-wipe! [s : Secret] :)

zero, unlock, and free a secret. THE destructor.

sthe secret to destroy

Nothing.

(secret-wipe! k)

Since: 0.1.0

defn

with-secret

(with-secret [^borrow s : Secret f : (fn [ptr<void> int])

run `f` over the secret's bytes for the duration of the call.

sthe secret, borrowed for the duration of the call
freceives (bytes, length) and returns an int

Whatever `f` returned.

(with-secret k hash-into)

Since: 0.1.0

defn

secret-len

(secret-len [^borrow s : Secret] :)

the secret's payload length in bytes.

sthe secret, borrowed

The byte length passed at construction.

(secret-len k)  ; => 32

Since: 0.1.0

defn

secret-locked?

(secret-locked? [^borrow s : Secret] :)

did the backing pages actually get locked into RAM?

sthe secret, borrowed

true when mlock/VirtualLock succeeded at construction.

(if (secret-locked? k) 0 (warn "key may reach swap"))

Since: 0.1.0

defn

secret-eq?

(secret-eq? [^borrow a : Secret ^borrow b : Secret] :)

constant-time equality of two secrets' contents.

afirst secret, borrowed
bsecond secret, borrowed

true when both hold the same bytes.

(if (secret-eq? computed supplied) (accept) (reject))

Since: 0.1.0

Internal definitions
secret-alloc-raw-- allocate and lock an n-byte secret; 0 on failure.
secret-free-raw!-- wipe, unlock, and free a raw handle from
secret-fill-random-raw!-- fill a raw handle's payload from the CSPRNG.
secret-copy-in-raw!-- copy n bytes into a raw handle, wiping the source.
secret-of-raw-- reinterpret a raw handle as the opaque Secret.
secret-data-raw-- raw pointer to the payload bytes.