depends-pkalgs.pl 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/usr/bin/env perl
  2. # depends-pkalgs.pl
  3. #
  4. # Copyright The Mbed TLS Contributors
  5. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  6. #
  7. # This file is provided under the Apache License 2.0, or the
  8. # GNU General Public License v2.0 or later.
  9. #
  10. # **********
  11. # Apache License 2.0:
  12. #
  13. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  14. # not use this file except in compliance with the License.
  15. # You may obtain a copy of the License at
  16. #
  17. # http://www.apache.org/licenses/LICENSE-2.0
  18. #
  19. # Unless required by applicable law or agreed to in writing, software
  20. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  21. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. # See the License for the specific language governing permissions and
  23. # limitations under the License.
  24. #
  25. # **********
  26. #
  27. # **********
  28. # GNU General Public License v2.0 or later:
  29. #
  30. # This program is free software; you can redistribute it and/or modify
  31. # it under the terms of the GNU General Public License as published by
  32. # the Free Software Foundation; either version 2 of the License, or
  33. # (at your option) any later version.
  34. #
  35. # This program is distributed in the hope that it will be useful,
  36. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  37. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  38. # GNU General Public License for more details.
  39. #
  40. # You should have received a copy of the GNU General Public License along
  41. # with this program; if not, write to the Free Software Foundation, Inc.,
  42. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  43. #
  44. # **********
  45. #
  46. # Purpose
  47. #
  48. # To test the code dependencies on individual PK algs (those that can be used
  49. # from the PK layer, so currently signature and encryption but not key
  50. # exchange) in each test suite. This is a verification step to ensure we don't
  51. # ship test suites that do not work for some build options.
  52. #
  53. # The process is:
  54. # for each possible PK alg
  55. # build the library and test suites with that alg disabled
  56. # execute the test suites
  57. #
  58. # And any test suite with the wrong dependencies will fail.
  59. #
  60. # Usage: tests/scripts/depends-pkalgs.pl
  61. #
  62. # This script should be executed from the root of the project directory.
  63. #
  64. # For best effect, run either with cmake disabled, or cmake enabled in a mode
  65. # that includes -Werror.
  66. use warnings;
  67. use strict;
  68. -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
  69. my $config_h = 'include/mbedtls/config.h';
  70. # Some algorithms can't be disabled on their own as others depend on them, so
  71. # we list those reverse-dependencies here to keep check_config.h happy.
  72. my %algs = (
  73. 'MBEDTLS_ECDSA_C' => ['MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED'],
  74. 'MBEDTLS_ECP_C' => ['MBEDTLS_ECDSA_C',
  75. 'MBEDTLS_ECDH_C',
  76. 'MBEDTLS_ECJPAKE_C',
  77. 'MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED',
  78. 'MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED',
  79. 'MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED',
  80. 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
  81. 'MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED'],
  82. 'MBEDTLS_X509_RSASSA_PSS_SUPPORT' => [],
  83. 'MBEDTLS_PKCS1_V21' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT'],
  84. 'MBEDTLS_PKCS1_V15' => ['MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED',
  85. 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
  86. 'MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED',
  87. 'MBEDTLS_KEY_EXCHANGE_RSA_ENABLED'],
  88. 'MBEDTLS_RSA_C' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT',
  89. '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. );
  94. system( "cp $config_h $config_h.bak" ) and die;
  95. sub abort {
  96. system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
  97. # use an exit code between 1 and 124 for git bisect (die returns 255)
  98. warn $_[0];
  99. exit 1;
  100. }
  101. while( my ($alg, $extras) = each %algs ) {
  102. system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
  103. system( "make clean" ) and die;
  104. print "\n******************************************\n";
  105. print "* Testing without alg: $alg\n";
  106. print "******************************************\n";
  107. system( "scripts/config.pl unset $alg" )
  108. and abort "Failed to disable $alg\n";
  109. for my $opt (@$extras) {
  110. system( "scripts/config.pl unset $opt" )
  111. and abort "Failed to disable $opt\n";
  112. }
  113. system( "CFLAGS='-Werror -Wall -Wextra' make lib" )
  114. and abort "Failed to build lib: $alg\n";
  115. system( "cd tests && make" ) and abort "Failed to build tests: $alg\n";
  116. system( "make test" ) and abort "Failed test suite: $alg\n";
  117. }
  118. system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
  119. system( "make clean" ) and die;
  120. exit 0;