Debian Codegraph @

guile/tests/list-ecc-curves.scm

raw
1 ;;; GnuTLS --- Guile bindings for GnuTLS
2 ;;; Copyright (C) 2011-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 the ECC curve inventory
20
21 (use-modules (gnutls)
22 (gnutls build tests))
23
24 (run-test
25 (lambda ()
26 (unless (eqv? (ecc-curve-size ecc-curve/secp256r1) 32)
27 (error "Wrong ECC curve size"))
28 (unless (equal? (pk-algorithm->string (ecc-curve->pk-algorithm ecc-curve/secp256r1))
29 (pk-algorithm->string pk-algorithm/ecdsa))
30 (error "Wrong PK algorithm for curve"))
31 (let ((all-curves (ecc-curve-list)))
32 (unless (member (ecc-curve->string ecc-curve/secp256r1)
33 (map ecc-curve->string all-curves))
34 (error "Not enough listed ECC curves"))
35 (for-each
36 (lambda (curve)
37 (let* ((name (ecc-curve->string curve))
38 (same-curve (string->ecc-curve name))
39 (same-name (ecc-curve->string same-curve)))
40 (unless (and (equal? curve same-curve)
41 (equal? name same-name))
42 (error "Inconsistent sign algorithm name")))
43 (let* ((oid (ecc-curve->oid curve))
44 (same-curve (and oid (oid->ecc-curve oid)))
45 (same-oid (and same-curve (ecc-curve->oid same-curve))))
46 (when oid
47 (unless (and (equal? curve same-curve)
48 (equal? oid same-oid))
49 (error "Inconsistent sign algorithm oid")))))
50 all-curves))))