Debian Codegraph @

guile/tests/list-sign-algorithms.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 signature algorithm inventory
20
21 (use-modules (gnutls)
22 (gnutls build tests))
23
24 (run-test
25 (lambda ()
26 (when (sign-algorithm-is-secure? sign-algorithm/rsa-md2 #t)
27 (error "Jump ship!"))
28 (unless (sign-algorithm-is-secure? sign-algorithm/ecdsa-secp256r1-sha256 #f)
29 (error "Are quantum computers a thing now?"))
30 (unless (equal? (sign-algorithm->digest-algorithm sign-algorithm/ecdsa-secp256r1-sha256)
31 digest/sha256)
32 (error "The ecdsa-sha256 signature algorithm should use \
33 the sha256 hash algorithm"))
34 (let ((all-algorithms (sign-algorithm-list)))
35 (for-each
36 (lambda (algo)
37 (unless algo
38 (error "gnutls lists more sign-algorithms than what gnutls-guile enumerates.")))
39 all-algorithms)
40 (unless (member (sign-algorithm->string
41 sign-algorithm/ecdsa-secp256r1-sha256)
42 (map (lambda (alg)
43 (and alg
44 (sign-algorithm->string alg)))
45 all-algorithms))
46 (error "Not enough listed sign algorithms"))
47 (for-each
48 (lambda (algo)
49 (let* ((name (and algo (sign-algorithm->string algo)))
50 (same-algo (and name (string->sign-algorithm name)))
51 (same-name (and same-algo (sign-algorithm->string same-algo))))
52 (unless (and (equal? algo same-algo)
53 (equal? name same-name))
54 (error "Inconsistent sign algorithm name")))
55 (let* ((oid (and algo (sign-algorithm->oid algo)))
56 (same-algo (and oid (oid->sign-algorithm oid)))
57 (same-oid (and same-algo (sign-algorithm->oid same-algo))))
58 (when (and oid
59 (not (equal? algo sign-algorithm/rsa-pss-rsae-sha256))
60 (not (equal? algo sign-algorithm/rsa-pss-sha384))
61 (not (equal? algo sign-algorithm/rsa-pss-rsae-sha384))
62 (not (equal? algo sign-algorithm/rsa-pss-sha512))
63 (not (equal? algo sign-algorithm/rsa-pss-rsae-sha512)))
64 (unless (and (equal? algo same-algo)
65 (equal? oid same-oid))
66 (error "Inconsistent sign algorithm oid")))))
67 all-algorithms))))