blob: b5a932e8304cf82e0565b3b27bc60368a7010c63 [file] [log] [blame]
fbrosson533407a2018-04-04 21:44:29 +00001#!/usr/bin/env perl
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +02002
3# depends-pkalgs.pl
4#
Bence Szépkútia2947ac2020-08-19 16:37:36 +02005# Copyright The Mbed TLS Contributors
Bence Szépkútif744bd72020-06-05 13:02:18 +02006# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7#
8# This file is provided under the Apache License 2.0, or the
9# GNU General Public License v2.0 or later.
10#
11# **********
12# Apache License 2.0:
Bence Szépkúti51b41d52020-05-26 01:54:15 +020013#
14# Licensed under the Apache License, Version 2.0 (the "License"); you may
15# not use this file except in compliance with the License.
16# You may obtain a copy of the License at
17#
18# http://www.apache.org/licenses/LICENSE-2.0
19#
20# Unless required by applicable law or agreed to in writing, software
21# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23# See the License for the specific language governing permissions and
24# limitations under the License.
25#
Bence Szépkútif744bd72020-06-05 13:02:18 +020026# **********
27#
28# **********
29# GNU General Public License v2.0 or later:
30#
31# This program is free software; you can redistribute it and/or modify
32# it under the terms of the GNU General Public License as published by
33# the Free Software Foundation; either version 2 of the License, or
34# (at your option) any later version.
35#
36# This program is distributed in the hope that it will be useful,
37# but WITHOUT ANY WARRANTY; without even the implied warranty of
38# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39# GNU General Public License for more details.
40#
41# You should have received a copy of the GNU General Public License along
42# with this program; if not, write to the Free Software Foundation, Inc.,
43# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
44#
45# **********
46#
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020047# Purpose
48#
Manuel Pégourié-Gonnard562df402017-08-08 18:09:14 +020049# To test the code dependencies on individual PK algs (those that can be used
50# from the PK layer, so currently signature and encryption but not key
51# exchange) in each test suite. This is a verification step to ensure we don't
52# ship test suites that do not work for some build options.
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020053#
54# The process is:
55# for each possible PK alg
56# build the library and test suites with that alg disabled
57# execute the test suites
58#
59# And any test suite with the wrong dependencies will fail.
60#
61# Usage: tests/scripts/depends-pkalgs.pl
62#
63# This script should be executed from the root of the project directory.
64#
65# For best effect, run either with cmake disabled, or cmake enabled in a mode
66# that includes -Werror.
67
68use warnings;
69use strict;
70
71-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
72
73my $config_h = 'include/mbedtls/config.h';
74
Manuel Pégourié-Gonnard562df402017-08-08 18:09:14 +020075# Some algorithms can't be disabled on their own as others depend on them, so
76# we list those reverse-dependencies here to keep check_config.h happy.
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020077my %algs = (
Gert van Dijk25d124d2017-09-05 14:25:52 +020078 'MBEDTLS_ECDSA_C' => ['MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED'],
79 'MBEDTLS_ECP_C' => ['MBEDTLS_ECDSA_C',
80 'MBEDTLS_ECDH_C',
81 'MBEDTLS_ECJPAKE_C',
82 'MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED',
83 'MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED',
84 'MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED',
85 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
86 'MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED'],
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020087 'MBEDTLS_X509_RSASSA_PSS_SUPPORT' => [],
88 'MBEDTLS_PKCS1_V21' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT'],
Gert van Dijk25d124d2017-09-05 14:25:52 +020089 'MBEDTLS_PKCS1_V15' => ['MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED',
90 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
91 'MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED',
92 'MBEDTLS_KEY_EXCHANGE_RSA_ENABLED'],
93 'MBEDTLS_RSA_C' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT',
94 'MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED',
95 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
96 'MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED',
97 'MBEDTLS_KEY_EXCHANGE_RSA_ENABLED'],
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020098);
99
100system( "cp $config_h $config_h.bak" ) and die;
101sub abort {
102 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +0200103 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +0200104 warn $_[0];
105 exit 1;
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +0200106}
107
108while( my ($alg, $extras) = each %algs ) {
109 system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
110 system( "make clean" ) and die;
111
112 print "\n******************************************\n";
113 print "* Testing without alg: $alg\n";
114 print "******************************************\n";
115
116 system( "scripts/config.pl unset $alg" )
117 and abort "Failed to disable $alg\n";
118 for my $opt (@$extras) {
119 system( "scripts/config.pl unset $opt" )
120 and abort "Failed to disable $opt\n";
121 }
122
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +0200123 system( "CFLAGS='-Werror -Wall -Wextra' make lib" )
124 and abort "Failed to build lib: $alg\n";
125 system( "cd tests && make" ) and abort "Failed to build tests: $alg\n";
126 system( "make test" ) and abort "Failed test suite: $alg\n";
127}
128
129system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
130system( "make clean" ) and die;
131exit 0;