Skip to content

Commit 8c412ed

Browse files
author
Krzysztof Stachowiak
committed
Resolve compiler and linker issues in MD APIs
The features/mbedtls/targets/TARGET_STM/* files include constant needed for the error codes returned from the MD functions. The features/mbedtls/targets/hash_wrappers.c provides thin redirection layer for the hardware accelerated MD implementations that rely on the old API. The TESTS/mbedtls/multi/main.cpp has been changed to use the new API as its build environment does not rely on the translation unit containing the necessary wrappers.
1 parent 256e1de commit 8c412ed

File tree

5 files changed

+409
-16
lines changed

5 files changed

+409
-16
lines changed

TESTS/mbedtls/multi/main.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#include "mbedtls/sha256.h"
2525

26-
2726
using namespace utest::v1;
2827

2928
#if defined(MBEDTLS_SHA256_C)
@@ -42,18 +41,18 @@ void test_case_sha256_split() {
4241
mbedtls_sha256_context ctx;
4342
printf("test sha256\n");
4443
mbedtls_sha256_init( &ctx );
45-
mbedtls_sha256_starts( &ctx, 0);
44+
mbedtls_sha256_starts_ret( &ctx, 0);
4645
#if 0
4746
printf("test not splitted\n");
4847
mbedtls_sha256_update( &ctx, test_buf, 168 );
4948
#else
5049
printf("test splitted into 3 pieces\n");
51-
mbedtls_sha256_update( &ctx, test_buf, 2 );
52-
mbedtls_sha256_update( &ctx, test_buf+2, 66 );
53-
mbedtls_sha256_update( &ctx, test_buf+68, 100 );
50+
mbedtls_sha256_update_ret( &ctx, test_buf, 2 );
51+
mbedtls_sha256_update_ret( &ctx, test_buf+2, 66 );
52+
mbedtls_sha256_update_ret( &ctx, test_buf+68, 100 );
5453
#endif
5554

56-
mbedtls_sha256_finish( &ctx, outsum );
55+
mbedtls_sha256_finish_ret( &ctx, outsum );
5756
mbedtls_sha256_free( &ctx );
5857

5958
printf("\nreceived result : ");
@@ -99,29 +98,29 @@ void test_case_sha256_multi() {
9998
mbedtls_sha256_init( &ctx2);
10099
mbedtls_sha256_init( &ctx3);
101100
//Start both contexts
102-
mbedtls_sha256_starts( &ctx1, 0);
103-
mbedtls_sha256_starts( &ctx2, 0);
101+
mbedtls_sha256_starts_ret( &ctx1, 0);
102+
mbedtls_sha256_starts_ret( &ctx2, 0);
104103

105104
printf("upd ctx1\n");
106-
mbedtls_sha256_update( &ctx1, test_buf, 56 );
105+
mbedtls_sha256_update_ret( &ctx1, test_buf, 56 );
107106
printf("upd ctx2\n");
108-
mbedtls_sha256_update( &ctx2, test_buf, 66 );
107+
mbedtls_sha256_update_ret( &ctx2, test_buf, 66 );
109108
printf("finish ctx1\n");
110-
mbedtls_sha256_finish( &ctx1, outsum1 );
109+
mbedtls_sha256_finish_ret( &ctx1, outsum1 );
111110
printf("upd ctx2\n");
112-
mbedtls_sha256_update( &ctx2, test_buf+66, 46 );
111+
mbedtls_sha256_update_ret( &ctx2, test_buf+66, 46 );
113112
printf("clone ctx2 in ctx3\n");
114113
mbedtls_sha256_clone(&ctx3, (const mbedtls_sha256_context *)&ctx2);
115114
printf("free ctx1\n");
116115
mbedtls_sha256_free( &ctx1 );
117116
printf("upd ctx2\n");
118-
mbedtls_sha256_update( &ctx2, test_buf+112, 56 );
117+
mbedtls_sha256_update_ret( &ctx2, test_buf+112, 56 );
119118
printf("upd ctx3 with different values than ctx2\n");
120-
mbedtls_sha256_update( &ctx3, test_buf2, 56 );
119+
mbedtls_sha256_update_ret( &ctx3, test_buf2, 56 );
121120
printf("finish ctx2\n");
122-
mbedtls_sha256_finish( &ctx2, outsum2 );
121+
mbedtls_sha256_finish_ret( &ctx2, outsum2 );
123122
printf("finish ctx3\n");
124-
mbedtls_sha256_finish( &ctx3, outsum3 );
123+
mbedtls_sha256_finish_ret( &ctx3, outsum3 );
125124
printf("free ctx2\n");
126125
mbedtls_sha256_free( &ctx2 );
127126
printf("free ctx3\n");

features/mbedtls/targets/TARGET_STM/md5_alt.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@
2727
#include "cmsis.h"
2828
#include <string.h>
2929

30+
/**
31+
* \name SECTION: Temporary compatibility code
32+
*
33+
* This section contains code to be added up stream in Mbed TLS. Once that
34+
* has been provided, this section should be removed as the code will be
35+
* provided elsewhere.
36+
* \{
37+
*/
38+
39+
#define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */
40+
41+
/* \} name SECTION: Temporary compatibility code */
42+
3043
#ifdef __cplusplus
3144
extern "C" {
3245
#endif

features/mbedtls/targets/TARGET_STM/sha1_alt.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@
2424

2525
#if defined (MBEDTLS_SHA1_ALT)
2626

27+
/**
28+
* \name SECTION: Temporary compatibility code
29+
*
30+
* This section contains code to be added up stream in Mbed TLS. Once that
31+
* has been provided, this section should be removed as the code will be
32+
* provided elsewhere.
33+
* \{
34+
*/
35+
36+
#define MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED -0x0035 /**< SHA-1 hardware accelerator failed */
37+
38+
/* \} name SECTION: Temporary compatibility code */
2739

2840
#include "cmsis.h"
2941
#include <string.h>

features/mbedtls/targets/TARGET_STM/sha256_alt.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@
2727
#include "cmsis.h"
2828
#include <string.h>
2929

30+
/**
31+
* \name SECTION: Temporary compatibility code
32+
*
33+
* This section contains code to be added up stream in Mbed TLS. Once that
34+
* has been provided, this section should be removed as the code will be
35+
* provided elsewhere.
36+
* \{
37+
*/
38+
39+
#define MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED -0x0037 /**< SHA-256 hardware accelerator failed */
40+
41+
/* \} name SECTION: Temporary compatibility code */
42+
3043
#ifdef __cplusplus
3144
extern "C" {
3245
#endif

0 commit comments

Comments
 (0)