blob: 9adbb71582ff378bd33528c50f7b75597978c0e8 [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#
5# Copyright (c) 2017, ARM Limited, All Rights Reserved
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#
Bence Szépkúti51b41d52020-05-26 01:54:15 +020047# This file is part of Mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020048#
49# Purpose
50#
Manuel Pégourié-Gonnard562df402017-08-08 18:09:14 +020051# To test the code dependencies on individual PK algs (those that can be used
52# from the PK layer, so currently signature and encryption but not key
53# exchange) in each test suite. This is a verification step to ensure we don't
54# ship test suites that do not work for some build options.
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020055#
56# The process is:
57# for each possible PK alg
58# build the library and test suites with that alg disabled
59# execute the test suites
60#
61# And any test suite with the wrong dependencies will fail.
62#
63# Usage: tests/scripts/depends-pkalgs.pl
64#
65# This script should be executed from the root of the project directory.
66#
67# For best effect, run either with cmake disabled, or cmake enabled in a mode
68# that includes -Werror.
69
70use warnings;
71use strict;
72
73-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
74
75my $config_h = 'include/mbedtls/config.h';
76
Manuel Pégourié-Gonnard562df402017-08-08 18:09:14 +020077# Some algorithms can't be disabled on their own as others depend on them, so
78# we list those reverse-dependencies here to keep check_config.h happy.
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020079my %algs = (
Gert van Dijk25d124d2017-09-05 14:25:52 +020080 'MBEDTLS_ECDSA_C' => ['MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED'],
81 'MBEDTLS_ECP_C' => ['MBEDTLS_ECDSA_C',
82 'MBEDTLS_ECDH_C',
83 'MBEDTLS_ECJPAKE_C',
84 'MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED',
85 'MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED',
86 'MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED',
87 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
88 'MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED'],
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020089 'MBEDTLS_X509_RSASSA_PSS_SUPPORT' => [],
90 'MBEDTLS_PKCS1_V21' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT'],
Gert van Dijk25d124d2017-09-05 14:25:52 +020091 'MBEDTLS_PKCS1_V15' => ['MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED',
92 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
93 'MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED',
94 'MBEDTLS_KEY_EXCHANGE_RSA_ENABLED'],
95 'MBEDTLS_RSA_C' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT',
96 'MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED',
97 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
98 'MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED',
99 'MBEDTLS_KEY_EXCHANGE_RSA_ENABLED'],
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +0200100);
101
102system( "cp $config_h $config_h.bak" ) and die;
103sub abort {
104 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +0200105 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +0200106 warn $_[0];
107 exit 1;
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +0200108}
109
110while( my ($alg, $extras) = each %algs ) {
111 system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
112 system( "make clean" ) and die;
113
114 print "\n******************************************\n";
115 print "* Testing without alg: $alg\n";
116 print "******************************************\n";
117
118 system( "scripts/config.pl unset $alg" )
119 and abort "Failed to disable $alg\n";
120 for my $opt (@$extras) {
121 system( "scripts/config.pl unset $opt" )
122 and abort "Failed to disable $opt\n";
123 }
124
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +0200125 system( "CFLAGS='-Werror -Wall -Wextra' make lib" )
126 and abort "Failed to build lib: $alg\n";
127 system( "cd tests && make" ) and abort "Failed to build tests: $alg\n";
128 system( "make test" ) and abort "Failed test suite: $alg\n";
129}
130
131system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
132system( "make clean" ) and die;
133exit 0;