-
Notifications
You must be signed in to change notification settings - Fork 1
/
verification.rkt
34 lines (23 loc) · 948 Bytes
/
verification.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#lang racket/base
(require racket/match crypto crypto/libcrypto)
(require ec)
(define ec-impl (get-pk 'ec libcrypto-factory))
;; Step 1: Alice generates a keypair and publishes her public key.
;; Alice:
(define alice:privkey (generate-private-key ec-impl '((curve secp256k1))))
(define alice:pubkey-spki
(pk-key->datum alice:privkey 'SubjectPublicKeyInfo))
;; Step 2: Alice signs a message and publishes both message and signature.
;; Alice:
(define msg #"Hi, my name is Alice.")
(define sig (digest/sign alice:privkey 'sha256 msg))
;; Step 2: Bob obtains Alice's public key
;; Bob:
;;(define bob:alices-pubkey
;; (datum->pk-key alice:pubkey-spki 'SubjectPublicKeyInfo))
;; Step 3: Bob verifies Alice's message
;;(digest/verify bob:alices-pubkey 'sha256 msg sig)
(define alice:pubkey (pk-key->public-only-key alice:privkey))
(digest/verify alice:pubkey 'sha256 msg sig)
;; skip running tests for this module
(module test racket/base)