]> gitweb.factorcode.org Git - factor.git/commitdiff
sodium: prepare some code for reuse
authorAlexander Iljin <ajsoft@yandex.ru>
Sun, 23 Dec 2018 23:50:20 +0000 (00:50 +0100)
committerAlexander Iljin <ajsoft@yandex.ru>
Sun, 23 Dec 2018 23:51:08 +0000 (00:51 +0100)
extra/sodium/sodium.factor

index 08df893324fd0a9049d09570841000a0a1a4bb86..95c68f69c4a298ab75b90836768dbc815b481e90 100644 (file)
@@ -14,10 +14,17 @@ ERROR: buffer-too-small ;
 <PRIVATE
 
 : cipher-buf ( message-length n -- byte-array )
-    crypto_secretbox_macbytes + <byte-array> ;
+    + <byte-array> ;
 
 : message-buf ( cipher-length n -- byte-array )
-    crypto_secretbox_macbytes - <byte-array> ;
+    - <byte-array> ;
+
+: 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*