depends-pkalgs.pl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env perl
  2. # depends-pkalgs.pl
  3. #
  4. # Copyright The Mbed TLS Contributors
  5. # SPDX-License-Identifier: Apache-2.0
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  8. # not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. # Purpose
  20. #
  21. # To test the code dependencies on individual PK algs (those that can be used
  22. # from the PK layer, so currently signature and encryption but not key
  23. # exchange) in each test suite. This is a verification step to ensure we don't
  24. # ship test suites that do not work for some build options.
  25. #
  26. # The process is:
  27. # for each possible PK alg
  28. # build the library and test suites with that alg disabled
  29. # execute the test suites
  30. #
  31. # And any test suite with the wrong dependencies will fail.
  32. #
  33. # Usage: tests/scripts/depends-pkalgs.pl
  34. #
  35. # This script should be executed from the root of the project directory.
  36. #
  37. # For best effect, run either with cmake disabled, or cmake enabled in a mode
  38. # that includes -Werror.
  39. use warnings;
  40. use strict;
  41. -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
  42. my $config_h = 'include/mbedtls/config.h';
  43. # Some algorithms can't be disabled on their own as others depend on them, so
  44. # we list those reverse-dependencies here to keep check_config.h happy.
  45. my %algs = (
  46. 'MBEDTLS_ECDSA_C' => ['MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED',
  47. 'MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED'],
  48. 'MBEDTLS_ECP_C' => ['MBEDTLS_ECDSA_C',
  49. 'MBEDTLS_ECDH_C',
  50. 'MBEDTLS_ECJPAKE_C',
  51. 'MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED',
  52. 'MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED',
  53. 'MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED',
  54. 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
  55. 'MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED'],
  56. 'MBEDTLS_X509_RSASSA_PSS_SUPPORT' => [],
  57. 'MBEDTLS_PKCS1_V21' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT'],
  58. 'MBEDTLS_PKCS1_V15' => ['MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED',
  59. 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
  60. 'MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED',
  61. 'MBEDTLS_KEY_EXCHANGE_RSA_ENABLED'],
  62. 'MBEDTLS_RSA_C' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT',
  63. 'MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED',
  64. 'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
  65. 'MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED',
  66. 'MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED',
  67. 'MBEDTLS_KEY_EXCHANGE_RSA_ENABLED'],
  68. );
  69. system( "cp $config_h $config_h.bak" ) and die;
  70. sub abort {
  71. system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
  72. # use an exit code between 1 and 124 for git bisect (die returns 255)
  73. warn $_[0];
  74. exit 1;
  75. }
  76. while( my ($alg, $extras) = each %algs ) {
  77. system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
  78. system( "make clean" ) and die;
  79. print "\n******************************************\n";
  80. print "* Testing without alg: $alg\n";
  81. print "******************************************\n";
  82. $ENV{MBEDTLS_TEST_CONFIGURATION} = "-$alg";
  83. system( "scripts/config.py unset $alg" )
  84. and abort "Failed to disable $alg\n";
  85. for my $opt (@$extras) {
  86. system( "scripts/config.py unset $opt" )
  87. and abort "Failed to disable $opt\n";
  88. }
  89. system( "CFLAGS='-Werror -Wall -Wextra' make lib" )
  90. and abort "Failed to build lib: $alg\n";
  91. system( "cd tests && make" ) and abort "Failed to build tests: $alg\n";
  92. system( "make test" ) and abort "Failed test suite: $alg\n";
  93. }
  94. system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
  95. system( "make clean" ) and die;
  96. exit 0;