Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
d589854
mbedtls_ssl_get_alert(): getter for fatal alerts
ng-gsmk Nov 18, 2025
0841cea
test ssl_get_alert_after_fatal - remove mbedtls_ssl_conf_rng
ng-gsmk Nov 19, 2025
f9a734f
Fix C code style issues
ng-gsmk Nov 19, 2025
13200ab
Fix more C code style issues
ng-gsmk Nov 19, 2025
33bd8f8
ssl - reset alert type for session reset
ng-gsmk Dec 10, 2025
6140cfb
tests/ssl_get_alert_after_fatal - add invalid param case
ng-gsmk Dec 10, 2025
10eaf68
library: debug: remove mbedtls_debug_print_mpi()
valeriosetti Nov 19, 2025
c6bf9d8
library: debug: use mbedtls_pk_write_pubkey_psa() to write public key
valeriosetti Nov 19, 2025
f1cb452
library: debug: improve mbedtls_debug_print_buf()
valeriosetti Nov 19, 2025
3c419c1
tests: scripts: adjust CRT dump test data
valeriosetti Nov 19, 2025
af62bae
library: debug: add PK_WRITE_C guard to mbedtls_debug_print_crt()
valeriosetti Dec 16, 2025
d040eb8
include: debug: fix guards for MBEDTLS_SSL_DEBUG_CRT
valeriosetti Dec 16, 2025
2af638a
library: debug: fix print format in mbedtls_debug_print_buf_ext()
valeriosetti Dec 18, 2025
ebbaca0
library: debug: adjust guards for "mbedtls_debug_print_crt"
valeriosetti Jan 7, 2026
4d62c59
tests: scripts: add new component to test with only pkwrite disabled
valeriosetti Jan 8, 2026
059aac8
tests: scripts: build with cmake in all components using Asan
valeriosetti Jan 8, 2026
fca232c
Update tf-psa-crypto with makefile helpers
gilles-peskine-arm Jan 7, 2026
e23b6e4
Use the crypto makefile helpers in tf-psa-crypto
gilles-peskine-arm Dec 18, 2025
4ffb299
Remove local copies of makefile helpers
gilles-peskine-arm Jan 7, 2026
193401c
Merge pull request #10544 from gilles-peskine-arm/move-crypto-makefiles
ronald-cron-arm Jan 8, 2026
fdccbbb
tests: scripts: configuration-crypto: fix paths after switch to CMake
valeriosetti Jan 8, 2026
f7173e4
Merge pull request #10517 from valeriosetti/issue10460
valeriosetti Jan 9, 2026
5aba22b
tests: scripts: configuration-crypto: fix paths for "not grep"
valeriosetti Jan 9, 2026
2481daa
Replace mbedtls_pk_get_name with pk_key_type_to_string
Dec 9, 2025
f9b95ce
Fix style issues
Dec 9, 2025
837a3ce
rename function
Dec 9, 2025
81deeb8
Update ssl-opt to remove Opaque key types
Dec 11, 2025
98e958c
Update ssl-opt tests as wrapped keys now expose the underlying type
Dec 22, 2025
f77d749
Further updates to ssl-opt tests as wrapped keys now expose the under…
Dec 23, 2025
085aef5
Change function name from mbedtls_pk_key_type_to_string to mbedtls_x5…
Jan 2, 2026
c23592d
Add improvements to code comments and docs
Jan 5, 2026
095fe07
Update tf-psa-crypto and framework modules to resolve merge conflict …
Jan 12, 2026
c58c20d
tests: scripts: fix grep paths in test_tfm_config_p256m_driver_accel_ec
valeriosetti Jan 12, 2026
fef622c
Merge pull request #10559 from valeriosetti/fix-not-grep
valeriosetti Jan 12, 2026
d1307a1
components-configuration-crypto: Migrated simple ASAN components.
minosgalanakis Dec 1, 2025
3baeee8
components-configuration-crypto: Migrated test_full_static_keystore t…
minosgalanakis Dec 1, 2025
279c016
components-configuration-crypto: Migrated test_tfm_config_p256m_drive…
minosgalanakis Dec 1, 2025
6db68f9
components-configuration-crypto: Migrated straightforwad Release comp…
minosgalanakis Dec 1, 2025
5e99591
components-configuration-crypto: Migrated include dir dependant Relea…
minosgalanakis Dec 1, 2025
1fcca1f
component-configuration-crypto: Migrated component_test_crypto_full_m…
minosgalanakis Dec 1, 2025
486b6c8
components-configuration-crypto: Migrated components with custom LDFL…
minosgalanakis Dec 1, 2025
8cdccde
component-configuration-crypto: Migrated build_psa_alt_headers
minosgalanakis Dec 1, 2025
69545a8
component-configuration-crypto: Added consistent cmake commands.
minosgalanakis Dec 2, 2025
67a9123
component-configuration-crypto: Changed location of psa-alt-header
minosgalanakis Dec 15, 2025
0c297de
component-configuration-crypto: Changed cleanup order.
minosgalanakis Jan 12, 2026
2ad6e5b
component-configuration-crypto: Adjusted test_crypto_full_md_light_only
minosgalanakis Jan 12, 2026
1919ee4
Merge pull request #10533 from bjwtaylor/remove-pk_get_name
valeriosetti Jan 13, 2026
21fa489
all.sh: fix file paths for "not grep"
mpg Jan 13, 2026
69e117f
Merge pull request #10562 from mpg/fix-not-grep
valeriosetti Jan 13, 2026
6370f1c
Merge pull request #10507 from minosgalanakis/rework/component-config…
ronald-cron-arm Jan 14, 2026
4e2584d
tests: scripts: remove set_psa_test_dependencies.py
valeriosetti Jan 14, 2026
fe978ac
Remove Deprecated Items From Sample Programs
Jan 2, 2026
eace7ca
Remove double initialisation of psa
Jan 6, 2026
99ec289
Remove duplicated reproducable
Jan 6, 2026
79002cc
Remove rng_get from sample programs, as it is no longer required
Jan 6, 2026
552f314
Re-add the HMAC_DRBG and CTR_DRBG are cryptographic modules as they a…
Jan 6, 2026
b6cccdf
Replace mbedtls_psa_get_random
Jan 12, 2026
767a365
Remove f_rng p_rng, as these are no longer used
Jan 12, 2026
7d71244
Remove rng_context_t, as it is no longer useful
Jan 12, 2026
dcf7670
Add further rng removals highlighted by the ci
Jan 12, 2026
b300692
Remove some headers from ssl_test_lib.h, as they are no longer required
Jan 14, 2026
842d2d9
Re-add mbedtls_entropy_self_test_wrapper
Jan 14, 2026
4569547
Add fixes for defines in selftest
Jan 15, 2026
fe3f378
Restore mbedtls_memory_buffer_alloc_free_and_self_test, as it is stil…
Jan 15, 2026
d493721
Merge pull request #10551 from bjwtaylor/remove-drbg-modules
gilles-peskine-arm Jan 15, 2026
069cfbd
Merge pull request #10564 from valeriosetti/issue10380-mbedtls
valeriosetti Jan 16, 2026
b712065
Clarify CRL security guarantees
yanesca Jan 19, 2026
7a9eceb
Clarify purpose and suitability of sample programs
yanesca Jan 19, 2026
a852e72
SECURITY.md: make x509 data section more readable
yanesca Jan 20, 2026
2b9f62a
programs/README.md clarify security remark
yanesca Jan 20, 2026
abf6c3a
CMake: Declare pqcp driver to mbedtls
gilles-peskine-arm Jan 20, 2026
7294fc1
Merge pull request #10567 from yanesca/add_clarifications_4.x
davidhorstmann-arm Jan 20, 2026
5ed5aeb
Merge pull request #10569 from gilles-peskine-arm/mldsa-pqcp-add-driv…
gilles-peskine-arm Jan 21, 2026
0c8b25a
library: ssl: add public function to retrieve the list of supported g…
valeriosetti Jan 21, 2026
1ab5173
library: ssl: improve documentation of mbedtls_ssl_conf_groups()
valeriosetti Jan 22, 2026
2707100
library: ssl: move location of ssl_preset_default_groups()
valeriosetti Jan 21, 2026
67f30df
library: ssl: use correct PSA_WANT for DH groups in ssl_preset_defaul…
valeriosetti Jan 21, 2026
335b1b6
library: ssl: add missing secp256k1 to ssl_preset_default_groups
valeriosetti Jan 21, 2026
499e3d1
Fix more paths for "not grep"
mpg Jan 22, 2026
8686ad1
tests: ssl: add testing for mbedtls_ssl_get_supported_group_list()
valeriosetti Jan 21, 2026
46a5f30
Merge pull request #10571 from mpg/fix-not-grep-2
valeriosetti Jan 22, 2026
6c5a9f0
library: ssl: improve/fix documentation of group related functions
valeriosetti Jan 22, 2026
2aecd2c
library|tests: ssl: remove secp256k1 from default groups
valeriosetti Jan 22, 2026
7ca3c60
library: ssl: add macro for allocating a TLS-ID <-> group-name table
valeriosetti Jan 26, 2026
c87adb6
tests: ssl: add test for TLS-ID <-> curve-name table
valeriosetti Jan 26, 2026
15c6899
Apply suggestions from code review
ng-gsmk Jan 26, 2026
4f83ebe
Fix outstanding code review issues
ng-gsmk Jan 26, 2026
6afd836
remove whitespace in mbedtls_ssl_session_msg_layer
ng-gsmk Jan 26, 2026
8a3bcb1
Fix coding style conventions for mbedtls_ssl_context
ng-gsmk Jan 26, 2026
fb317af
library: ssl: rework macro to define known TLS ID <-> group name list
valeriosetti Jan 26, 2026
bb4f584
tests: ssl: improve test_mbedtls_tls_id_group_name_table()
valeriosetti Jan 26, 2026
4f1e4fb
library: ssl: make the list of "TLS ID" <-> "group name" public when …
valeriosetti Jan 26, 2026
cc53b06
Improve changelog for alert getter
ng-gsmk Jan 27, 2026
d658f3d
tests: ssl: skip testing of MBEDTLS_SSL_IANA_TLS_GROUP_NONE
valeriosetti Jan 27, 2026
097e578
Moved tests/psa-client-server to framework.
minosgalanakis Jan 8, 2026
1c2b690
Test Makefiles: Updated location of psasim
minosgalanakis Nov 17, 2025
9b49d5d
library: ssl: fix documentation of IANA TLS group info
valeriosetti Jan 27, 2026
476a2ed
library: extend mbedtls_ssl_iana_tls_group_info_t structure
valeriosetti Jan 27, 2026
7663b9c
Updated framework pointer
minosgalanakis Jan 28, 2026
d0bff58
Merge pull request #10514 from ng-gsmk/development
davidhorstmann-arm Jan 28, 2026
068ef9c
Merge pull request #10511 from minosgalanakis/rework/move-psasim
gilles-peskine-arm Jan 28, 2026
d823908
fix: Disabling the MBEDTLS_SSL_CLI_C feature caused a compilation err…
okning Jan 26, 2026
4987340
fix code style in ssl_msg.c and add signoff
okning Jan 28, 2026
75eec4b
Merge pull request #10577 from h1wind/patch-1
mpg Jan 29, 2026
7bba265
Add link to TF-PSA-Crypto SECURITY.md
davidhorstmann-arm Jan 30, 2026
8b1d9e4
Reword to be more specific
davidhorstmann-arm Jan 30, 2026
c3f585b
tests: ssl: fix typo in comment in test_mbedtls_ssl_get_supported_gro…
valeriosetti Jan 30, 2026
318e431
changelog: add notes about helpers added to get list of known/support…
valeriosetti Feb 2, 2026
2a72766
Merge pull request #10570 from valeriosetti/issue10349
valeriosetti Feb 3, 2026
4cce035
Remove unused variable
gilles-peskine-arm Feb 10, 2026
05d8c71
Don't treat --help as an error
gilles-peskine-arm Feb 10, 2026
d3a8582
Actually check committed generated files
gilles-peskine-arm Feb 12, 2026
384a167
library: check_config: remove redundant check on hash algorithms for …
valeriosetti Feb 11, 2026
4602f36
Merge pull request #10596 from gilles-peskine-arm/check_committed_gen…
gilles-peskine-arm Feb 12, 2026
24c80cc
Update tf-psa-crypto with mldsa-native
gilles-peskine-arm Feb 16, 2026
26e1a7c
Update framework with XOF support in psasim
gilles-peskine-arm Feb 16, 2026
bac74a0
Merge pull request #10593 from gilles-peskine-arm/bump-version-202602…
davidhorstmann-arm Feb 16, 2026
059fe77
Fix missing type conversion in the TLS-Exporter
davidhorstmann-arm Feb 16, 2026
4398e83
Merge pull request #10600 from gilles-peskine-arm/update-submodules-2…
valeriosetti Feb 17, 2026
3f2a8b0
Merge pull request #10601 from davidhorstmann-arm/fix-missing-type-co…
davidhorstmann-arm Feb 17, 2026
29eb988
Update framework pointer
ronald-cron-arm Jan 14, 2026
57b29c2
Introduce branch specific make_generated_files.py
ronald-cron-arm Jan 20, 2026
1b5a0b1
Add branch specific generate_tls_handshake_tests.py file
ronald-cron-arm Jan 20, 2026
8ab1440
ssl_server2.c: Flush stdout to improve logs timeliness
ronald-cron-arm Jan 29, 2026
86b7df5
ssl_tls.c: Rename and expand ssl_tls13_get_hs_msg_name
ronald-cron-arm Feb 3, 2026
7fe38dd
ssl_msg.c: Improve HS message reassembly completed message
ronald-cron-arm Feb 3, 2026
8f0240c
ssl-opt.sh: Remove CH reassembly unsupported test
ronald-cron-arm Jan 14, 2026
cad9c8a
ssl-opt.sh: Remove DTLS reassembly redundant test
ronald-cron-arm Feb 3, 2026
addf640
ssl-opt.sh: Improve DTLS reassembly tests
ronald-cron-arm Feb 3, 2026
b952ba0
ssl-opt.sh: Improve DTLS proxy 3d tests
ronald-cron-arm Feb 3, 2026
4f07414
ssl_msg.c: Improve handshake message fragmenting message
ronald-cron-arm Feb 3, 2026
076ddc3
tests: cmake: Fix dependency on generate_tls_handshake_tests.py
ronald-cron-arm Feb 13, 2026
73be048
ssl-opt.sh: Revert leftover debug level increase
ronald-cron-arm Feb 13, 2026
86eac79
Have MBEDTLS_TIMING_C require MBEDTLS_HAVE_TIME
gilles-peskine-arm Feb 19, 2026
137b5b7
Simplify MBEDTLS_TIMING_C to use mbedtls_ms_time()
gilles-peskine-arm Feb 18, 2026
7ea3182
Fix build error when MBEDTLS_TIMING_C and MBEDTLS_HAVE_TIME are both …
gilles-peskine-arm Feb 19, 2026
5890b22
Fix a build error with MSVC
gilles-peskine-arm Feb 19, 2026
e2b04b6
Don't use printf("%llu")
gilles-peskine-arm Feb 19, 2026
ed642ca
Fix inclusion of <time.h> when MBEDTLS_HAVE_TIME is disabled
gilles-peskine-arm Feb 19, 2026
3b49842
Merge pull request #10595 from valeriosetti/fix-tls12-sha-guards
valeriosetti Feb 20, 2026
d507b46
Remove DriverVsReference tasks from analyze_outcomes.py
Feb 19, 2026
f004998
Add issue number
gilles-peskine-arm Feb 21, 2026
99c4159
Disable Unix-like integration code in baremetal builds in all.sh
gilles-peskine-arm Feb 21, 2026
bbf8bbb
Merge pull request #10575 from ronald-cron-arm/dtls-client-hello-defr…
bensze01 Feb 22, 2026
b41c8f6
Merge pull request #10608 from bjwtaylor/DriverVsReference_removal
valeriosetti Feb 23, 2026
9394d25
Merge pull request #10584 from davidhorstmann-arm/add-link-to-crypto-…
yanesca Feb 24, 2026
c2cb856
Merge pull request #10607 from gilles-peskine-arm/timing-use-mstime
bensze01 Feb 26, 2026
7e011cc
Move some scripts from mbedtls into the framework
gilles-peskine-arm Mar 3, 2026
7dffa35
Merge branch 'tmp-branch-move-files-to-framework' into audit_validity…
gilles-peskine-arm Mar 3, 2026
731ff38
Merge remote-tracking branch 'main' into audit_validity_dates-move-fr…
gilles-peskine-arm Mar 9, 2026
7221529
Add requirements in the framework for scripts in the framework
gilles-peskine-arm Feb 26, 2026
7bc3cdf
Update paths after moving some scripts to the framework
gilles-peskine-arm Feb 26, 2026
d393ebd
Fix cosmetic issues reported by pylint
gilles-peskine-arm Mar 2, 2026
c77ecf0
Fix or silence minor issues reported by pylint
gilles-peskine-arm Mar 2, 2026
95367db
Remove temporary code from the tf-psa-crypto split
gilles-peskine-arm Mar 2, 2026
345b13a
Run pylint and mypy on all files in mbedtls_framework
gilles-peskine-arm Mar 2, 2026
c5135a0
Add pylint duplicate-code exceptions for newly moved files
gilles-peskine-arm Mar 2, 2026
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
468 changes: 468 additions & 0 deletions scripts/audit-validity-dates.py

Large diffs are not rendered by default.

31 changes: 20 additions & 11 deletions scripts/check-python-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,39 @@ elif [ "$1" = "--can-mypy" ]; then
fi

echo 'Running pylint ...'
# Temporary workaround while moving the bulk of abi_check.py to the framework
# Check abi_check.py separately from the rest of the files, so it's not flagged
# for code duplication.
# Temporary workaround for the transitional wrapper framework/scripts/make_generated_files.py
# as well. Once make_generated_files.py exists in both MbedTLS:development and
# TF-PSA-Crypto:development branches, we will be able to remove
# framework/scripts/make_generated_files.py and, consequently, this exception.
find framework/scripts/*.py framework/scripts/mbedtls_framework/*.py scripts/*.py tests/scripts/*.py \
# When we move Python code between repositories, there is a transition
# period during which code is duplicated between the old repository and
# the new repository.
# Pylint looks for duplicate code inside files that are mentioned in the
# same invocation. When we move some code from A to B, we want to skip
# duplicate-code checks between A and B. So we arrange for two separate
# runs of pylint: one for the A files, and one for the others.
# Remove exceptions below once the A file (or the moved code in the A file)
# has been removed from all consuming branches.
find framework/scripts scripts tests/scripts -name '*.py' \( \
! -path scripts/abi_check.py \
! -path scripts/code_size_compare.py \
! -path scripts/ecp_comb_table.py \
! -path tests/scripts/audit-validity-dates.py \
! -path tests/scripts/generate_server9_bad_saltlen.py \
! -path tests/scripts/psa_collect_statuses.py \
! -path tests/scripts/run_demos.py \
! -path tests/scripts/test_config_script.py \
! -path framework/scripts/make_generated_files.py \
-exec $PYTHON -m pylint {} + \
-o -exec $PYTHON -m pylint {} + || {
-o -exec $PYTHON -m pylint {} + \) || {
echo >&2 "pylint reported errors"
ret=1
}

echo
echo 'Running mypy ...'
$PYTHON -m mypy framework/scripts/*.py framework/scripts/mbedtls_framework/*.py || {
$PYTHON -m mypy framework/scripts || {
echo >&2 "mypy reported errors in the framework"
ret=1
}

$PYTHON -m mypy scripts/*.py tests/scripts/*.py || {
$PYTHON -m mypy scripts tests/scripts || {
echo >&2 "mypy reported errors in the parent repository"
ret=1
}
Expand Down
11 changes: 11 additions & 0 deletions scripts/ci.requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Python package requirements for Mbed TLS testing.

# At the time of writing, only needed for scripts/audit-validity-dates.py.
# It needs >=35.0.0 for correct operation, and that requires Python >=3.6.
# >=35.0.0 also requires Rust to build from source, which we are forced to do on
# FreeBSD, since PyPI doesn't carry binary wheels for the BSDs.
cryptography >= 35.0.0; platform_system == 'Linux'

# At the time of writing, only needed for
# scripts/generate_server9_bad_saltlen.py.
asn1crypto; platform_system == 'Linux'
237 changes: 237 additions & 0 deletions scripts/ecp_comb_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
#!/usr/bin/env python3
"""
Purpose

This script dumps comb table of ec curve. When you add a new ec curve, you
can use this script to generate codes to define `<curve>_T` in ecp_curves.c
"""

# Copyright The Mbed TLS Contributors
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later

import os
import subprocess
import sys
import tempfile

HOW_TO_ADD_NEW_CURVE = """
If you are trying to add new curve, you can follow these steps:

1. Define curve parameters (<curve>_p, <curve>_gx, etc...) in ecp_curves.c.
2. Add a macro to define <curve>_T to NULL following these parameters.
3. Build mbedcrypto
4. Run this script with an argument of new curve
5. Copy the output of this script into ecp_curves.c and replace the macro added
in Step 2
6. Rebuild and test if everything is ok

Replace the <curve> in the above with the name of the curve you want to add."""

CC = os.getenv('CC', 'cc')
MBEDTLS_LIBRARY_PATH = os.getenv('MBEDTLS_LIBRARY_PATH', "library")

SRC_DUMP_COMB_TABLE = r'''
#include <stdio.h>
#include <stdlib.h>
#include "mbedtls/ecp.h"
#include "mbedtls/error.h"

static void dump_mpi_initialize( const char *name, const mbedtls_mpi *d )
{
uint8_t buf[128] = {0};
size_t olen;
uint8_t *p;

olen = mbedtls_mpi_size( d );
mbedtls_mpi_write_binary_le( d, buf, olen );
printf("static const mbedtls_mpi_uint %s[] = {\n", name);
for (p = buf; p < buf + olen; p += 8) {
printf( " BYTES_TO_T_UINT_8( 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X ),\n",
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7] );
}
printf("};\n");
}

static void dump_T( const mbedtls_ecp_group *grp )
{
char name[128];

printf( "#if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1\n" );

for (size_t i = 0; i < grp->T_size; ++i) {
snprintf( name, sizeof(name), "%s_T_%zu_X", CURVE_NAME, i );
dump_mpi_initialize( name, &grp->T[i].X );

snprintf( name, sizeof(name), "%s_T_%zu_Y", CURVE_NAME, i );
dump_mpi_initialize( name, &grp->T[i].Y );
}
printf( "static const mbedtls_ecp_point %s_T[%zu] = {\n", CURVE_NAME, grp->T_size );
size_t olen;
for (size_t i = 0; i < grp->T_size; ++i) {
int z;
if ( mbedtls_mpi_cmp_int(&grp->T[i].Z, 0) == 0 ) {
z = 0;
} else if ( mbedtls_mpi_cmp_int(&grp->T[i].Z, 1) == 0 ) {
z = 1;
} else {
fprintf( stderr, "Unexpected value of Z (i = %d)\n", (int)i );
exit( 1 );
}
printf( " ECP_POINT_INIT_XY_Z%d(%s_T_%zu_X, %s_T_%zu_Y),\n",
z,
CURVE_NAME, i,
CURVE_NAME, i
);
}
printf("};\n#endif\n\n");
}

int main()
{
int rc;
mbedtls_mpi m;
mbedtls_ecp_point R;
mbedtls_ecp_group grp;

mbedtls_ecp_group_init( &grp );
rc = mbedtls_ecp_group_load( &grp, CURVE_ID );
if (rc != 0) {
char buf[100];
mbedtls_strerror( rc, buf, sizeof(buf) );
fprintf( stderr, "mbedtls_ecp_group_load: %s (-0x%x)\n", buf, -rc );
return 1;
}
grp.T = NULL;
mbedtls_ecp_point_init( &R );
mbedtls_mpi_init( &m);
mbedtls_mpi_lset( &m, 1 );
rc = mbedtls_ecp_mul( &grp, &R, &m, &grp.G, NULL, NULL );
if ( rc != 0 ) {
char buf[100];
mbedtls_strerror( rc, buf, sizeof(buf) );
fprintf( stderr, "mbedtls_ecp_mul: %s (-0x%x)\n", buf, -rc );
return 1;
}
if ( grp.T == NULL ) {
fprintf( stderr, "grp.T is not generated. Please make sure"
"MBEDTLS_ECP_FIXED_POINT_OPTIM is enabled in mbedtls_config.h\n" );
return 1;
}
dump_T( &grp );
return 0;
}
'''

SRC_DUMP_KNOWN_CURVE = r'''
#include <stdio.h>
#include <stdlib.h>
#include "mbedtls/ecp.h"

int main() {
const mbedtls_ecp_curve_info *info = mbedtls_ecp_curve_list();
mbedtls_ecp_group grp;

mbedtls_ecp_group_init( &grp );
while ( info->name != NULL ) {
mbedtls_ecp_group_load( &grp, info->grp_id );
if ( mbedtls_ecp_get_type(&grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS ) {
printf( " %s", info->name );
}
info++;
}
printf( "\n" );
return 0;
}
'''


def join_src_path(*args):
return os.path.normpath(os.path.join(os.path.dirname(__file__), "..", *args))


def run_c_source(src, cflags):
"""
Compile and run C source code
:param src: the c language code to run
:param cflags: additional cflags passing to compiler
:return:
"""
binname = tempfile.mktemp(prefix="mbedtls")
fd, srcname = tempfile.mkstemp(prefix="mbedtls", suffix=".c")
srcfile = os.fdopen(fd, mode="w")
srcfile.write(src)
srcfile.close()
args = [CC,
*cflags,
'-I' + join_src_path("include"),
"-o", binname,
'-L' + MBEDTLS_LIBRARY_PATH,
srcname,
'-lmbedcrypto']

p = subprocess.run(args=args, check=False)
if p.returncode != 0:
return False
p = subprocess.run(args=[binname], check=False, env={
'LD_LIBRARY_PATH': MBEDTLS_LIBRARY_PATH
})
if p.returncode != 0:
return False
os.unlink(srcname)
os.unlink(binname)
return True


def compute_curve(curve):
"""compute comb table for curve"""
r = run_c_source(
SRC_DUMP_COMB_TABLE,
[
'-g',
'-DCURVE_ID=MBEDTLS_ECP_DP_%s' % curve.upper(),
'-DCURVE_NAME="%s"' % curve.lower(),
])
if not r:
print("""\
Unable to compile and run utility.""", file=sys.stderr)
sys.exit(1)


def usage():
print("""
Usage: python %s <curve>...

Arguments:
curve Specify one or more curve names (e.g secp256r1)

All possible curves: """ % sys.argv[0])
run_c_source(SRC_DUMP_KNOWN_CURVE, [])
print("""
Environment Variable:
CC Specify which c compile to use to compile utility.
MBEDTLS_LIBRARY_PATH
Specify the path to mbedcrypto library. (e.g. build/library/)

How to add a new curve: %s""" % HOW_TO_ADD_NEW_CURVE)


def run_main():
shared_lib_path = os.path.normpath(os.path.join(MBEDTLS_LIBRARY_PATH, "libmbedcrypto.so"))
static_lib_path = os.path.normpath(os.path.join(MBEDTLS_LIBRARY_PATH, "libmbedcrypto.a"))
if not os.path.exists(shared_lib_path) and not os.path.exists(static_lib_path):
print("Warning: both '%s' and '%s' are not exists. This script will use "
"the library from your system instead of the library compiled by "
"this source directory.\n"
"You can specify library path using environment variable "
"'MBEDTLS_LIBRARY_PATH'." % (shared_lib_path, static_lib_path),
file=sys.stderr)

if len(sys.argv) <= 1:
usage()
else:
for curve in sys.argv[1:]:
compute_curve(curve)


if __name__ == '__main__':
run_main()
96 changes: 96 additions & 0 deletions scripts/gen_ctr_drbg.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env perl
#
# Based on NIST CTR_DRBG.rsp validation file
# Only uses AES-256-CTR cases that use a Derivation function
# and concats nonce and personalization for initialization.
#
# Copyright The Mbed TLS Contributors
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later

use strict;

my $file = shift;

open(TEST_DATA, "$file") or die "Opening test cases '$file': $!";

sub get_suite_val($)
{
my $name = shift;
my $val = "";

my $line = <TEST_DATA>;
($val) = ($line =~ /\[$name\s\=\s(\w+)\]/);

return $val;
}

sub get_val($)
{
my $name = shift;
my $val = "";
my $line;

while($line = <TEST_DATA>)
{
next if($line !~ /=/);
last;
}

($val) = ($line =~ /^$name = (\w+)/);

return $val;
}

my $cnt = 1;;
while (my $line = <TEST_DATA>)
{
next if ($line !~ /^\[AES-256 use df/);

my $PredictionResistanceStr = get_suite_val("PredictionResistance");
my $PredictionResistance = 0;
$PredictionResistance = 1 if ($PredictionResistanceStr eq 'True');
my $EntropyInputLen = get_suite_val("EntropyInputLen");
my $NonceLen = get_suite_val("NonceLen");
my $PersonalizationStringLen = get_suite_val("PersonalizationStringLen");
my $AdditionalInputLen = get_suite_val("AdditionalInputLen");

for ($cnt = 0; $cnt < 15; $cnt++)
{
my $Count = get_val("COUNT");
my $EntropyInput = get_val("EntropyInput");
my $Nonce = get_val("Nonce");
my $PersonalizationString = get_val("PersonalizationString");
my $AdditionalInput1 = get_val("AdditionalInput");
my $EntropyInputPR1 = get_val("EntropyInputPR") if ($PredictionResistance == 1);
my $EntropyInputReseed = get_val("EntropyInputReseed") if ($PredictionResistance == 0);
my $AdditionalInputReseed = get_val("AdditionalInputReseed") if ($PredictionResistance == 0);
my $AdditionalInput2 = get_val("AdditionalInput");
my $EntropyInputPR2 = get_val("EntropyInputPR") if ($PredictionResistance == 1);
my $ReturnedBits = get_val("ReturnedBits");

if ($PredictionResistance == 1)
{
print("CTR_DRBG NIST Validation (AES-256 use df,$PredictionResistanceStr,$EntropyInputLen,$NonceLen,$PersonalizationStringLen,$AdditionalInputLen) #$Count\n");
print("ctr_drbg_validate_pr");
print(":\"$Nonce$PersonalizationString\"");
print(":\"$EntropyInput$EntropyInputPR1$EntropyInputPR2\"");
print(":\"$AdditionalInput1\"");
print(":\"$AdditionalInput2\"");
print(":\"$ReturnedBits\"");
print("\n\n");
}
else
{
print("CTR_DRBG NIST Validation (AES-256 use df,$PredictionResistanceStr,$EntropyInputLen,$NonceLen,$PersonalizationStringLen,$AdditionalInputLen) #$Count\n");
print("ctr_drbg_validate_nopr");
print(":\"$Nonce$PersonalizationString\"");
print(":\"$EntropyInput$EntropyInputReseed\"");
print(":\"$AdditionalInput1\"");
print(":\"$AdditionalInputReseed\"");
print(":\"$AdditionalInput2\"");
print(":\"$ReturnedBits\"");
print("\n\n");
}
}
}
close(TEST_DATA);
Loading