[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet-scheme] 34/49: crypto: Implement functional variants.
From: |
gnunet |
Subject: |
[gnunet-scheme] 34/49: crypto: Implement functional variants. |
Date: |
Sat, 25 Dec 2021 23:00:11 +0100 |
This is an automated email from the git hooks/post-receive script.
maxime-devos pushed a commit to branch master
in repository gnunet-scheme.
commit d68778f10a817e69d078dbb0bbf9e3e049a31164
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Sat Oct 2 23:58:57 2021 +0200
crypto: Implement functional variants.
* gnu/gnunet/crypto.scm: Add the file to git.
* gnu/gnunet/crypto.scm
(hasher,hash-slice/bytevector,hash-slice,hash/sha512): New
procedures.
(hash-slice!): Use hash-slice/bytevector.
* doc/scheme-gnunet.tm: Document hash/sha512.
---
doc/scheme-gnunet.tm | 7 ++++++
gnu/gnunet/crypto.scm | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+)
diff --git a/doc/scheme-gnunet.tm b/doc/scheme-gnunet.tm
index 25f4216..f388f79 100644
--- a/doc/scheme-gnunet.tm
+++ b/doc/scheme-gnunet.tm
@@ -1062,6 +1062,13 @@
slice of length 512 bits / 64 bytes.<space|1em>The result is unspecified if
<var|slice> and <var|to> overlap.>
+ <\explain>
+ <scm|(hash/sha512 <var|slice>)>
+ <|explain>
+ Like <scm|hash/sha512!>, but allocate the <var|>destination slice
+ <var|to> and return it.
+ </explain>
+
<chapter|Implementation details>
TODO<appendix|GNU Free Documentation License>
diff --git a/gnu/gnunet/crypto.scm b/gnu/gnunet/crypto.scm
new file mode 100644
index 0000000..c824faf
--- /dev/null
+++ b/gnu/gnunet/crypto.scm
@@ -0,0 +1,68 @@
+;; This file is part of GNUnet
+;; Copyright (C) 2021 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
+;; by the Free Software Foundation, either version 3 of the License,
+;; or (at your option) any later version.
+;;
+;; GNUnet is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; Affero General Public License for more details.
+;;
+;; You should have received a copy of the GNU Affero General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+;;
+;; SPDX-License-Identifier: AGPL-3.0-or-later
+
+;; Small wrapper around guile-gcrypt
+(define-library (gnu gnunet crypto)
+ (export hash/sha512 hash/sha512!)
+ (import (only (gcrypt hash)
+ hash-algorithm open-hash-port sha512)
+ (gnu gnunet utils bv-slice)
+ (only (srfi srfi-8)
+ receive)
+ (only (guile)
+ %make-void-port close-port)
+ (only (ice-9 binary-ports)
+ put-bytevector)
+ (only (rnrs base)
+ begin lambda define))
+ (begin
+ ;; TODO: Extend bytevector-hash with offset + length.
+ (define (hash-slice/bytevector algorithm slice)
+ "Hash the data in the readable bytevector slice @var{slice} and
+return a bytevector with the resulting hash."
+ (define slice/read (slice/read-only slice))
+ (receive (port get-hash) (open-hash-port algorithm)
+ (put-bytevector port
+ (slice-bv slice/read)
+ (slice-offset slice/read)
+ (slice-length slice/read))
+ (close-port port)
+ (get-hash)))
+
+ (define (hash-slice! algorithm slice to)
+ "Hash the data in the readable bytevector slice @var{slice} and write the
+hash to the bytevector slice @var{to}."
+ (slice-copy! (hash-slice/bytevector algorithm slice) to))
+
+ (define (hash-slice algorithm slice)
+ "Hash the data in the readable bytevector slice @var{slice} and return a
+fresh readable bytevector slice with the hash."
+ (slice/read-only
+ (bv-slice/read-write (hash-slice/bytevector algorithm slice))))
+
+ (define (hasher! algorithm)
+ (lambda (slice to)
+ (hash-slice! algorithm slice to)))
+
+ (define (hasher algorithm)
+ (lambda (slice)
+ (hash-slice algorithm slice)))
+
+ ;; (hash/sha512! data-to-hash-slice destination-slice) --> (nothing)
+ (define hash/sha512! (hasher! (hash-algorithm sha512)))
+ (define hash/sha512 (hasher (hash-algorithm sha512)))))
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet-scheme] 24/49: examples/web: Put different information on separate pages., (continued)
- [gnunet-scheme] 24/49: examples/web: Put different information on separate pages., gnunet, 2021/12/25
- [gnunet-scheme] 20/49: dht/client: Call the callback on the client result., gnunet, 2021/12/25
- [gnunet-scheme] 17/49: dht/struct: Fix typo in synopsis., gnunet, 2021/12/25
- [gnunet-scheme] 14/49: Merge branch 'master' into dht, gnunet, 2021/12/25
- [gnunet-scheme] 22/49: examples/web: Make a non-functional web form for searching the DHT., gnunet, 2021/12/25
- [gnunet-scheme] 27/49: examples/web: Process DHT insertion forms., gnunet, 2021/12/25
- [gnunet-scheme] 40/49: examples/web: Don't hash the data., gnunet, 2021/12/25
- [gnunet-scheme] 35/49: examples/web: Allow module reloading., gnunet, 2021/12/25
- [gnunet-scheme] 23/49: examles/web: Add a non-functional form for DHT insertions., gnunet, 2021/12/25
- [gnunet-scheme] 15/49: Update copyright notices, gnunet, 2021/12/25
- [gnunet-scheme] 34/49: crypto: Implement functional variants.,
gnunet <=
- [gnunet-scheme] 33/49: examples/web: Hash free-form text first., gnunet, 2021/12/25
- [gnunet-scheme] 46/49: Merge branch 'dht'., gnunet, 2021/12/25
- [gnunet-scheme] 11/49: config: Define default UNIXPATH for DHT service., gnunet, 2021/12/25
- [gnunet-scheme] 16/49: Merge branch 'master' into dht, gnunet, 2021/12/25
- [gnunet-scheme] 19/49: dht/client: Recognise client result messages., gnunet, 2021/12/25
- [gnunet-scheme] 38/49: examples/web: Implement searching form., gnunet, 2021/12/25
- [gnunet-scheme] 43/49: examples/web: Display UTF-8 keys and data as text., gnunet, 2021/12/25
- [gnunet-scheme] 32/49: crypto: Implement a wrapper for hashing with bytevector slices., gnunet, 2021/12/25
- [gnunet-scheme] 47/49: web: Extract HTTP implementation from Cuirass., gnunet, 2021/12/25
- [gnunet-scheme] 45/49: guix: Skip tests in guile-fibers/patched., gnunet, 2021/12/25