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 | # |
Bence Szépkúti | a2947ac | 2020-08-19 16:37:36 +0200 | [diff] [blame] | 5 | # Copyright The Mbed TLS Contributors |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 6 | # 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úti | 51b41d5 | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 13 | # |
| 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úti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 26 | # ********** |
| 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é-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 47 | # Purpose |
| 48 | # |
Manuel Pégourié-Gonnard | 562df40 | 2017-08-08 18:09:14 +0200 | [diff] [blame] | 49 | # 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é-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 53 | # |
| 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 | |
| 68 | use warnings; |
| 69 | use strict; |
| 70 | |
| 71 | -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n"; |
| 72 | |
| 73 | my $config_h = 'include/mbedtls/config.h'; |
| 74 | |
Manuel Pégourié-Gonnard | 562df40 | 2017-08-08 18:09:14 +0200 | [diff] [blame] | 75 | # 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é-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 77 | my %algs = ( |
Gert van Dijk | 25d124d | 2017-09-05 14:25:52 +0200 | [diff] [blame] | 78 | '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é-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 87 | 'MBEDTLS_X509_RSASSA_PSS_SUPPORT' => [], |
| 88 | 'MBEDTLS_PKCS1_V21' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT'], |
Gert van Dijk | 25d124d | 2017-09-05 14:25:52 +0200 | [diff] [blame] | 89 | '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é-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 98 | ); |
| 99 | |
| 100 | system( "cp $config_h $config_h.bak" ) and die; |
| 101 | sub abort { |
| 102 | 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] | 103 | # 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] | 104 | warn $_[0]; |
| 105 | exit 1; |
Manuel Pégourié-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | while( 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é-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame] | 123 | 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 | |
| 129 | system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 130 | system( "make clean" ) and die; |
| 131 | exit 0; |