gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet-scheme] branch master updated (36ad841 -> 11cda5c)


From: gnunet
Subject: [gnunet-scheme] branch master updated (36ad841 -> 11cda5c)
Date: Mon, 15 Aug 2022 15:57:38 +0200

This is an automated email from the git hooks/post-receive script.

maxime-devos pushed a change to branch master
in repository gnunet-scheme.

    from 36ad841  cadet/client: Unstub verification of 
msg:cadet:local:acknowledgement.
     new 2566208  crypto: Modernise typography.
     new b1e4d37  crypto/struct: Correct public key sizes.
     new 11cda5c  crypto: Define procedures for decoding Crockford 
Base32-encoded public keys.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 doc/scheme-gnunet.tm         |  9 +++++++
 gnu/gnunet/crypto.scm        | 63 +++++++++++++++++++++++++++++++++++++++-----
 gnu/gnunet/crypto/struct.scm |  4 +--
 tests/crypto.scm             | 21 ++++++++++++++-
 4 files changed, 88 insertions(+), 9 deletions(-)

diff --git a/doc/scheme-gnunet.tm b/doc/scheme-gnunet.tm
index e0e0491..2359858 100644
--- a/doc/scheme-gnunet.tm
+++ b/doc/scheme-gnunet.tm
@@ -260,6 +260,15 @@
     <var|to> and return it.
   </explain>
 
+  It also has a procedure 
<scm|string-\<gtr\>eddsa-public-key><index|string-\<gtr\>eddsa-public-key>
+  and 
<scm|string-\<gtr\>ecdsa-public-key><index|string-\<gtr\>ecdsa-public-key>.
+  They respectively accept a Crockford Base32-encoded EdDSA and ECDSA public
+  key as a string and return the decoded key as a fresh bytevector. In case
+  the string has an incorrect length or characters, a
+  <scm|&invalid-public-key-encoding><index|&invalid-public-key-encoding>
+  condition is raised, which can be tested for with the predicate
+  <scm|invalid-public-key-encoding?><index|invalid-public-key-encoding?>.
+
   The module <scm|(gnu gnunet data-string)><index|(gnu gnunet data-string)>
   has two procedures <scm|data-\<gtr\>string><index|data-\<gtr\>string> and
   <scm|string-\<gtr\>data><index|string-\<gtr\>data>, for representing binary
diff --git a/gnu/gnunet/crypto.scm b/gnu/gnunet/crypto.scm
index eb86c47..df6af3b 100644
--- a/gnu/gnunet/crypto.scm
+++ b/gnu/gnunet/crypto.scm
@@ -1,5 +1,5 @@
 ;; This file is part of GNUnet
-;; Copyright (C) 2021 GNUnet e.V.
+;; Copyright © 2021, 2022 GNUnet e.V.
 ;;
 ;; GNUnet is free software: you can redistribute it and/or modify it
 ;; under the terms of the GNU Affero General Public License as published
@@ -16,20 +16,36 @@
 ;;
 ;; SPDX-License-Identifier: AGPL-3.0-or-later
 
-;; Small wrapper around guile-gcrypt
+;; Small wrapper around guile-gcrypt and other related procedures.
 (define-library (gnu gnunet crypto)
-  (export hash/sha512 hash/sha512!)
+  (export hash/sha512 hash/sha512!
+         &invalid-public-key-encoding
+         invalid-public-key-encoding?
+         string->eddsa-public-key
+         string->ecdsa-public-key)
   (import (only (gcrypt hash)
                hash-algorithm open-hash-port sha512)
          (gnu gnunet utils bv-slice)
+         (only (gnu gnunet crypto struct)
+               /eddsa-public-key /ecdsa-public-key)
+         (only (gnu gnunet data-string)
+               string->data)
+         (only (gnu gnunet netstruct syntactic)
+               sizeof)
+         (only (gnu gnunet utils hat-let)
+               let^)
          (only (srfi srfi-8)
                receive)
          (only (guile)
-               %make-void-port close-port)
+               %make-void-port close-port ceiling-quotient)
          (only (ice-9 binary-ports)
                put-bytevector)
          (only (rnrs base)
-               begin lambda define))
+               begin lambda define quote * not = string-length or)
+         (only (rnrs conditions)
+               define-condition-type &violation)
+         (only (rnrs exceptions)
+               raise))
   (begin
     ;; TODO: Extend bytevector-hash with offset + length.
     (define (hash-slice/bytevector algorithm slice)
@@ -66,4 +82,39 @@ fresh readable bytevector slice with the hash."
 
     ;; (hash/sha512! data-to-hash-slice destination-slice) --> (nothing)
     (define hash/sha512! (hasher! (hash-algorithm sha512)))
-    (define hash/sha512 (hasher (hash-algorithm sha512)))))
+    (define hash/sha512 (hasher (hash-algorithm sha512)))
+
+    
+    ;; TODO: &who, how to decide between supertypes, maybe some
+    ;; more specific subtypes and some fields
+    (define-condition-type &invalid-public-key-encoding &violation
+      make-invalid-public-key-encoding invalid-public-key-encoding?)
+
+    (define (raise-invalid-public-key-encoding)
+      (raise (make-invalid-public-key-encoding)))
+
+    ;; See next two procedures.
+    (define (string->something-public-key key-length/bytes string)
+      (let^ ((! key-length/bits (* 8 key-length/bytes))
+            (! key-length/characters (ceiling-quotient key-length/bits 5))
+            (? (not (= key-length/characters (string-length string)))
+               (raise-invalid-public-key-encoding)))
+           (or (string->data string key-length/bytes)
+               (raise-invalid-public-key-encoding))))
+
+    ;; TODO: find some test cases
+    (define (string->eddsa-public-key string)
+      "Decode the Crockford Base32-encoded EdDSA public key @var{string} from 
a string
+into a fresh bytevector.  In case of a decoding error (unexpected characters
+or wrong length), an @code{&invalid-public-key-encoding} is raised.
+
+This corresponds to @code{GNUNET_CRYPTO_ecdsa_public_key_from_string} in the C 
API."
+      (string->something-public-key (sizeof /eddsa-public-key '()) string))
+
+    (define (string->ecdsa-public-key string)
+      "Decode the Crockford Base32-encoded ECDSA public key @var{string} from 
a string
+into a fresh bytevector.  In case of a decoding error (unexpected characters
+or wrong length), an @code{&invalid-public-key-encoding} is raised.
+
+This corresponds to @code{GNUNET_CRYPTO_ecdsa_public_key_from_string} in the C 
API."
+      (string->something-public-key (sizeof /ecdsa-public-key '()) string))))
diff --git a/gnu/gnunet/crypto/struct.scm b/gnu/gnunet/crypto/struct.scm
index ea1d2f8..a19b8b6 100644
--- a/gnu/gnunet/crypto/struct.scm
+++ b/gnu/gnunet/crypto/struct.scm
@@ -86,7 +86,7 @@ a format suitable for network transmission and EdDSA 
signatures.
 Refer to section 5.1.3 of rfc8032, for a thorough explanation of how this
 value maps to the x- and y-coordinates.")
        (properties '((c-type . GNUNET_CRYPTO_EddsaPublicKey)))
-       (field (q (u8vector 64))
+       (field (q (u8vector 32))
              (documentation "Point Q consists of a y-value mod p (256 bits);
 the x-value is always positive. The point is stored in Ed25519 standard
 compact format."))))
@@ -97,7 +97,7 @@ compact format."))))
        "Public ECC key (always for Curve25519) encoded in a format suitable
 for network transmission and ECDSA signatures.")
        (properties '((c-type . GNUNET_CRYPTO_EcdsaPublicKey)))
-       (field (q-y (u8vector 64))
+       (field (q-y (u8vector 32))
              (documentation
               "Q consists of an x- and a y-value, each mod p (256 bits), given
 here in affine coordinates and Ed25519 standard compact format."))))
diff --git a/tests/crypto.scm b/tests/crypto.scm
index bcc6723..26d6b5b 100644
--- a/tests/crypto.scm
+++ b/tests/crypto.scm
@@ -1,5 +1,5 @@
 ;; This file is part of scheme-GNUnet.
-;; Copyright (C) 2021 GNUnet e.V.
+;; Copyright © 2021, 2022 GNUnet e.V.
 ;;
 ;; scheme-GNUnet is free software: you can redistribute it and/or modify it
 ;; under the terms of the GNU Affero General Public License as published
@@ -26,6 +26,7 @@
        (only (rnrs bytevectors)
              make-bytevector string->utf8)
        (srfi srfi-64)
+       (rnrs exceptions)
        (only (srfi srfi-43)
              vector-every)
        (only (ice-9 match)
@@ -87,3 +88,21 @@
 (test-equal "size of /hashcode:512"
   512
   (* 8 (sizeof /hashcode:512 '())))
+
+;; TODO: the #vu8(...) was generated by running string->eddsa-public-key,
+;; it is not independently tested (TODO: test with examples/web.scm and
+;; local GNUnet peer).
+(test-equal "string->eddsa-public-key test case"
+           #vu8(57 243 205 186 142 192 173 103 132 59 211 78 51 218 234 21 213 
205 245 73 49 220 179 121 235 142 11 241 72 234 145 220)
+           (string->eddsa-public-key 
"77SWVEMER2PPF11VTD737PQA2QAWVXA967EB6YFBHR5Z2J7AJ7E0"))
+
+(test-assert "string->eddsa-public-key, overly short (invalid)"
+            (guard (c ((invalid-public-key-encoding? c) #true))
+                   (string->eddsa-public-key "")
+                   #false))
+
+(test-expect-fail 1) ; TODO
+(test-assert "string->eddsa-public-key, bogus character (invalid)"
+            (guard (c ((invalid-public-key-encoding? c) #true))
+                   (string->eddsa-public-key 
"@7SWVEMER2PPF11VTD737PQA2QAWVXA967EB6YFBHR5Z2J7AJ7E0")
+                   #false))

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]