Skip to content

Commit 06b6184

Browse files
authored
Merge pull request #5973 from k-stachowiak/IOTSSL-1727-update-to-new-md-api
Update Mbed TLS HW acceleration partner code to new hashing API
2 parents 975b940 + 2e9243f commit 06b6184

File tree

21 files changed

+725
-133
lines changed

21 files changed

+725
-133
lines changed

TESTS/mbedtls/multi/main.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,67 @@
2323

2424
#include "mbedtls/sha256.h"
2525

26+
/**
27+
* \name SECTION: Compatibility code
28+
*
29+
* Depending on whether the alternative (hatdware accelerated) hashing
30+
* functions are provided or not, different API should be used for hashing.
31+
* \{
32+
*/
33+
34+
#if defined(MBEDTLS_SHA256_ALT)
35+
36+
/**
37+
* \brief This function starts a SHA-256 checksum calculation.
38+
*
39+
* \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0.
40+
*
41+
* \param ctx The SHA-256 context to initialize.
42+
* \param is224 Determines which function to use.
43+
* <ul><li>0: Use SHA-256.</li>
44+
* <li>1: Use SHA-224.</li></ul>
45+
*/
46+
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
47+
int is224 )
48+
{
49+
mbedtls_sha256_starts_ret( ctx, is224 );
50+
}
51+
52+
/**
53+
* \brief This function feeds an input buffer into an ongoing
54+
* SHA-256 checksum calculation.
55+
*
56+
* \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0.
57+
*
58+
* \param ctx The SHA-256 context to initialize.
59+
* \param input The buffer holding the data.
60+
* \param ilen The length of the input data.
61+
*/
62+
void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
63+
const unsigned char *input,
64+
size_t ilen )
65+
{
66+
mbedtls_sha256_update_ret( ctx, input, ilen );
67+
}
68+
69+
/**
70+
* \brief This function finishes the SHA-256 operation, and writes
71+
* the result to the output buffer.
72+
*
73+
* \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0.
74+
*
75+
* \param ctx The SHA-256 context.
76+
* \param output The SHA-224or SHA-256 checksum result.
77+
*/
78+
void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
79+
unsigned char output[32] )
80+
{
81+
mbedtls_sha256_finish_ret( ctx, output );
82+
}
83+
84+
#endif /* defined(MBEDTLS_SHA256_ALT) */
85+
86+
/* \} name SECTION: Compatibility code */
2687

2788
using namespace utest::v1;
2889

features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/sha/sha1_alt.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,37 +103,40 @@ void mbedtls_sha1_clone(mbedtls_sha1_context *dst,
103103
/*
104104
* SHA-1 context setup
105105
*/
106-
void mbedtls_sha1_starts(mbedtls_sha1_context *ctx)
106+
int mbedtls_sha1_starts_ret(mbedtls_sha1_context *ctx)
107107
{
108108
if (ctx->active_ctx == &ctx->hw_ctx) {
109109
mbedtls_sha1_hw_starts(&ctx->hw_ctx);
110110
} else if (ctx->active_ctx == &ctx->sw_ctx) {
111111
mbedtls_sha1_sw_starts(&ctx->sw_ctx);
112112
}
113+
return 0;
113114
}
114115

115116
/*
116117
* SHA-1 process buffer
117118
*/
118-
void mbedtls_sha1_update(mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen)
119+
int mbedtls_sha1_update_ret(mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen)
119120
{
120121
if (ctx->active_ctx == &ctx->hw_ctx) {
121122
mbedtls_sha1_hw_update(&ctx->hw_ctx, input, ilen);
122123
} else if (ctx->active_ctx == &ctx->sw_ctx) {
123124
mbedtls_sha1_sw_update(&ctx->sw_ctx, input, ilen);
124125
}
126+
return 0;
125127
}
126128

127129
/*
128130
* SHA-1 final digest
129131
*/
130-
void mbedtls_sha1_finish(mbedtls_sha1_context *ctx, unsigned char output[20])
132+
int mbedtls_sha1_finish_ret(mbedtls_sha1_context *ctx, unsigned char output[20])
131133
{
132134
if (ctx->active_ctx == &ctx->hw_ctx) {
133135
mbedtls_sha1_hw_finish(&ctx->hw_ctx, output);
134136
} else if (ctx->active_ctx == &ctx->sw_ctx) {
135137
mbedtls_sha1_sw_finish(&ctx->sw_ctx, output);
136138
}
139+
return 0;
137140
}
138141

139142
void mbedtls_sha1_process(mbedtls_sha1_context *ctx, const unsigned char data[64])

features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/sha/sha1_alt.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,31 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
6666
* \brief SHA-1 context setup
6767
*
6868
* \param ctx context to be initialized
69+
*
70+
* \return 0 if successful
6971
*/
70-
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
72+
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
7173

7274
/**
7375
* \brief SHA-1 process buffer
7476
*
7577
* \param ctx SHA-1 context
7678
* \param input buffer holding the data
7779
* \param ilen length of the input data
80+
*
81+
* \return 0 if successful
7882
*/
79-
void mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
83+
int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
8084

8185
/**
8286
* \brief SHA-1 final digest
8387
*
8488
* \param ctx SHA-1 context
8589
* \param output SHA-1 checksum result
90+
*
91+
* \return 0 if successful
8692
*/
87-
void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] );
93+
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx, unsigned char output[20] );
8894

8995
/* Internal use */
9096
void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[64] );

features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/sha/sha256_alt.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,37 +104,40 @@ void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
104104
/*
105105
* SHA-256 context setup
106106
*/
107-
void mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224)
107+
int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224)
108108
{
109109
if (ctx->active_ctx == &ctx->hw_ctx) {
110110
mbedtls_sha256_hw_starts(&ctx->hw_ctx, is224);
111111
} else if (ctx->active_ctx == &ctx->sw_ctx) {
112112
mbedtls_sha256_sw_starts(&ctx->sw_ctx, is224);
113113
}
114+
return 0;
114115
}
115116

116117
/*
117118
* SHA-256 process buffer
118119
*/
119-
void mbedtls_sha256_update(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen)
120+
int mbedtls_sha256_update_ret(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen)
120121
{
121122
if (ctx->active_ctx == &ctx->hw_ctx) {
122123
mbedtls_sha256_hw_update(&ctx->hw_ctx, input, ilen);
123124
} else if (ctx->active_ctx == &ctx->sw_ctx) {
124125
mbedtls_sha256_sw_update(&ctx->sw_ctx, input, ilen);
125126
}
127+
return 0;
126128
}
127129

128130
/*
129131
* SHA-256 final digest
130132
*/
131-
void mbedtls_sha256_finish(mbedtls_sha256_context *ctx, unsigned char output[32])
133+
int mbedtls_sha256_finish_ret(mbedtls_sha256_context *ctx, unsigned char output[32])
132134
{
133135
if (ctx->active_ctx == &ctx->hw_ctx) {
134136
mbedtls_sha256_hw_finish(&ctx->hw_ctx, output);
135137
} else if (ctx->active_ctx == &ctx->sw_ctx) {
136138
mbedtls_sha256_sw_finish(&ctx->sw_ctx, output);
137139
}
140+
return 0;
138141
}
139142

140143
void mbedtls_sha256_process(mbedtls_sha256_context *ctx, const unsigned char data[64])

features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/sha/sha256_alt.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,32 @@ void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
6767
*
6868
* \param ctx context to be initialized
6969
* \param is224 0 = use SHA256, 1 = use SHA224
70+
*
71+
* \return 0 if successful
7072
*/
71-
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 );
73+
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
7274

7375
/**
7476
* \brief SHA-256 process buffer
7577
*
7678
* \param ctx SHA-256 context
7779
* \param input buffer holding the data
7880
* \param ilen length of the input data
81+
*
82+
* \return 0 if successful
7983
*/
80-
void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *input,
81-
size_t ilen );
84+
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char *input,
85+
size_t ilen );
8286

8387
/**
8488
* \brief SHA-256 final digest
8589
*
8690
* \param ctx SHA-256 context
8791
* \param output SHA-224/256 checksum result
92+
*
93+
* \return 0 if successful
8894
*/
89-
void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32] );
95+
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32] );
9096

9197
/* Internal use */
9298
void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[64] );

features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/sha/sha512_alt.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,37 +105,40 @@ void mbedtls_sha512_clone(mbedtls_sha512_context *dst,
105105
/*
106106
* SHA-512 context setup
107107
*/
108-
void mbedtls_sha512_starts(mbedtls_sha512_context *ctx, int is384)
108+
int mbedtls_sha512_starts_ret(mbedtls_sha512_context *ctx, int is384)
109109
{
110110
if (ctx->active_ctx == &ctx->hw_ctx) {
111111
mbedtls_sha512_hw_starts(&ctx->hw_ctx, is384);
112112
} else if (ctx->active_ctx == &ctx->sw_ctx) {
113113
mbedtls_sha512_sw_starts(&ctx->sw_ctx, is384);
114114
}
115+
return 0;
115116
}
116117

117118
/*
118119
* SHA-512 process buffer
119120
*/
120-
void mbedtls_sha512_update(mbedtls_sha512_context *ctx, const unsigned char *input, size_t ilen)
121+
int mbedtls_sha512_update_ret(mbedtls_sha512_context *ctx, const unsigned char *input, size_t ilen)
121122
{
122123
if (ctx->active_ctx == &ctx->hw_ctx) {
123124
mbedtls_sha512_hw_update(&ctx->hw_ctx, input, ilen);
124125
} else if (ctx->active_ctx == &ctx->sw_ctx) {
125126
mbedtls_sha512_sw_update(&ctx->sw_ctx, input, ilen);
126127
}
128+
return 0;
127129
}
128130

129131
/*
130132
* SHA-512 final digest
131133
*/
132-
void mbedtls_sha512_finish(mbedtls_sha512_context *ctx, unsigned char output[64])
134+
int mbedtls_sha512_finish_ret(mbedtls_sha512_context *ctx, unsigned char output[64])
133135
{
134136
if (ctx->active_ctx == &ctx->hw_ctx) {
135137
mbedtls_sha512_hw_finish(&ctx->hw_ctx, output);
136138
} else if (ctx->active_ctx == &ctx->sw_ctx) {
137139
mbedtls_sha512_sw_finish(&ctx->sw_ctx, output);
138140
}
141+
return 0;
139142
}
140143

141144
void mbedtls_sha512_process(mbedtls_sha512_context *ctx, const unsigned char data[128])

features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/sha/sha512_alt.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,32 @@ void mbedtls_sha512_clone( mbedtls_sha512_context *dst,
6767
*
6868
* \param ctx context to be initialized
6969
* \param is384 0 = use SHA512, 1 = use SHA384
70+
*
71+
* \return 0 if successful
7072
*/
71-
void mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 );
73+
int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 );
7274

7375
/**
7476
* \brief SHA-512 process buffer
7577
*
7678
* \param ctx SHA-512 context
7779
* \param input buffer holding the data
7880
* \param ilen length of the input data
81+
*
82+
* \return 0 if successful
7983
*/
80-
void mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *input,
81-
size_t ilen );
84+
int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx, const unsigned char *input,
85+
size_t ilen );
8286

8387
/**
8488
* \brief SHA-512 final digest
8589
*
8690
* \param ctx SHA-512 context
8791
* \param output SHA-384/512 checksum result
92+
*
93+
* \return 0 if successful
8894
*/
89-
void mbedtls_sha512_finish( mbedtls_sha512_context *ctx, unsigned char output[64] );
95+
int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx, unsigned char output[64] );
9096

9197
/* Internal use */
9298
void mbedtls_sha512_process( mbedtls_sha512_context *ctx, const unsigned char data[128] );

features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/sha/sha1_alt.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,37 +103,40 @@ void mbedtls_sha1_clone(mbedtls_sha1_context *dst,
103103
/*
104104
* SHA-1 context setup
105105
*/
106-
void mbedtls_sha1_starts(mbedtls_sha1_context *ctx)
106+
int mbedtls_sha1_starts_ret(mbedtls_sha1_context *ctx)
107107
{
108108
if (ctx->active_ctx == &ctx->hw_ctx) {
109109
mbedtls_sha1_hw_starts(&ctx->hw_ctx);
110110
} else if (ctx->active_ctx == &ctx->sw_ctx) {
111111
mbedtls_sha1_sw_starts(&ctx->sw_ctx);
112112
}
113+
return 0;
113114
}
114115

115116
/*
116117
* SHA-1 process buffer
117118
*/
118-
void mbedtls_sha1_update(mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen)
119+
int mbedtls_sha1_update_ret(mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen)
119120
{
120121
if (ctx->active_ctx == &ctx->hw_ctx) {
121122
mbedtls_sha1_hw_update(&ctx->hw_ctx, input, ilen);
122123
} else if (ctx->active_ctx == &ctx->sw_ctx) {
123124
mbedtls_sha1_sw_update(&ctx->sw_ctx, input, ilen);
124125
}
126+
return 0;
125127
}
126128

127129
/*
128130
* SHA-1 final digest
129131
*/
130-
void mbedtls_sha1_finish(mbedtls_sha1_context *ctx, unsigned char output[20])
132+
int mbedtls_sha1_finish_ret(mbedtls_sha1_context *ctx, unsigned char output[20])
131133
{
132134
if (ctx->active_ctx == &ctx->hw_ctx) {
133135
mbedtls_sha1_hw_finish(&ctx->hw_ctx, output);
134136
} else if (ctx->active_ctx == &ctx->sw_ctx) {
135137
mbedtls_sha1_sw_finish(&ctx->sw_ctx, output);
136138
}
139+
return 0;
137140
}
138141

139142
void mbedtls_sha1_process(mbedtls_sha1_context *ctx, const unsigned char data[64])

features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/sha/sha1_alt.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,31 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
6666
* \brief SHA-1 context setup
6767
*
6868
* \param ctx context to be initialized
69+
*
70+
* \return 0 if successful
6971
*/
70-
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
72+
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
7173

7274
/**
7375
* \brief SHA-1 process buffer
7476
*
7577
* \param ctx SHA-1 context
7678
* \param input buffer holding the data
7779
* \param ilen length of the input data
80+
*
81+
* \return 0 if successful
7882
*/
79-
void mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
83+
int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
8084

8185
/**
8286
* \brief SHA-1 final digest
8387
*
8488
* \param ctx SHA-1 context
8589
* \param output SHA-1 checksum result
90+
*
91+
* \return 0 if successful
8692
*/
87-
void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] );
93+
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx, unsigned char output[20] );
8894

8995
/* Internal use */
9096
void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[64] );

0 commit comments

Comments
 (0)