Skip to content

Remove MBEDTLS_SHA3_C config option #10145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion programs/test/selftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,10 @@ const selftest_t selftests[] =
#if defined(MBEDTLS_SHA512_C)
{ "sha512", mbedtls_sha512_self_test },
#endif
#if defined(MBEDTLS_SHA3_C)
#if defined(PSA_WANT_ALG_SHA3_224) || \
defined(PSA_WANT_ALG_SHA3_256) || \
defined(PSA_WANT_ALG_SHA3_384) || \
defined(PSA_WANT_ALG_SHA3_512)
{ "sha3", mbedtls_sha3_self_test },
#endif
#if defined(MBEDTLS_DES_C)
Expand Down
64 changes: 39 additions & 25 deletions scripts/generate_errors.pl
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
}
}

my $ll_old_define = "";
my $hl_old_define = "";
my @ll_old_define = ("", "", "");
my @hl_old_define = ("", "", "");

my $ll_code_check = "";
my $hl_code_check = "";
Expand Down Expand Up @@ -129,6 +129,14 @@
$define_name = "SSL_TLS" if ($define_name eq "SSL");
$define_name = "PEM_PARSE,PEM_WRITE" if ($define_name eq "PEM");
$define_name = "PKCS7" if ($define_name eq "PKCS7");
$define_name = "ALG_SHA3_224,ALG_SHA3_256,ALG_SHA3_384,ALG_SHA3_512"
if ($define_name eq "SHA3");

my $define_prefix = "MBEDTLS_";
$define_prefix = "PSA_WANT_" if ($module_name eq "SHA3");

my $define_suffix = "_C";
$define_suffix = "" if ($module_name eq "SHA3");

my $include_name = $module_name;
$include_name =~ tr/A-Z/a-z/;
Expand All @@ -154,26 +162,30 @@
if ($found_ll)
{
$code_check = \$ll_code_check;
$old_define = \$ll_old_define;
$old_define = \@ll_old_define;
$white_space = ' ';
}
else
{
$code_check = \$hl_code_check;
$old_define = \$hl_old_define;
$old_define = \@hl_old_define;
$white_space = ' ';
}

if ($define_name ne ${$old_define})
my $old_define_name = \${$old_define}[0];
my $old_define_prefix = \${$old_define}[1];
my $old_define_suffix = \${$old_define}[2];

if ($define_name ne ${$old_define_name})
{
if (${$old_define} ne "")
if (${$old_define_name} ne "")
{
${$code_check} .= "#endif /* ";
$first = 0;
foreach my $dep (split(/,/, ${$old_define}))
foreach my $dep (split(/,/, ${$old_define_name}))
{
${$code_check} .= " || " if ($first++);
${$code_check} .= "MBEDTLS_${dep}_C";
${$code_check} .= " || \n " if ($first++);
${$code_check} .= "${$old_define_prefix}${dep}${$old_define_suffix}";
}
${$code_check} .= " */\n\n";
}
Expand All @@ -183,49 +195,51 @@
$first = 0;
foreach my $dep (split(/,/, ${define_name}))
{
${$code_check} .= " || " if ($first);
$headers .= " || " if ($first++);
${$code_check} .= " || \\\n " if ($first);
$headers .= " || \\\n " if ($first++);

${$code_check} .= "defined(MBEDTLS_${dep}_C)";
$headers .= "defined(MBEDTLS_${dep}_C)" if
($include_name ne "");
${$code_check} .= "defined(${define_prefix}${dep}${define_suffix})";
$headers .= "defined(${define_prefix}${dep}${define_suffix})"
if ($include_name ne "");
}
${$code_check} .= "\n";
$headers .= "\n#include \"mbedtls/${include_name}.h\"\n".
"#endif\n\n" if ($include_name ne "");
${$old_define} = $define_name;
${$old_define_name} = $define_name;
${$old_define_prefix} = $define_prefix;
${$old_define_suffix} = $define_suffix;
}

${$code_check} .= "${white_space}case -($error_name):\n".
"${white_space} return( \"$module_name - $description\" );\n"
};

if ($ll_old_define ne "")
if ($ll_old_define[0] ne "")
{
$ll_code_check .= "#endif /* ";
my $first = 0;
foreach my $dep (split(/,/, $ll_old_define))
foreach my $dep (split(/,/, $ll_old_define[0]))
{
$ll_code_check .= " || " if ($first++);
$ll_code_check .= "MBEDTLS_${dep}_C";
$ll_code_check .= " || \n " if ($first++);
$ll_code_check .= "${ll_old_define[1]}${dep}${ll_old_define[2]}";
}
$ll_code_check .= " */\n";
}
if ($hl_old_define ne "")
if ($hl_old_define[0] ne "")
{
$hl_code_check .= "#endif /* ";
my $first = 0;
foreach my $dep (split(/,/, $hl_old_define))
foreach my $dep (split(/,/, $hl_old_define[0]))
{
$hl_code_check .= " || " if ($first++);
$hl_code_check .= "MBEDTLS_${dep}_C";
$hl_code_check .= " || \n " if ($first++);
$hl_code_check .= "${hl_old_define[1]}${dep}${hl_old_define[2]}";
}
$hl_code_check .= " */\n";
}

$error_format =~ s/HEADER_INCLUDED\n/$headers/g;
$error_format =~ s/LOW_LEVEL_CODE_CHECKS\n/$ll_code_check/g;
$error_format =~ s/HIGH_LEVEL_CODE_CHECKS\n/$hl_code_check/g;
$error_format =~ s/ *LOW_LEVEL_CODE_CHECKS\n/$ll_code_check/g;
$error_format =~ s/ *HIGH_LEVEL_CODE_CHECKS\n/$hl_code_check/g;

open(ERROR_FILE, ">$error_file") or die "Opening destination file '$error_file': $!";
print ERROR_FILE $error_format;
Expand Down
4 changes: 2 additions & 2 deletions tests/scripts/components-configuration-crypto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,7 @@ component_test_psa_crypto_config_accel_hash () {
scripts/config.py unset MBEDTLS_SHA256_C
scripts/config.py unset MBEDTLS_SHA384_C
scripts/config.py unset MBEDTLS_SHA512_C
scripts/config.py unset MBEDTLS_SHA3_C
scripts/config.py unset-all PSA_WANT_ALG_SHA3_*

# Build
# -----
Expand Down Expand Up @@ -1594,7 +1594,7 @@ config_psa_crypto_hash_use_psa () {
scripts/config.py unset MBEDTLS_SHA384_C
scripts/config.py unset MBEDTLS_SHA512_C
scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
scripts/config.py unset MBEDTLS_SHA3_C
scripts/config.py unset-all PSA_WANT_ALG_SHA3_*
fi
}

Expand Down
4 changes: 0 additions & 4 deletions tests/scripts/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,6 @@ def test(self, options):
'MBEDTLS_SHA512_C': ['MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT',
'MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY',
'PSA_WANT_ALG_SHA_512'],
'MBEDTLS_SHA3_C' : ['PSA_WANT_ALG_SHA3_224',
'PSA_WANT_ALG_SHA3_256',
'PSA_WANT_ALG_SHA3_384',
'PSA_WANT_ALG_SHA3_512'],
}

# If an option is tested in an exclusive test, alter the following defines.
Expand Down