[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/04: openpgp: Use Libgcrypt's crc24 implementation.
From: |
guix-commits |
Subject: |
02/04: openpgp: Use Libgcrypt's crc24 implementation. |
Date: |
Tue, 23 Jun 2020 18:04:53 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit 6f233040d34706879a9ac490668a7132be4f1e13
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Tue Jun 23 18:11:35 2020 +0200
openpgp: Use Libgcrypt's crc24 implementation.
This gives an 18% speedup on the wall-clock time of:
guile -c '(use-modules (git) (guix git-authenticate))
(load-keyring-from-reference (repository-open ".") "keyring")'
* guix/openpgp.scm (crc24): Rewrite by calling out to 'bytevector-hash'.
---
guix/openpgp.scm | 21 ++++-----------------
1 file changed, 4 insertions(+), 17 deletions(-)
diff --git a/guix/openpgp.scm b/guix/openpgp.scm
index b74f8ff..33c8512 100644
--- a/guix/openpgp.scm
+++ b/guix/openpgp.scm
@@ -1029,23 +1029,10 @@ there is no limit."
(define (crc24 bv)
"Compute a CRC24 as described in RFC4880, Section 6.1."
- (define poly #x1864cfb)
-
- (let loop ((crc #xb704ce)
- (index 0))
- (if (= index (bytevector-length bv))
- (logand crc #xffffff)
- (let ((crc (logxor (ash (bytevector-u8-ref bv index) 16)
- crc)))
- (let inner ((i 0)
- (crc crc))
- (if (< i 8)
- (let ((crc (ash crc 1)))
- (inner (+ i 1)
- (if (zero? (logand crc #x1000000))
- crc
- (logxor crc poly))))
- (loop crc (+ index 1))))))))
+ ;; We used to have it implemented in Scheme but the C version here makes
+ ;; 'load-keyring-from-reference' 18% faster when loading the 72
+ ;; ASCII-armored files of today's Guix keyring.
+ (bytevector->uint (bytevector-hash bv (hash-algorithm crc24-rfc2440))))
(define %begin-block-prefix "-----BEGIN ")
(define %begin-block-suffix "-----")