#include <stddef.h>
#include <stdint.h>
Go to the source code of this file.
◆ mbedtls_sha256()
| void mbedtls_sha256 |
( |
const unsigned char * |
input, |
|
|
size_t |
ilen, |
|
|
unsigned char |
output[32], |
|
|
int |
is224 |
|
) |
| |
Output = SHA-256( input buffer )
- Parameters
-
| input | buffer holding the data |
| ilen | length of the input data |
| output | SHA-224/256 checksum result |
| is224 | 0 = use SHA256, 1 = use SHA224 |
Definition at line 325 of file sha256.cxx.
327{
329
335}
static void output(code_int code)
void mbedtls_sha256_finish(mbedtls_sha256_context *ctx, unsigned char output[32])
SHA-256 final digest.
void mbedtls_sha256_update(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen)
SHA-256 process buffer.
void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
Clear SHA-256 context.
void mbedtls_sha256_init(mbedtls_sha256_context *ctx)
Initialize SHA-256 context.
void mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224)
SHA-256 context setup.
SHA-256 context structure.
◆ mbedtls_sha256_clone()
Clone (the state of) a SHA-256 context.
- Parameters
-
| dst | The destination context |
| src | The context to be cloned |
Definition at line 93 of file sha256.cxx.
◆ mbedtls_sha256_finish()
SHA-256 final digest.
- Parameters
-
| ctx | SHA-256 context |
| output | SHA-224/256 checksum result |
Definition at line 289 of file sha256.cxx.
290{
291 uint32_t last, padn;
292 uint32_t high, low;
293 unsigned char msglen[8];
294
295 high = ( ctx->
total[0] >> 29 )
296 | ( ctx->
total[1] << 3 );
297 low = ( ctx->
total[0] << 3 );
298
301
302 last = ctx->
total[0] & 0x3F;
303 padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
304
307
315
316 if( ctx->
is224 == 0 )
318}
#define PUT_UINT32_BE(n, b, i)
static const unsigned char sha256_padding[64]
◆ mbedtls_sha256_free()
Clear SHA-256 context.
- Parameters
-
| ctx | SHA-256 context to be cleared |
Definition at line 85 of file sha256.cxx.
86{
87 if( ctx == NULL )
88 return;
89
91}
static void mbedtls_zeroize(void *v, size_t n)
◆ mbedtls_sha256_init()
Initialize SHA-256 context.
- Parameters
-
| ctx | SHA-256 context to be initialized |
Definition at line 80 of file sha256.cxx.
◆ mbedtls_sha256_process()
Definition at line 181 of file sha256.cxx.
182{
183 uint32_t temp1, temp2, W[64];
186
187 for(
i = 0;
i < 8;
i++ )
189
190#if defined(MBEDTLS_SHA256_SMALLER)
191 for(
i = 0;
i < 64;
i++ )
192 {
195 else
197
198 P(
A[0],
A[1],
A[2],
A[3],
A[4],
A[5],
A[6],
A[7], W[
i],
K[
i] );
199
200 temp1 =
A[7];
A[7] =
A[6];
A[6] =
A[5];
A[5] =
A[4];
A[4] =
A[3];
201 A[3] =
A[2];
A[2] =
A[1];
A[1] =
A[0];
A[0] = temp1;
202 }
203#else
204 for(
i = 0;
i < 16;
i++ )
206
207 for(
i = 0;
i < 16;
i += 8 )
208 {
209 P(
A[0],
A[1],
A[2],
A[3],
A[4],
A[5],
A[6],
A[7], W[
i+0],
K[
i+0] );
210 P(
A[7],
A[0],
A[1],
A[2],
A[3],
A[4],
A[5],
A[6], W[
i+1],
K[
i+1] );
211 P(
A[6],
A[7],
A[0],
A[1],
A[2],
A[3],
A[4],
A[5], W[
i+2],
K[
i+2] );
212 P(
A[5],
A[6],
A[7],
A[0],
A[1],
A[2],
A[3],
A[4], W[
i+3],
K[
i+3] );
213 P(
A[4],
A[5],
A[6],
A[7],
A[0],
A[1],
A[2],
A[3], W[
i+4],
K[
i+4] );
214 P(
A[3],
A[4],
A[5],
A[6],
A[7],
A[0],
A[1],
A[2], W[
i+5],
K[
i+5] );
215 P(
A[2],
A[3],
A[4],
A[5],
A[6],
A[7],
A[0],
A[1], W[
i+6],
K[
i+6] );
216 P(
A[1],
A[2],
A[3],
A[4],
A[5],
A[6],
A[7],
A[0], W[
i+7],
K[
i+7] );
217 }
218
219 for(
i = 16;
i < 64;
i += 8 )
220 {
221 P(
A[0],
A[1],
A[2],
A[3],
A[4],
A[5],
A[6],
A[7],
R(
i+0),
K[
i+0] );
222 P(
A[7],
A[0],
A[1],
A[2],
A[3],
A[4],
A[5],
A[6],
R(
i+1),
K[
i+1] );
223 P(
A[6],
A[7],
A[0],
A[1],
A[2],
A[3],
A[4],
A[5],
R(
i+2),
K[
i+2] );
224 P(
A[5],
A[6],
A[7],
A[0],
A[1],
A[2],
A[3],
A[4],
R(
i+3),
K[
i+3] );
225 P(
A[4],
A[5],
A[6],
A[7],
A[0],
A[1],
A[2],
A[3],
R(
i+4),
K[
i+4] );
226 P(
A[3],
A[4],
A[5],
A[6],
A[7],
A[0],
A[1],
A[2],
R(
i+5),
K[
i+5] );
227 P(
A[2],
A[3],
A[4],
A[5],
A[6],
A[7],
A[0],
A[1],
R(
i+6),
K[
i+6] );
228 P(
A[1],
A[2],
A[3],
A[4],
A[5],
A[6],
A[7],
A[0],
R(
i+7),
K[
i+7] );
229 }
230#endif
231
232 for(
i = 0;
i < 8;
i++ )
234}
#define GET_UINT32_BE(n, b, i)
#define P(a, b, c, d, e, f, g, h, x, K)
static const uint32_t K[]
◆ mbedtls_sha256_self_test()
| int mbedtls_sha256_self_test |
( |
int |
verbose | ) |
|
Checkup routine.
- Returns
- 0 if successful, or 1 if the test failed
◆ mbedtls_sha256_starts()
SHA-256 context setup.
- Parameters
-
| ctx | context to be initialized |
| is224 | 0 = use SHA256, 1 = use SHA224 |
Definition at line 102 of file sha256.cxx.
103{
106
107 if( is224 == 0 )
108 {
109
110 ctx->
state[0] = 0x6A09E667;
111 ctx->
state[1] = 0xBB67AE85;
112 ctx->
state[2] = 0x3C6EF372;
113 ctx->
state[3] = 0xA54FF53A;
114 ctx->
state[4] = 0x510E527F;
115 ctx->
state[5] = 0x9B05688C;
116 ctx->
state[6] = 0x1F83D9AB;
117 ctx->
state[7] = 0x5BE0CD19;
118 }
119 else
120 {
121
122 ctx->
state[0] = 0xC1059ED8;
123 ctx->
state[1] = 0x367CD507;
124 ctx->
state[2] = 0x3070DD17;
125 ctx->
state[3] = 0xF70E5939;
126 ctx->
state[4] = 0xFFC00B31;
127 ctx->
state[5] = 0x68581511;
128 ctx->
state[6] = 0x64F98FA7;
129 ctx->
state[7] = 0xBEFA4FA4;
130 }
131
133}
◆ mbedtls_sha256_update()
SHA-256 process buffer.
- Parameters
-
| ctx | SHA-256 context |
| input | buffer holding the data |
| ilen | length of the input data |
Definition at line 240 of file sha256.cxx.
242{
243 size_t fill;
245
246 if( ilen == 0 )
247 return;
248
251
252 ctx->
total[0] += (uint32_t) ilen;
253 ctx->
total[0] &= 0xFFFFFFFF;
254
255 if( ctx->
total[0] < (uint32_t) ilen )
257
258 if(
left && ilen >= fill )
259 {
260 memcpy( (
void *) (ctx->
buffer +
left), input, fill );
262 input += fill;
263 ilen -= fill;
265 }
266
267 while( ilen >= 64 )
268 {
270 input += 64;
271 ilen -= 64;
272 }
273
274 if( ilen > 0 )
275 memcpy( (
void *) (ctx->
buffer +
left), input, ilen );
276}
static int left(const struct frozen *f)
void mbedtls_sha256_process(mbedtls_sha256_context *ctx, const unsigned char data[64])