]> gitweb.factorcode.org Git - factor.git/commitdiff
sodium: add wrapper words for working with detached signatures
authorAlexander Iljin <ajsoft@yandex.ru>
Sun, 14 Apr 2019 13:17:06 +0000 (15:17 +0200)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 14 Apr 2019 13:42:49 +0000 (08:42 -0500)
extra/sodium/sodium-tests.factor
extra/sodium/sodium.factor

index f0d3e38c3abda69b8645f0961444c58783347645..c2c3dfefa669209835c7e5abffeb9b1741b0a853 100644 (file)
@@ -10,3 +10,9 @@ IN: sodium.tests
     [ [ first ] [ second ] bi* crypto-box-easy ] 3keep swap
     [ first ] [ second ] bi* crypto-box-open-easy utf8 decode =
 ] unit-test
+
+{ t } [
+    "Signature verification test" utf8 encode
+    crypto-sign-keypair [ over ] dip crypto-sign
+    -rot crypto-sign-verify
+] unit-test
index 283e8085725ea4cc3069ea68645c26a2ff36ea77..18c6416ea92c605e35b05c7f25622459de211e14 100644 (file)
@@ -75,6 +75,18 @@ PRIVATE>
     crypto_box_secretkeybytes <byte-array>
     2dup crypto_box_keypair check0 ;
 
+: crypto-sign-keypair ( -- public-key secret-key )
+    crypto_sign_publickeybytes <byte-array>
+    crypto_sign_secretkeybytes <byte-array>
+    2dup crypto_sign_keypair check0 ;
+
+: crypto-sign ( message secret-key -- signature )
+    [ crypto_sign_bytes <byte-array> dup f ] 2dip
+    [ dup length ] dip crypto_sign_detached check0 ;
+
+: crypto-sign-verify ( signature message public-key -- ? )
+    [ dup length ] dip crypto_sign_verify_detached 0 = ;
+
 : crypto-box-nonce ( -- nonce-bytes )
     crypto_box_noncebytes n-random-bytes ;