blob: 50e4837cdcf548ad4e94f880eec6f779e301ed43 [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
6#
7# Purpose
8#
Manuel Pégourié-Gonnard562df402017-08-08 18:09:14 +02009# To test the code dependencies on individual PK algs (those that can be used
10# from the PK layer, so currently signature and encryption but not key
11# exchange) in each test suite. This is a verification step to ensure we don't
12# ship test suites that do not work for some build options.
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020013#
14# The process is:
15# for each possible PK alg
16# build the library and test suites with that alg disabled
17# execute the test suites
18#
19# And any test suite with the wrong dependencies will fail.
20#
21# Usage: tests/scripts/depends-pkalgs.pl
22#
23# This script should be executed from the root of the project directory.
24#
25# For best effect, run either with cmake disabled, or cmake enabled in a mode
26# that includes -Werror.
27
28use warnings;
29use strict;
30
31-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
32
33my $config_h = 'include/mbedtls/config.h';
34
Manuel Pégourié-Gonnard562df402017-08-08 18:09:14 +020035# Some algorithms can't be disabled on their own as others depend on them, so
36# we list those reverse-dependencies here to keep check_config.h happy.
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020037my %algs = (
Gert van Dijk25d124d2017-09-05 14:25:52 +020038 'MBEDTLS_ECDSA_C' => ['MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED'],
39 'MBEDTLS_ECP_C' => ['MBEDTLS_ECDSA_C',
40 'MBEDTLS_ECDH_C',
41 'MBEDTLS_ECJPAKE_C',
Hanno Becker6b2b2212019-09-02 16:58:24 +010042 'MBEDTLS_ECP_DP_SECP192R1_ENABLED',
43 'MBEDTLS_ECP_DP_SECP224R1_ENABLED',
44 'MBEDTLS_ECP_DP_SECP256R1_ENABLED',
45 'MBEDTLS_ECP_DP_SECP384R1_ENABLED',
46 'MBEDTLS_ECP_DP_SECP521R1_ENABLED',
47 'MBEDTLS_ECP_DP_BP256R1_ENABLED',
48 'MBEDTLS_ECP_DP_BP384R1_ENABLED',
49 'MBEDTLS_ECP_DP_BP512R1_ENABLED',
50 'MBEDTLS_ECP_DP_SECP192K1_ENABLED',
51 'MBEDTLS_ECP_DP_SECP224K1_ENABLED',
52 'MBEDTLS_ECP_DP_SECP256K1_ENABLED',
Gert van Dijk25d124d2017-09-05 14:25:52 +020053 'MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED',
54 'MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED',
55 'MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED',
56 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
57 'MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED'],
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020058 'MBEDTLS_X509_RSASSA_PSS_SUPPORT' => [],
59 'MBEDTLS_PKCS1_V21' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT'],
Gert van Dijk25d124d2017-09-05 14:25:52 +020060 'MBEDTLS_PKCS1_V15' => ['MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED',
61 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
62 'MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED',
63 'MBEDTLS_KEY_EXCHANGE_RSA_ENABLED'],
64 'MBEDTLS_RSA_C' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT',
65 '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'],
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020069);
70
71system( "cp $config_h $config_h.bak" ) and die;
72sub abort {
73 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020074 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020075 warn $_[0];
76 exit 1;
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020077}
78
79while( my ($alg, $extras) = each %algs ) {
80 system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
81 system( "make clean" ) and die;
82
83 print "\n******************************************\n";
84 print "* Testing without alg: $alg\n";
85 print "******************************************\n";
86
87 system( "scripts/config.pl unset $alg" )
88 and abort "Failed to disable $alg\n";
89 for my $opt (@$extras) {
90 system( "scripts/config.pl unset $opt" )
91 and abort "Failed to disable $opt\n";
92 }
93
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020094 system( "CFLAGS='-Werror -Wall -Wextra' make lib" )
95 and abort "Failed to build lib: $alg\n";
96 system( "cd tests && make" ) and abort "Failed to build tests: $alg\n";
97 system( "make test" ) and abort "Failed test suite: $alg\n";
98}
99
100system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
101system( "make clean" ) and die;
102exit 0;