Browse Source
Racket Goblins used to send the the key and signature in a racket specific format across the wire, this worked well when it was just racket goblins <-> racket goblins. However now we need a less implementation specific approach to allow for other implementations. This now uses the sexp format which is native to gcrypt. It includes converters to and from these gcrypt sexps when sending and receiving on the wire in CapTP. Note: There are more changes to crypto to do, at the very least around handoffs.fix-gitlab-ci
2 changed files with 55 additions and 6 deletions
@ -0,0 +1,48 @@
|
||||
#lang racket |
||||
|
||||
;;; Copyright 2022 Jessica Tallon |
||||
;;; |
||||
;;; Licensed under the Apache License, Version 2.0 (the "License"); |
||||
;;; you may not use this file except in compliance with the License. |
||||
;;; You may obtain a copy of the License at |
||||
;;; |
||||
;;; http://www.apache.org/licenses/LICENSE-2.0 |
||||
;;; |
||||
;;; Unless required by applicable law or agreed to in writing, software |
||||
;;; distributed under the License is distributed on an "AS IS" BASIS, |
||||
;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
;;; See the License for the specific language governing permissions and |
||||
;;; limitations under the License. |
||||
|
||||
(provide racket->gcrypt/public-key |
||||
gcrypt->racket/public-key |
||||
|
||||
racket->gcrypt/signature |
||||
gcrypt->racket/signature) |
||||
|
||||
(require racket/match) |
||||
|
||||
(define (racket->gcrypt/public-key public-key) |
||||
(match public-key |
||||
[(list 'eddsa 'public 'ed25519 data) |
||||
`(public-key (ecc (curve Ed25519) (flags eddsa) (q ,data)))] |
||||
[_ (error "Don't know how to encode key: ~a" public-key)])) |
||||
|
||||
(define (gcrypt->racket/public-key public-key) |
||||
(match public-key |
||||
[`(public-key (ecc (curve Ed25519) (flags eddsa) (q ,data))) |
||||
`(eddsa public ed25519 ,data)])) |
||||
|
||||
(define (racket->gcrypt/signature signature) |
||||
(let ((r (subbytes signature 0 32)) |
||||
(s (subbytes signature 32))) |
||||
`(sig-val (eddsa (r ,r) (s ,s))))) |
||||
|
||||
(define (gcrypt->racket/signature signature) |
||||
(match signature |
||||
[`(sig-val (eddsa (r ,r) (s ,s))) |
||||
(bytes-append r |
||||
(make-bytes (- 32 (bytes-length r)) 0) |
||||
s |
||||
(make-bytes (- 32 (bytes-length s)) 0))] |
||||
[_ (error "No matching signature: ~a" signature)])) |
||||
Loading…
Reference in new issue