secret/hygiene
src/secret/hygiene.tur
free-standing crypto hygiene primitives.
Since: 0.1.0
defn
secure-wipe-ptr!
(secure-wipe-ptr! [p ptr<void> n : int] :)
zero `n` bytes at `p` in a way the optimizer may not
Parameters
| p | start of the region to zero; NULL is a no-op | |
| n | byte count; values <= 0 are a no-op |
Returns
Nothing.
Example
(secure-wipe-ptr! key 32)
Since: 0.1.0
defn
crypto-random-bytes!
(crypto-random-bytes! [p ptr<void> n : int])
fill `n` bytes at `p` from the OS CSPRNG.
Parameters
| p | destination buffer, at least `n` bytes | |
| n | byte count; 0 succeeds trivially, negative is an error |
Returns
(Result int cstr) -- ok carries the byte count written; err carries a static description. On error the destination is left wiped, never partially filled with low-entropy bytes.
Example
(let [r (crypto-random-bytes! buf 32)]
(if (ok? r) (use-key buf) (die (err-val r))))
Since: 0.1.0
defn
crypto-random-source
(crypto-random-source :)
name the CSPRNG backend this build selected.
Returns
A static cstr: "BCryptGenRandom", "arc4random_buf", "getrandom", or "/dev/urandom".
Example
(println (crypto-random-source)) ; => "arc4random_buf" on macOS
Since: 0.1.0
defn
ct-eq-ptr?
(ct-eq-ptr? [a ptr<void> b ptr<void> n : int] :)
compare two `n`-byte buffers in time independent of content.
Parameters
| a | first buffer | |
| b | second buffer | |
| n | byte count to compare; <= 0 compares equal |
Returns
true when all `n` bytes match.
Example
(if (ct-eq-ptr? computed-mac supplied-mac 32) (accept) (reject))
Since: 0.1.0