From 0f573800746830011565853057f6c00dd49583c3 Mon Sep 17 00:00:00 2001 From: Alexander Iljin Date: Mon, 24 Dec 2018 00:50:20 +0100 Subject: [PATCH] sodium: prepare some code for reuse --- extra/sodium/sodium.factor | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/extra/sodium/sodium.factor b/extra/sodium/sodium.factor index 08df893324..95c68f69c4 100644 --- a/extra/sodium/sodium.factor +++ b/extra/sodium/sodium.factor @@ -14,10 +14,17 @@ ERROR: buffer-too-small ; ; + + ; : message-buf ( cipher-length n -- byte-array ) - crypto_secretbox_macbytes - ; + - ; + +: secretbox-cipher-buf ( message-length -- byte-array ) + crypto_secretbox_macbytes cipher-buf ; + +: secretbox-message-buf ( cipher-length -- byte-array ) + crypto_secretbox_macbytes message-buf ; + PRIVATE> @@ -44,7 +51,7 @@ PRIVATE> [ dup length ] dip < [ buffer-too-small ] when ; : crypto-secretbox-easy ( msg-bytes nonce-bytes key-bytes -- cipher-bytes ) - [ dup length [ cipher-buf swap dupd ] keep ] + [ dup length [ secretbox-cipher-buf swap dupd ] keep ] [ crypto_secretbox_noncebytes check-length ] [ crypto_secretbox_keybytes check-length ] tri* crypto_secretbox_easy check0 ; @@ -52,7 +59,7 @@ PRIVATE> : crypto-secretbox-open-easy ( cipher-bytes nonce-bytes key-bytes -- msg-bytes/f ) [ crypto_secretbox_macbytes check-length - dup length [ message-buf swap dupd ] keep + dup length [ secretbox-message-buf swap dupd ] keep ] [ crypto_secretbox_noncebytes check-length ] [ crypto_secretbox_keybytes check-length ] tri*