Keys and nonces are types; Argon2id costs are explicit; passwords are NFC
- AeadKey and AeadNonce are opaque types. A key given where a nonce is wanted is a type error: for AEGIS-256 both are 32 bytes, and as arrays a swap would store the key in clear. Both print as #<AeadKey> and #<AeadNonce>. - A nonce knows its cipher, so aead-encrypt and aead-decrypt take none. They and the nonce functions move to (bjosodium raw). (bjosodium core) keeps aead-seal and aead-unseal, which make the nonce. - Every Argon2id function takes an Argon2idCost. There are no defaults: a key made with a default that a later version changed would not be made again. argon2id-interactive, -moderate and -sensitive are libsodium's three costs. - argon2id-derive-key returns an AeadKey of 32 bytes. #:length is gone. - Passwords are normalized to Unicode NFC before Argon2id. - random-bytes. make-aead-key takes no cipher: both keys are 32 bytes. - (bjosodium impl) holds the code; core and raw are facades of it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
911f4bcc46
commit
2b42abb6d9
8 changed files with 738 additions and 522 deletions
|
|
@ -14,46 +14,46 @@
|
|||
(import (std prelude))
|
||||
(import (std bench))
|
||||
(import (bjosodium core))
|
||||
(import (bjosodium raw))
|
||||
|
||||
(def/bench "encrypt AEGIS-256"
|
||||
#:group "aead"
|
||||
#:params ((bytes [1024 1048576]))
|
||||
#:setup ((key (make-aead-key Aegis256))
|
||||
#:setup ((key (make-aead-key))
|
||||
(nonce (make-aead-nonce Aegis256))
|
||||
(message (: (make-array bytes) (Array byte))))
|
||||
(aead-encrypt Aegis256 key nonce message))
|
||||
(aead-encrypt key nonce message))
|
||||
|
||||
(def/bench "encrypt XChaCha20-Poly1305"
|
||||
#:group "aead"
|
||||
#:params ((bytes [1024 1048576]))
|
||||
#:setup ((key (make-aead-key XChaCha20Poly1305))
|
||||
#:setup ((key (make-aead-key))
|
||||
(nonce (make-aead-nonce XChaCha20Poly1305))
|
||||
(message (: (make-array bytes) (Array byte))))
|
||||
(aead-encrypt XChaCha20Poly1305 key nonce message))
|
||||
(aead-encrypt key nonce message))
|
||||
|
||||
(def/bench "decrypt AEGIS-256"
|
||||
#:group "aead"
|
||||
#:params ((bytes [1024 1048576]))
|
||||
#:setup ((key (make-aead-key Aegis256))
|
||||
#:setup ((key (make-aead-key))
|
||||
(nonce (make-aead-nonce Aegis256))
|
||||
(boxed (aead-encrypt Aegis256 key nonce (: (make-array bytes) (Array byte)))))
|
||||
(aead-decrypt Aegis256 key nonce boxed))
|
||||
(boxed (aead-encrypt key nonce (: (make-array bytes) (Array byte)))))
|
||||
(aead-decrypt key nonce boxed))
|
||||
|
||||
(def/bench "decrypt XChaCha20-Poly1305"
|
||||
#:group "aead"
|
||||
#:params ((bytes [1024 1048576]))
|
||||
#:setup ((key (make-aead-key XChaCha20Poly1305))
|
||||
#:setup ((key (make-aead-key))
|
||||
(nonce (make-aead-nonce XChaCha20Poly1305))
|
||||
(boxed (aead-encrypt XChaCha20Poly1305 key nonce (: (make-array bytes) (Array byte)))))
|
||||
(aead-decrypt XChaCha20Poly1305 key nonce boxed))
|
||||
(boxed (aead-encrypt key nonce (: (make-array bytes) (Array byte)))))
|
||||
(aead-decrypt key nonce boxed))
|
||||
|
||||
;; The default cost, and libsodium's MODERATE cost.
|
||||
;; libsodium's INTERACTIVE and MODERATE costs.
|
||||
(def/bench "argon2id-derive-key"
|
||||
#:group "argon2id"
|
||||
#:params ((cost ["t=2 m=64MiB" "t=3 m=256MiB"]))
|
||||
#:setup ((salt (: (make-array argon2id-salt-length) (Array byte)))
|
||||
(t (if (= cost "t=2 m=64MiB") 2 3))
|
||||
(m (if (= cost "t=2 m=64MiB") 65536 262144)))
|
||||
(argon2id-derive-key "correct horse battery staple" salt #:iterations t #:memory-kib m))
|
||||
(c (if (= cost "t=2 m=64MiB") argon2id-interactive argon2id-moderate)))
|
||||
(argon2id-derive-key "correct horse battery staple" salt c))
|
||||
|
||||
(run-benches)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue