fbrosson | 533407a | 2018-04-04 21:44:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Manuel Pégourié-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 2 | |
| 3 | # depends-pkalgs.pl |
| 4 | # |
| 5 | # Copyright (c) 2017, ARM Limited, All Rights Reserved |
Bence Szépkúti | c7da1fe | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 6 | # 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 | # |
| 20 | # This file is part of Mbed TLS (https://tls.mbed.org) |
Manuel Pégourié-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 21 | # |
| 22 | # Purpose |
| 23 | # |
Manuel Pégourié-Gonnard | 562df40 | 2017-08-08 18:09:14 +0200 | [diff] [blame] | 24 | # To test the code dependencies on individual PK algs (those that can be used |
| 25 | # from the PK layer, so currently signature and encryption but not key |
| 26 | # exchange) in each test suite. This is a verification step to ensure we don't |
| 27 | # ship test suites that do not work for some build options. |
Manuel Pégourié-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 28 | # |
| 29 | # The process is: |
| 30 | # for each possible PK alg |
| 31 | # build the library and test suites with that alg disabled |
| 32 | # execute the test suites |
| 33 | # |
| 34 | # And any test suite with the wrong dependencies will fail. |
| 35 | # |
| 36 | # Usage: tests/scripts/depends-pkalgs.pl |
| 37 | # |
| 38 | # This script should be executed from the root of the project directory. |
| 39 | # |
| 40 | # For best effect, run either with cmake disabled, or cmake enabled in a mode |
| 41 | # that includes -Werror. |
| 42 | |
| 43 | use warnings; |
| 44 | use strict; |
| 45 | |
| 46 | -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n"; |
| 47 | |
| 48 | my $config_h = 'include/mbedtls/config.h'; |
| 49 | |
Manuel Pégourié-Gonnard | 562df40 | 2017-08-08 18:09:14 +0200 | [diff] [blame] | 50 | # Some algorithms can't be disabled on their own as others depend on them, so |
| 51 | # we list those reverse-dependencies here to keep check_config.h happy. |
Manuel Pégourié-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 52 | my %algs = ( |
Gilles Peskine | 7ab66a6 | 2018-09-14 17:47:41 +0200 | [diff] [blame^] | 53 | 'MBEDTLS_ECDSA_C' => ['MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED', |
| 54 | 'MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED'], |
Gert van Dijk | 25d124d | 2017-09-05 14:25:52 +0200 | [diff] [blame] | 55 | 'MBEDTLS_ECP_C' => ['MBEDTLS_ECDSA_C', |
| 56 | 'MBEDTLS_ECDH_C', |
| 57 | 'MBEDTLS_ECJPAKE_C', |
| 58 | 'MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED', |
| 59 | 'MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED', |
| 60 | 'MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED', |
| 61 | 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED', |
| 62 | 'MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED'], |
Manuel Pégourié-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 63 | 'MBEDTLS_X509_RSASSA_PSS_SUPPORT' => [], |
| 64 | 'MBEDTLS_PKCS1_V21' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT'], |
Gert van Dijk | 25d124d | 2017-09-05 14:25:52 +0200 | [diff] [blame] | 65 | 'MBEDTLS_PKCS1_V15' => ['MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED', |
| 66 | 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED', |
| 67 | 'MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED', |
| 68 | 'MBEDTLS_KEY_EXCHANGE_RSA_ENABLED'], |
| 69 | 'MBEDTLS_RSA_C' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT', |
| 70 | 'MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED', |
| 71 | 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED', |
Gilles Peskine | 7ab66a6 | 2018-09-14 17:47:41 +0200 | [diff] [blame^] | 72 | 'MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED', |
Gert van Dijk | 25d124d | 2017-09-05 14:25:52 +0200 | [diff] [blame] | 73 | 'MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED', |
| 74 | 'MBEDTLS_KEY_EXCHANGE_RSA_ENABLED'], |
Manuel Pégourié-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 75 | ); |
| 76 | |
| 77 | system( "cp $config_h $config_h.bak" ) and die; |
| 78 | sub abort { |
| 79 | system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n"; |
Manuel Pégourié-Gonnard | 254eec8 | 2017-10-26 09:47:36 +0200 | [diff] [blame] | 80 | # use an exit code between 1 and 124 for git bisect (die returns 255) |
Manuel Pégourié-Gonnard | a7c4c8a | 2017-07-12 12:15:24 +0200 | [diff] [blame] | 81 | warn $_[0]; |
| 82 | exit 1; |
Manuel Pégourié-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | while( my ($alg, $extras) = each %algs ) { |
| 86 | system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 87 | system( "make clean" ) and die; |
| 88 | |
| 89 | print "\n******************************************\n"; |
| 90 | print "* Testing without alg: $alg\n"; |
| 91 | print "******************************************\n"; |
Gilles Peskine | 9004a17 | 2019-09-16 15:20:36 +0200 | [diff] [blame] | 92 | $ENV{MBEDTLS_TEST_CONFIGURATION} = "-$alg"; |
Manuel Pégourié-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 93 | |
Gilles Peskine | 5d46f6a | 2019-07-27 23:52:53 +0200 | [diff] [blame] | 94 | system( "scripts/config.py unset $alg" ) |
Manuel Pégourié-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 95 | and abort "Failed to disable $alg\n"; |
| 96 | for my $opt (@$extras) { |
Gilles Peskine | 5d46f6a | 2019-07-27 23:52:53 +0200 | [diff] [blame] | 97 | system( "scripts/config.py unset $opt" ) |
Manuel Pégourié-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 98 | and abort "Failed to disable $opt\n"; |
| 99 | } |
| 100 | |
Manuel Pégourié-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 101 | system( "CFLAGS='-Werror -Wall -Wextra' make lib" ) |
| 102 | and abort "Failed to build lib: $alg\n"; |
| 103 | system( "cd tests && make" ) and abort "Failed to build tests: $alg\n"; |
| 104 | system( "make test" ) and abort "Failed test suite: $alg\n"; |
| 105 | } |
| 106 | |
| 107 | system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 108 | system( "make clean" ) and die; |
| 109 | exit 0; |