bjosodium: libsodium's authenticated encryption and Argon2id for Bjolang
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
911f4bcc46
9 changed files with 1409 additions and 0 deletions
59
bench/ciphers.bjo
Normal file
59
bench/ciphers.bjo
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
;; bjosodium/bench/ciphers.bjo — the two ciphers side by side, and the cost
|
||||
;; of Argon2id.
|
||||
;;
|
||||
;; bjo bench bench/ciphers.bjo --all
|
||||
;; bjo bench bench/ciphers.bjo --compare-within aead
|
||||
;;
|
||||
;; The times include this module's work for each call: the checks of the
|
||||
;; lengths and a new array for the result.
|
||||
|
||||
(import (std prelude))
|
||||
(import (std bench))
|
||||
(import (bjosodium core))
|
||||
|
||||
(def/bench "encrypt AEGIS-256"
|
||||
#:group "aead"
|
||||
#:params ((bytes [1024 1048576]))
|
||||
#:setup ((key (make-aead-key Aegis256))
|
||||
(nonce (make-aead-nonce Aegis256))
|
||||
(message (: (make-array bytes) (Array byte))))
|
||||
(aead-encrypt Aegis256 key nonce message))
|
||||
|
||||
(def/bench "encrypt XChaCha20-Poly1305"
|
||||
#:group "aead"
|
||||
#:params ((bytes [1024 1048576]))
|
||||
#:setup ((key (make-aead-key XChaCha20Poly1305))
|
||||
(nonce (make-aead-nonce XChaCha20Poly1305))
|
||||
(message (: (make-array bytes) (Array byte))))
|
||||
(aead-encrypt XChaCha20Poly1305 key nonce message))
|
||||
|
||||
(def/bench "decrypt AEGIS-256"
|
||||
#:group "aead"
|
||||
#:params ((bytes [1024 1048576]))
|
||||
#:setup ((key (make-aead-key Aegis256))
|
||||
(nonce (make-aead-nonce Aegis256))
|
||||
(boxed (aead-encrypt Aegis256 key nonce (: (make-array bytes) (Array byte)))))
|
||||
(aead-decrypt Aegis256 key nonce boxed))
|
||||
|
||||
(def/bench "decrypt XChaCha20-Poly1305"
|
||||
#:group "aead"
|
||||
#:params ((bytes [1024 1048576]))
|
||||
#:setup ((key (make-aead-key XChaCha20Poly1305))
|
||||
(nonce (make-aead-nonce XChaCha20Poly1305))
|
||||
(boxed (aead-encrypt XChaCha20Poly1305 key nonce (: (make-array bytes) (Array byte)))))
|
||||
(aead-decrypt XChaCha20Poly1305 key nonce boxed))
|
||||
|
||||
;; The default cost, and libsodium's MODERATE cost.
|
||||
(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))
|
||||
|
||||
(run-benches)
|
||||
Loading…
Add table
Add a link
Reference in a new issue