| 1 |
;;; GnuTLS --- Guile bindings for GnuTLS |
| 2 |
;;; Copyright (C) 2024-2025 Free Software Foundation, Inc. |
| 3 |
;;; |
| 4 |
;;; This file is part of Guile-GnuTLS. |
| 5 |
;;; |
| 6 |
;;; This program is free software: you can redistribute it and/or modify |
| 7 |
;;; it under the terms of the GNU General Public License as published by |
| 8 |
;;; the Free Software Foundation, either version 3 of the License, or |
| 9 |
;;; (at your option) any later version. |
| 10 |
;;; |
| 11 |
;;; This program is distributed in the hope that it will be useful, |
| 12 |
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
;;; GNU General Public License for more details. |
| 15 |
;;; |
| 16 |
;;; You should have received a copy of the GNU General Public License |
| 17 |
;;; along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
;; Check that EdDSA curves do not have a Y parameter. |
| 20 |
|
| 21 |
(use-modules (gnutls) |
| 22 |
(gnutls build tests) |
| 23 |
(ice-9 match) |
| 24 |
(ice-9 receive)) |
| 25 |
|
| 26 |
(run-test |
| 27 |
(lambda () |
| 28 |
;; Create an EdDSA key pair. Export its public key and import it |
| 29 |
;; back. Export its private key and import it back. They should have the |
| 30 |
;; same x parameter. |
| 31 |
(let ((key-pair (generate-private-key pk-algorithm/eddsa-ed25519 ecc-curve/ed25519))) |
| 32 |
(receive (public-crv public-x public-y) |
| 33 |
(public-key-export-raw-ecc (private-key->public-key key-pair '())) |
| 34 |
(receive (private-crv private-x private-y private-k) |
| 35 |
(private-key-export-raw-ecc key-pair) |
| 36 |
(unless (and (not public-y) (not private-y)) |
| 37 |
(error "the y component cannot be exported for ed25519 curves")) |
| 38 |
(unless (and (equal? (ecc-curve->oid public-crv) |
| 39 |
(ecc-curve->oid ecc-curve/ed25519)) |
| 40 |
(equal? (ecc-curve->oid private-crv) |
| 41 |
(ecc-curve->oid ecc-curve/ed25519))) |
| 42 |
(error "incorrect curve name")) |
| 43 |
(unless (equal? public-x private-x) |
| 44 |
(error "inconsistent public key")) |
| 45 |
(receive (reimported-public-key reimported-private-key) |
| 46 |
(values |
| 47 |
(import-raw-ecc-public-key ecc-curve/ed25519 |
| 48 |
public-x |
| 49 |
#f) |
| 50 |
(import-raw-ecc-private-key ecc-curve/ed25519 |
| 51 |
private-x |
| 52 |
#f |
| 53 |
private-k)) |
| 54 |
(receive (re-public-crv re-public-x re-public-y) |
| 55 |
(public-key-export-raw-ecc reimported-public-key) |
| 56 |
(receive (re-private-crv re-private-x re-private-y re-private-k) |
| 57 |
(private-key-export-raw-ecc reimported-private-key) |
| 58 |
(unless (and (not re-public-y) (not re-private-y)) |
| 59 |
(error "the y component cannot be re-exported for ed25519 curves")) |
| 60 |
(unless (and (equal? (ecc-curve->oid re-public-crv) |
| 61 |
(ecc-curve->oid ecc-curve/ed25519)) |
| 62 |
(equal? (ecc-curve->oid re-private-crv) |
| 63 |
(ecc-curve->oid ecc-curve/ed25519))) |
| 64 |
(error "incorrect curve name")) |
| 65 |
(unless (equal? re-public-x re-private-x) |
| 66 |
(error "inconsistent reimported public key")) |
| 67 |
(unless (equal? re-public-x public-x) |
| 68 |
(error "export/import failed")))))))))) |