Skip to content

Commit 9d5d60b

Browse files
committed
Adjust partner code for MD HW acceleration to new MD API
1 parent 9472750 commit 9d5d60b

File tree

20 files changed

+1338
-148
lines changed

20 files changed

+1338
-148
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,46 +103,50 @@ 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

139-
void mbedtls_sha1_process(mbedtls_sha1_context *ctx, const unsigned char data[64])
142+
int mbedtls_internal_sha1_process(mbedtls_sha1_context *ctx, const unsigned char data[64])
140143
{
141144
if (ctx->active_ctx == &ctx->hw_ctx) {
142145
mbedtls_sha1_hw_process(&ctx->hw_ctx, data);
143146
} else if (ctx->active_ctx == &ctx->sw_ctx) {
144147
mbedtls_sha1_sw_process(&ctx->sw_ctx, data);
145148
}
149+
return 0;
146150
}
147151

148152
#endif /* MBEDTLS_SHA1_ALT */

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

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,107 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
6666
* \brief SHA-1 context setup
6767
*
6868
* \param ctx context to be initialized
69+
*
70+
* \returns error code
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+
* \returns error code
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+
* \returns error code
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 */
90-
void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[64] );
96+
int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[64] );
97+
98+
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
99+
#if defined(MBEDTLS_DEPRECATED_WARNING)
100+
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
101+
#else
102+
#define MBEDTLS_DEPRECATED
103+
#endif
104+
/**
105+
* \brief SHA-1 context setup
106+
*
107+
* \deprecated Superseded by mbedtls_sha1_starts_ret() in 2.7.0
108+
*
109+
* \param ctx The SHA-1 context to be initialized.
110+
*
111+
* \warning SHA-1 is considered a weak message digest and its use
112+
* constitutes a security risk. We recommend considering
113+
* stronger message digests instead.
114+
*
115+
*/
116+
MBEDTLS_DEPRECATED void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
117+
118+
/**
119+
* \brief SHA-1 process buffer
120+
*
121+
* \deprecated Superseded by mbedtls_sha1_update_ret() in 2.7.0
122+
*
123+
* \param ctx The SHA-1 context.
124+
* \param input The buffer holding the input data.
125+
* \param ilen The length of the input data.
126+
*
127+
* \warning SHA-1 is considered a weak message digest and its use
128+
* constitutes a security risk. We recommend considering
129+
* stronger message digests instead.
130+
*
131+
*/
132+
MBEDTLS_DEPRECATED void mbedtls_sha1_update( mbedtls_sha1_context *ctx,
133+
const unsigned char *input,
134+
size_t ilen );
135+
136+
/**
137+
* \brief SHA-1 final digest
138+
*
139+
* \deprecated Superseded by mbedtls_sha1_finish_ret() in 2.7.0
140+
*
141+
* \param ctx The SHA-1 context.
142+
* \param output The SHA-1 checksum result.
143+
*
144+
* \warning SHA-1 is considered a weak message digest and its use
145+
* constitutes a security risk. We recommend considering
146+
* stronger message digests instead.
147+
*
148+
*/
149+
MBEDTLS_DEPRECATED void mbedtls_sha1_finish( mbedtls_sha1_context *ctx,
150+
unsigned char output[20] );
151+
152+
/**
153+
* \brief SHA-1 process data block (internal use only)
154+
*
155+
* \deprecated Superseded by mbedtls_internal_sha1_process() in 2.7.0
156+
*
157+
* \param ctx The SHA-1 context.
158+
* \param data The data block being processed.
159+
*
160+
* \warning SHA-1 is considered a weak message digest and its use
161+
* constitutes a security risk. We recommend considering
162+
* stronger message digests instead.
163+
*
164+
*/
165+
MBEDTLS_DEPRECATED void mbedtls_sha1_process( mbedtls_sha1_context *ctx,
166+
const unsigned char data[64] );
167+
168+
#undef MBEDTLS_DEPRECATED
169+
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
91170

92171
#ifdef __cplusplus
93172
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,46 +104,50 @@ 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

140-
void mbedtls_sha256_process(mbedtls_sha256_context *ctx, const unsigned char data[64])
143+
int mbedtls_internal_sha256_process(mbedtls_sha256_context *ctx, const unsigned char data[64])
141144
{
142145
if (ctx->active_ctx == &ctx->hw_ctx) {
143146
mbedtls_sha256_hw_process(&ctx->hw_ctx, data);
144147
} else if (ctx->active_ctx == &ctx->sw_ctx) {
145148
mbedtls_sha256_sw_process(&ctx->sw_ctx, data);
146149
}
150+
return 0;
147151
}
148152

149153
#endif /* MBEDTLS_SHA256_ALT */

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

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,96 @@ 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+
* \returns error code
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+
* \returns error code
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+
* \returns error code
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 */
92-
void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[64] );
98+
int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[64] );
99+
100+
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
101+
#if defined(MBEDTLS_DEPRECATED_WARNING)
102+
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
103+
#else
104+
#define MBEDTLS_DEPRECATED
105+
#endif
106+
/**
107+
* \brief This function starts a SHA-256 checksum calculation.
108+
*
109+
* \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0.
110+
*
111+
* \param ctx The SHA-256 context to initialize.
112+
* \param is224 Determines which function to use.
113+
* <ul><li>0: Use SHA-256.</li>
114+
* <li>1: Use SHA-224.</li></ul>
115+
*/
116+
MBEDTLS_DEPRECATED void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
117+
int is224 );
118+
119+
/**
120+
* \brief This function feeds an input buffer into an ongoing
121+
* SHA-256 checksum calculation.
122+
*
123+
* \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0.
124+
*
125+
* \param ctx The SHA-256 context to initialize.
126+
* \param input The buffer holding the data.
127+
* \param ilen The length of the input data.
128+
*/
129+
MBEDTLS_DEPRECATED void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
130+
const unsigned char *input,
131+
size_t ilen );
132+
133+
/**
134+
* \brief This function finishes the SHA-256 operation, and writes
135+
* the result to the output buffer.
136+
*
137+
* \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0.
138+
*
139+
* \param ctx The SHA-256 context.
140+
* \param output The SHA-224or SHA-256 checksum result.
141+
*/
142+
MBEDTLS_DEPRECATED void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
143+
unsigned char output[32] );
144+
145+
/**
146+
* \brief This function processes a single data block within
147+
* the ongoing SHA-256 computation. This function is for
148+
* internal use only.
149+
*
150+
* \deprecated Superseded by mbedtls_internal_sha256_process() in 2.7.0.
151+
*
152+
* \param ctx The SHA-256 context.
153+
* \param data The buffer holding one block of data.
154+
*/
155+
MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
156+
const unsigned char data[64] );
157+
158+
#undef MBEDTLS_DEPRECATED
159+
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
93160

94161
#ifdef __cplusplus
95162
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,46 +105,50 @@ 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

141-
void mbedtls_sha512_process(mbedtls_sha512_context *ctx, const unsigned char data[128])
144+
int mbedtls_internal_sha512_process(mbedtls_sha512_context *ctx, const unsigned char data[128])
142145
{
143146
if (ctx->active_ctx == &ctx->hw_ctx) {
144147
mbedtls_sha512_hw_process(&ctx->hw_ctx, data);
145148
} else if (ctx->active_ctx == &ctx->sw_ctx) {
146149
mbedtls_sha512_sw_process(&ctx->sw_ctx, data);
147150
}
151+
return 0;
148152
}
149153

150154
#endif /* MBEDTLS_SHA512_ALT */

0 commit comments

Comments
 (0)