mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-23 18:55:40 +01:00
8dd1690993
Resolve conflicts by performing the following operations: - Reject changes related to building a crypto submodule, since Mbed Crypto is the crypto submodule. - Reject X.509, NET, and SSL changes. - Reject changes to README, as Mbed Crypto is a different project from Mbed TLS, with a different README. - Avoid adding mention of ssl-opt.sh in a comment near some modified code in include/CMakeLists.txt (around where ENABLE_TESTING as added). - Align config.pl in Mbed TLS with config.pl in Mbed Crypto where PSA options are concerned, to make future merging easier. There is no reason for the two to be different in this regard, now that Mbed TLS always depends on Mbed Crypto. Remaining differences are only the PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER option and the absence of X.509, NET, and SSL related options in Mbed Crypto's config.pl. - Align config.h in Mbed Crypto with Mbed TLS's copy, with a few notable exceptions: - Leave CMAC on by default. - Leave storage on by default (including ITS emulation). - Avoid documenting the PSA Crypto API as is in beta stage in documentation for MBEDTLS_PSA_CRYPTO_C. The only remaining differences are a lack of X.509, NET, and SSL options in Mbed Crypto's config.h, as well as an additional Mbed-Crypto-specific PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER option. Documentation for the check params feature and related macros is also updated to match Mbed TLS's description. - Reject tests/data_files/Makefile changes to generate DER versions of CRTs and keys, as none of those are used by Mbed Crypto tests. - Add the "no PEM and no filesystem" test to all.sh, without ssl-opt.sh run, as Mbed Crypto doesn't have ssl-opt.sh. Also remove use of PSA Crypto storage and ITS emulation, since those depend on filesystem support. - Reject addition of test when no ciphersuites have MAC to all.sh, as the option being tested, MBEDTLS_SSL_SOME_MODES_USE_MAC, is not present in Mbed Crypto. - Use baremetal config in all.sh, as Mbed Crypto's baremetal configuration does exclude the net module (as it doesn't exist in Mbed Crypto) - Reject cmake_subproject_build changes, continuing to link only libmbedcrypto. - Reject changes to visualc and associated templates. Mbed Crypto doesn't need additional logic to handle submodule-sourced headers. - Avoid adding fuzzers from Mbed TLS. The only relevant fuzzers are the privkey and pubkey fuzzers, but non-trivial work would be required to integrate those into Mbed Crypto (more than is comfortable in a merge commit). - Reject addition of Docker wrappers for compat.sh and ssl-opt.sh, as those are not present in Mbed Crypto. - Remove calls to SSL-related scripts from basic-in-docker.sh Fix test errors by performing the following: - Avoid using a link that Doxygen can't seem to resolve in Mbed Crypto, but can resolve in Mbed TLS. In documentation for MBEDTLS_CHECK_PARAMS, don't attempt to link to MBEDTLS_PARAM_FAILED. * origin/development: (339 commits) Do not build fuzz on windows No booleans and import config Removing space before opening parenthesis Style corrections Syntax fix Fixes warnings from MSVC Add a linker flag to enable gcov in basic-build-test.sh Update crypto submodule to a revision with the HAVEGE header changes Test with MBEDTLS_ECP_RESTARTABLE Allow TODO in code Use the docstring in the command line help Split _abi_compliance_command into smaller functions Record the commits that were compared Document how to build the typical argument for -s Allow running /somewhere/else/path/to/abi_check.py tests: Limit each log to 10 GiB Warn if VLAs are used Remove redundant compiler flag Consistently spell -Wextra Fix parsing issue when int parameter is in base 16 ...
293 lines
8.6 KiB
Perl
Executable File
293 lines
8.6 KiB
Perl
Executable File
#!/usr/bin/env perl
|
|
#
|
|
# This file is part of mbed TLS (https://tls.mbed.org)
|
|
#
|
|
# Copyright (c) 2014-2016, ARM Limited, All Rights Reserved
|
|
#
|
|
# Purpose
|
|
#
|
|
# Comments and uncomments #define lines in the given header file and optionally
|
|
# sets their value or can get the value. This is to provide scripting control of
|
|
# what preprocessor symbols, and therefore what build time configuration flags
|
|
# are set in the 'config.h' file.
|
|
#
|
|
# Usage: config.pl [-f <file> | --file <file>] [-o | --force]
|
|
# [set <symbol> <value> | unset <symbol> | get <symbol> |
|
|
# full | realfull]
|
|
#
|
|
# Full usage description provided below.
|
|
#
|
|
# The following options are disabled instead of enabled with "full".
|
|
#
|
|
# MBEDTLS_TEST_NULL_ENTROPY
|
|
# MBEDTLS_DEPRECATED_REMOVED
|
|
# MBEDTLS_HAVE_SSE2
|
|
# MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
|
|
# MBEDTLS_ECP_DP_M221_ENABLED
|
|
# MBEDTLS_ECP_DP_M383_ENABLED
|
|
# MBEDTLS_ECP_DP_M511_ENABLED
|
|
# MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
|
|
# MBEDTLS_NO_PLATFORM_ENTROPY
|
|
# MBEDTLS_RSA_NO_CRT
|
|
# MBEDTLS_PSA_CRYPTO_SPM
|
|
# MBEDTLS_PSA_INJECT_ENTROPY
|
|
# MBEDTLS_ECP_RESTARTABLE
|
|
# and any symbol beginning _ALT
|
|
#
|
|
|
|
use warnings;
|
|
use strict;
|
|
|
|
my $config_file = "include/mbedtls/config.h";
|
|
my $usage = <<EOU;
|
|
$0 [-f <file> | --file <file>] [-o | --force]
|
|
[set <symbol> <value> | unset <symbol> | get <symbol> |
|
|
full | realfull | baremetal]
|
|
|
|
Commands
|
|
set <symbol> [<value>] - Uncomments or adds a #define for the <symbol> to
|
|
the configuration file, and optionally making it
|
|
of <value>.
|
|
If the symbol isn't present in the file an error
|
|
is returned.
|
|
unset <symbol> - Comments out the #define for the given symbol if
|
|
present in the configuration file.
|
|
get <symbol> - Finds the #define for the given symbol, returning
|
|
an exitcode of 0 if the symbol is found, and 1 if
|
|
not. The value of the symbol is output if one is
|
|
specified in the configuration file.
|
|
full - Uncomments all #define's in the configuration file
|
|
excluding some reserved symbols, until the
|
|
'Module configuration options' section
|
|
realfull - Uncomments all #define's with no exclusions
|
|
baremetal - Sets full configuration suitable for baremetal build.
|
|
|
|
Options
|
|
-f | --file <filename> - The file or file path for the configuration file
|
|
to edit. When omitted, the following default is
|
|
used:
|
|
$config_file
|
|
-o | --force - If the symbol isn't present in the configuration
|
|
file when setting its value, a #define is
|
|
appended to the end of the file.
|
|
|
|
EOU
|
|
|
|
my @excluded = qw(
|
|
MBEDTLS_TEST_NULL_ENTROPY
|
|
MBEDTLS_DEPRECATED_REMOVED
|
|
MBEDTLS_HAVE_SSE2
|
|
MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
|
|
MBEDTLS_ECP_DP_M221_ENABLED
|
|
MBEDTLS_ECP_DP_M383_ENABLED
|
|
MBEDTLS_ECP_DP_M511_ENABLED
|
|
MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
|
|
MBEDTLS_NO_PLATFORM_ENTROPY
|
|
MBEDTLS_RSA_NO_CRT
|
|
MBEDTLS_NO_UDBL_DIVISION
|
|
MBEDTLS_NO_64BIT_MULTIPLICATION
|
|
MBEDTLS_PSA_CRYPTO_SPM
|
|
MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER
|
|
MBEDTLS_PSA_INJECT_ENTROPY
|
|
MBEDTLS_ECP_RESTARTABLE
|
|
_ALT\s*$
|
|
);
|
|
|
|
# Things that should be disabled in "baremetal"
|
|
my @excluded_baremetal = qw(
|
|
MBEDTLS_TIMING_C
|
|
MBEDTLS_FS_IO
|
|
MBEDTLS_ENTROPY_NV_SEED
|
|
MBEDTLS_HAVE_TIME
|
|
MBEDTLS_HAVE_TIME_DATE
|
|
MBEDTLS_DEPRECATED_WARNING
|
|
MBEDTLS_HAVEGE_C
|
|
MBEDTLS_THREADING_C
|
|
MBEDTLS_THREADING_PTHREAD
|
|
MBEDTLS_MEMORY_BACKTRACE
|
|
MBEDTLS_MEMORY_BUFFER_ALLOC_C
|
|
MBEDTLS_PLATFORM_TIME_ALT
|
|
MBEDTLS_PLATFORM_FPRINTF_ALT
|
|
MBEDTLS_PSA_ITS_FILE_C
|
|
MBEDTLS_PSA_CRYPTO_STORAGE_C
|
|
);
|
|
|
|
# Things that should be enabled in "full" even if they match @excluded
|
|
my @non_excluded = qw(
|
|
PLATFORM_[A-Z0-9]+_ALT
|
|
);
|
|
|
|
# Things that should be enabled in "baremetal"
|
|
my @non_excluded_baremetal = qw(
|
|
MBEDTLS_NO_PLATFORM_ENTROPY
|
|
);
|
|
|
|
# Process the command line arguments
|
|
|
|
my $force_option = 0;
|
|
|
|
my ($arg, $name, $value, $action);
|
|
|
|
while ($arg = shift) {
|
|
|
|
# Check if the argument is an option
|
|
if ($arg eq "-f" || $arg eq "--file") {
|
|
$config_file = shift;
|
|
|
|
-f $config_file or die "No such file: $config_file\n";
|
|
|
|
}
|
|
elsif ($arg eq "-o" || $arg eq "--force") {
|
|
$force_option = 1;
|
|
|
|
}
|
|
else
|
|
{
|
|
# ...else assume it's a command
|
|
$action = $arg;
|
|
|
|
if ($action eq "full" || $action eq "realfull" || $action eq "baremetal" ) {
|
|
# No additional parameters
|
|
die $usage if @ARGV;
|
|
|
|
}
|
|
elsif ($action eq "unset" || $action eq "get") {
|
|
die $usage unless @ARGV;
|
|
$name = shift;
|
|
|
|
}
|
|
elsif ($action eq "set") {
|
|
die $usage unless @ARGV;
|
|
$name = shift;
|
|
$value = shift if @ARGV;
|
|
|
|
}
|
|
else {
|
|
die "Command '$action' not recognised.\n\n".$usage;
|
|
}
|
|
}
|
|
}
|
|
|
|
# If no command was specified, exit...
|
|
if ( not defined($action) ){ die $usage; }
|
|
|
|
# Check the config file is present
|
|
if (! -f $config_file) {
|
|
|
|
chdir '..' or die;
|
|
|
|
# Confirm this is the project root directory and try again
|
|
if ( !(-d 'scripts' && -d 'include' && -d 'library' && -f $config_file) ) {
|
|
die "If no file specified, must be run from the project root or scripts directory.\n";
|
|
}
|
|
}
|
|
|
|
|
|
# Now read the file and process the contents
|
|
|
|
open my $config_read, '<', $config_file or die "read $config_file: $!\n";
|
|
my @config_lines = <$config_read>;
|
|
close $config_read;
|
|
|
|
# Add required baremetal symbols to the list that is included.
|
|
if ( $action eq "baremetal" ) {
|
|
@non_excluded = ( @non_excluded, @non_excluded_baremetal );
|
|
}
|
|
|
|
my ($exclude_re, $no_exclude_re, $exclude_baremetal_re);
|
|
if ($action eq "realfull") {
|
|
$exclude_re = qr/^$/;
|
|
$no_exclude_re = qr/./;
|
|
} else {
|
|
$exclude_re = join '|', @excluded;
|
|
$no_exclude_re = join '|', @non_excluded;
|
|
}
|
|
if ( $action eq "baremetal" ) {
|
|
$exclude_baremetal_re = join '|', @excluded_baremetal;
|
|
}
|
|
|
|
my $config_write = undef;
|
|
if ($action ne "get") {
|
|
open $config_write, '>', $config_file or die "write $config_file: $!\n";
|
|
}
|
|
|
|
my $done;
|
|
for my $line (@config_lines) {
|
|
if ($action eq "full" || $action eq "realfull" || $action eq "baremetal" ) {
|
|
if ($line =~ /name SECTION: Module configuration options/) {
|
|
$done = 1;
|
|
}
|
|
|
|
if (!$done && $line =~ m!^//\s?#define! &&
|
|
( $line !~ /$exclude_re/ || $line =~ /$no_exclude_re/ ) &&
|
|
( $action ne "baremetal" || ( $line !~ /$exclude_baremetal_re/ ) ) ) {
|
|
$line =~ s!^//\s?!!;
|
|
}
|
|
if (!$done && $line =~ m!^\s?#define! &&
|
|
! ( ( $line !~ /$exclude_re/ || $line =~ /$no_exclude_re/ ) &&
|
|
( $action ne "baremetal" || ( $line !~ /$exclude_baremetal_re/ ) ) ) ) {
|
|
$line =~ s!^!//!;
|
|
}
|
|
} elsif ($action eq "unset") {
|
|
if (!$done && $line =~ /^\s*#define\s*$name\b/) {
|
|
$line = '//' . $line;
|
|
$done = 1;
|
|
}
|
|
} elsif (!$done && $action eq "set") {
|
|
if ($line =~ m!^(?://)?\s*#define\s*$name\b!) {
|
|
$line = "#define $name";
|
|
$line .= " $value" if defined $value && $value ne "";
|
|
$line .= "\n";
|
|
$done = 1;
|
|
}
|
|
} elsif (!$done && $action eq "get") {
|
|
if ($line =~ /^\s*#define\s*$name(?:\s+(.*?))\s*(?:$|\/\*|\/\/)/) {
|
|
$value = $1;
|
|
$done = 1;
|
|
}
|
|
}
|
|
|
|
if (defined $config_write) {
|
|
print $config_write $line or die "write $config_file: $!\n";
|
|
}
|
|
}
|
|
|
|
# Did the set command work?
|
|
if ($action eq "set" && $force_option && !$done) {
|
|
|
|
# If the force option was set, append the symbol to the end of the file
|
|
my $line = "#define $name";
|
|
$line .= " $value" if defined $value && $value ne "";
|
|
$line .= "\n";
|
|
$done = 1;
|
|
|
|
print $config_write $line or die "write $config_file: $!\n";
|
|
}
|
|
|
|
if (defined $config_write) {
|
|
close $config_write or die "close $config_file: $!\n";
|
|
}
|
|
|
|
if ($action eq "get") {
|
|
if ($done) {
|
|
if ($value ne '') {
|
|
print "$value\n";
|
|
}
|
|
exit 0;
|
|
} else {
|
|
# If the symbol was not found, return an error
|
|
exit 1;
|
|
}
|
|
}
|
|
|
|
if ($action eq "full" && !$done) {
|
|
die "Configuration section was not found in $config_file\n";
|
|
|
|
}
|
|
|
|
if ($action ne "full" && $action ne "unset" && !$done) {
|
|
die "A #define for the symbol $name was not found in $config_file\n";
|
|
}
|
|
|
|
__END__
|