2026-11-21 21:07:27 +01:00
|
|
|
;; 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))
|
2026-11-22 08:13:50 +01:00
|
|
|
(import (bjosodium raw))
|
2026-11-21 21:07:27 +01:00
|
|
|
|
|
|
|
|
(def/bench "encrypt AEGIS-256"
|
|
|
|
|
#:group "aead"
|
|
|
|
|
#:params ((bytes [1024 1048576]))
|
2026-11-22 08:13:50 +01:00
|
|
|
#:setup ((key (make-aead-key))
|
2026-11-21 21:07:27 +01:00
|
|
|
(nonce (make-aead-nonce Aegis256))
|
|
|
|
|
(message (: (make-array bytes) (Array byte))))
|
2026-11-22 08:13:50 +01:00
|
|
|
(aead-encrypt key nonce message))
|
2026-11-21 21:07:27 +01:00
|
|
|
|
|
|
|
|
(def/bench "encrypt XChaCha20-Poly1305"
|
|
|
|
|
#:group "aead"
|
|
|
|
|
#:params ((bytes [1024 1048576]))
|
2026-11-22 08:13:50 +01:00
|
|
|
#:setup ((key (make-aead-key))
|
2026-11-21 21:07:27 +01:00
|
|
|
(nonce (make-aead-nonce XChaCha20Poly1305))
|
|
|
|
|
(message (: (make-array bytes) (Array byte))))
|
2026-11-22 08:13:50 +01:00
|
|
|
(aead-encrypt key nonce message))
|
2026-11-21 21:07:27 +01:00
|
|
|
|
|
|
|
|
(def/bench "decrypt AEGIS-256"
|
|
|
|
|
#:group "aead"
|
|
|
|
|
#:params ((bytes [1024 1048576]))
|
2026-11-22 08:13:50 +01:00
|
|
|
#:setup ((key (make-aead-key))
|
2026-11-21 21:07:27 +01:00
|
|
|
(nonce (make-aead-nonce Aegis256))
|
2026-11-22 08:13:50 +01:00
|
|
|
(boxed (aead-encrypt key nonce (: (make-array bytes) (Array byte)))))
|
|
|
|
|
(aead-decrypt key nonce boxed))
|
2026-11-21 21:07:27 +01:00
|
|
|
|
|
|
|
|
(def/bench "decrypt XChaCha20-Poly1305"
|
|
|
|
|
#:group "aead"
|
|
|
|
|
#:params ((bytes [1024 1048576]))
|
2026-11-22 08:13:50 +01:00
|
|
|
#:setup ((key (make-aead-key))
|
2026-11-21 21:07:27 +01:00
|
|
|
(nonce (make-aead-nonce XChaCha20Poly1305))
|
2026-11-22 08:13:50 +01:00
|
|
|
(boxed (aead-encrypt key nonce (: (make-array bytes) (Array byte)))))
|
|
|
|
|
(aead-decrypt key nonce boxed))
|
2026-11-21 21:07:27 +01:00
|
|
|
|
2026-11-22 08:13:50 +01:00
|
|
|
;; libsodium's INTERACTIVE and MODERATE costs.
|
2026-11-21 21:07:27 +01:00
|
|
|
(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)))
|
2026-11-22 08:13:50 +01:00
|
|
|
(c (if (= cost "t=2 m=64MiB") argon2id-interactive argon2id-moderate)))
|
|
|
|
|
(argon2id-derive-key "correct horse battery staple" salt c))
|
2026-11-21 21:07:27 +01:00
|
|
|
|
|
|
|
|
(run-benches)
|