summaryrefslogtreecommitdiff
path: root/dynamic
diff options
context:
space:
mode:
Diffstat (limited to 'dynamic')
-rw-r--r--dynamic/captcha.scm13
1 files changed, 9 insertions, 4 deletions
diff --git a/dynamic/captcha.scm b/dynamic/captcha.scm
index 99aa0cd..b095ebf 100644
--- a/dynamic/captcha.scm
+++ b/dynamic/captcha.scm
@@ -16,7 +16,7 @@
(define-module (captcha)
#:use-module (base64)
- #:use-module (hashing sha-2)
+ #:use-module (gcrypt hash)
#:use-module (gcrypt mac)
#:use-module (gcrypt random)
#:use-module (ice-9 binary-ports)
@@ -155,10 +155,15 @@
(define (check-proof-of-work prefix
challenge challenge-signature
expiry-timestamp timestamp-signature)
+ (define hash-value
+ (chain (list prefix challenge)
+ (string-concatenate _)
+ (string->bytevector _ "utf8")
+ (bytevector-hash _ (lookup-hash-algorithm 'sha256))
+ (bytevector->base16-string _)))
+ (define zero-prefix (string-join (map (lambda (_) "0") (iota %hardness)) ""))
(and (= 32 (string-length prefix))
- (string-prefix?
- (string-join (map (lambda (_) "0") (iota %hardness)) "")
- (sha-256->string (sha-256 (string->bytevector (string-concatenate (list prefix challenge)) "utf8"))))
+ (string-prefix? zero-prefix hash-value)
(valid-base64-signature? %pow-mac-key challenge challenge-signature)
(valid-base64-signature? %pow-mac-key expiry-timestamp timestamp-signature)
(time<=? (current-time)