blob: 6eb726927e7e7e027e27d465ac3cec2d2948a030 [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úti1e148272020-08-07 13:07:28 +02005# Copyright The Mbed TLS Contributors
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02006# SPDX-License-Identifier: Apache-2.0
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19#
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020020# Purpose
21#
Manuel Pégourié-Gonnard562df402017-08-08 18:09:14 +020022# To test the code dependencies on individual PK algs (those that can be used
23# from the PK layer, so currently signature and encryption but not key
24# exchange) in each test suite. This is a verification step to ensure we don't
25# ship test suites that do not work for some build options.
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020026#
27# The process is:
28# for each possible PK alg
29# build the library and test suites with that alg disabled
30# execute the test suites
31#
32# And any test suite with the wrong dependencies will fail.
33#
34# Usage: tests/scripts/depends-pkalgs.pl
35#
36# This script should be executed from the root of the project directory.
37#
38# For best effect, run either with cmake disabled, or cmake enabled in a mode
39# that includes -Werror.
40
41use warnings;
42use strict;
43
44-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
45
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +020046my $config_h = 'include/mbedtls/mbedtls_config.h';
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020047
Manuel Pégourié-Gonnard562df402017-08-08 18:09:14 +020048# Some algorithms can't be disabled on their own as others depend on them, so
49# we list those reverse-dependencies here to keep check_config.h happy.
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020050my %algs = (
Gilles Peskine7ab66a62018-09-14 17:47:41 +020051 'MBEDTLS_ECDSA_C' => ['MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED',
52 'MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED'],
Gert van Dijk25d124d2017-09-05 14:25:52 +020053 'MBEDTLS_ECP_C' => ['MBEDTLS_ECDSA_C',
54 'MBEDTLS_ECDH_C',
55 'MBEDTLS_ECJPAKE_C',
56 'MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED',
57 'MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED',
58 'MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED',
59 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
60 'MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED'],
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020061 'MBEDTLS_X509_RSASSA_PSS_SUPPORT' => [],
62 'MBEDTLS_PKCS1_V21' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT'],
Gert van Dijk25d124d2017-09-05 14:25:52 +020063 'MBEDTLS_PKCS1_V15' => ['MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED',
64 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
65 'MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED',
66 'MBEDTLS_KEY_EXCHANGE_RSA_ENABLED'],
67 'MBEDTLS_RSA_C' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT',
68 'MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED',
69 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
Gilles Peskine7ab66a62018-09-14 17:47:41 +020070 'MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED',
Gert van Dijk25d124d2017-09-05 14:25:52 +020071 'MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED',
72 'MBEDTLS_KEY_EXCHANGE_RSA_ENABLED'],
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020073);
74
75system( "cp $config_h $config_h.bak" ) and die;
76sub abort {
77 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020078 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020079 warn $_[0];
80 exit 1;
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020081}
82
83while( my ($alg, $extras) = each %algs ) {
84 system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
85 system( "make clean" ) and die;
86
87 print "\n******************************************\n";
88 print "* Testing without alg: $alg\n";
89 print "******************************************\n";
Gilles Peskine9004a172019-09-16 15:20:36 +020090 $ENV{MBEDTLS_TEST_CONFIGURATION} = "-$alg";
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020091
Gilles Peskine5d46f6a2019-07-27 23:52:53 +020092 system( "scripts/config.py unset $alg" )
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020093 and abort "Failed to disable $alg\n";
94 for my $opt (@$extras) {
Gilles Peskine5d46f6a2019-07-27 23:52:53 +020095 system( "scripts/config.py unset $opt" )
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020096 and abort "Failed to disable $opt\n";
97 }
98
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020099 system( "CFLAGS='-Werror -Wall -Wextra' make lib" )
100 and abort "Failed to build lib: $alg\n";
101 system( "cd tests && make" ) and abort "Failed to build tests: $alg\n";
102 system( "make test" ) and abort "Failed test suite: $alg\n";
103}
104
105system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
106system( "make clean" ) and die;
107exit 0;