Skip to content

Commit

Permalink
Merge pull request #6931 from AndrzejKurek/timeless-selftest-waz-bad
Browse files Browse the repository at this point in the history
[2.28] Enable the timing.c selftest with MBEDTLS_TIMING_ALT
  • Loading branch information
gilles-peskine-arm authored Jan 26, 2023
2 parents 0f16ce0 + 26d3839 commit f57f3db
Show file tree
Hide file tree
Showing 6 changed files with 508 additions and 4 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.d/fix_timing_alt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix
* Fix a build issue when defining MBEDTLS_TIMING_ALT and MBEDTLS_SELF_TEST.
The library would not link if the user didn't provide an external self-test
function. The self-test is now provided regardless of the choice of
internal/alternative timing implementation. Fixes #6923.
7 changes: 7 additions & 0 deletions library/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ else
all: shared static
endif

ifdef TEST_TIMING_ALT_IMPL
OBJS_CRYPTO += external_timing_for_test.o
external_timing_for_test.o: ../tests/src/external_timing/external_timing_for_test.c
echo " CC $<"
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $<
endif

static: libmbedcrypto.a libmbedx509.a libmbedtls.a
cd ../tests && echo "This is a seedfile that contains 64 bytes (65 on Windows)......" > seedfile

Expand Down
6 changes: 2 additions & 4 deletions library/timing.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ int mbedtls_timing_get_delay(void *data)
return 0;
}

#endif /* !MBEDTLS_TIMING_ALT */

#if defined(MBEDTLS_SELF_TEST)

/*
* Busy-waits for the given number of milliseconds.
* Used for testing mbedtls_timing_hardclock.
Expand Down Expand Up @@ -383,9 +383,8 @@ static void busy_msleep(unsigned long msec)
mbedtls_printf(" cycles=%lu ratio=%lu millisecs=%lu secs=%lu hardfail=%d a=%lu b=%lu\n", \
cycles, ratio, millisecs, secs, hardfail, \
(unsigned long) a, (unsigned long) b); \
mbedtls_printf(" elapsed(hires)=%lu elapsed(ctx)=%lu status(ctx)=%d\n", \
mbedtls_printf(" elapsed(hires)=%lu status(ctx)=%d\n", \
mbedtls_timing_get_timer(&hires, 0), \
mbedtls_timing_get_timer(&ctx.timer, 0), \
mbedtls_timing_get_delay(&ctx)); \
} \
return 1; \
Expand Down Expand Up @@ -526,5 +525,4 @@ int mbedtls_timing_self_test(int verbose)
}

#endif /* MBEDTLS_SELF_TEST */
#endif /* !MBEDTLS_TIMING_ALT */
#endif /* MBEDTLS_TIMING_C */
13 changes: 13 additions & 0 deletions tests/scripts/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2728,6 +2728,19 @@ component_test_no_date_time () {
make test
}

component_test_alt_timing() {
msg "build: alternate timing implementation"
scripts/config.py set MBEDTLS_TIMING_ALT
make lib TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"

msg "test: MBEDTLS_TIMING_ALT - test suites"
make test TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"

msg "selftest - MBEDTLS-TIMING_ALT"
make programs TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../../tests/src/external_timing -I../tests/src/external_timing"
programs/test/selftest
}

component_test_platform_calloc_macro () {
msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Expand Down
Loading

0 comments on commit f57f3db

Please sign in to comment.