@@ -234,7 +234,7 @@ void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
234
234
/*
235
235
* SHA-256 context setup
236
236
*/
237
- void mbedtls_sha256_starts ( mbedtls_sha256_context * ctx , int is224 )
237
+ int mbedtls_sha256_starts_ret ( mbedtls_sha256_context * ctx , int is224 )
238
238
{
239
239
ctx -> total [0 ] = 0 ;
240
240
ctx -> total [1 ] = 0 ;
@@ -246,6 +246,8 @@ void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 )
246
246
ctx -> is224 = false;
247
247
memcpy (ctx -> state , init_state_sha256 , sizeof (ctx -> state ));
248
248
}
249
+
250
+ return 0 ;
249
251
}
250
252
251
253
void mbedtls_sha256_process ( mbedtls_sha256_context * ctx ,
@@ -257,15 +259,15 @@ void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
257
259
/*
258
260
* SHA-256 process buffer
259
261
*/
260
- void mbedtls_sha256_update ( mbedtls_sha256_context * ctx ,
261
- const unsigned char * input ,
262
- size_t ilen )
262
+ int mbedtls_sha256_update_ret ( mbedtls_sha256_context * ctx ,
263
+ const unsigned char * input ,
264
+ size_t ilen )
263
265
{
264
266
size_t fill ;
265
267
uint32_t left ;
266
268
267
269
if ( ilen == 0 ) {
268
- return ;
270
+ return 0 ;
269
271
}
270
272
271
273
left = ctx -> total [0 ] & 0x3F ;
@@ -296,17 +298,20 @@ void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
296
298
if ( ilen > 0 ) {
297
299
memcpy ( (void * ) (ctx -> buffer + left ), input , ilen );
298
300
}
301
+
302
+ return 0 ;
299
303
}
300
304
301
305
/*
302
306
* SHA-256 final digest
303
307
*/
304
- void mbedtls_sha256_finish ( mbedtls_sha256_context * ctx ,
305
- unsigned char output [32 ] )
308
+ int mbedtls_sha256_finish_ret ( mbedtls_sha256_context * ctx ,
309
+ unsigned char output [32 ] )
306
310
{
307
311
uint32_t last , padn ;
308
312
uint32_t high , low ;
309
313
unsigned char msglen [8 ];
314
+ int err ;
310
315
311
316
high = ( ctx -> total [0 ] >> 29 )
312
317
| ( ctx -> total [1 ] << 3 );
@@ -318,12 +323,21 @@ void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
318
323
last = ctx -> total [0 ] & 0x3F ;
319
324
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
320
325
321
- mbedtls_sha256_update ( ctx , sha_padding , padn );
322
- mbedtls_sha256_update ( ctx , msglen , 8 );
326
+ err = mbedtls_sha256_update_ret ( ctx , sha_padding , padn );
327
+ if ( err != 0 ) {
328
+ return err ;
329
+ }
330
+
331
+ err = mbedtls_sha256_update_ret ( ctx , msglen , 8 );
332
+ if ( err != 0 ) {
333
+ return err ;
334
+ }
323
335
324
336
for ( size_t i = 0 ; i < (ctx -> is224 ? 28 : 32 ); i += 4 ) {
325
337
* ((uint32_t * )(& output [i ])) = __REV (ctx -> state [i >> 2 ]);
326
338
}
339
+
340
+ return 0 ;
327
341
}
328
342
#endif /* #if defined(MBEDTLS_SHA256_ALT) && defined(MBEDTLS_SHA256_C) */
329
343
@@ -366,12 +380,16 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
366
380
* \brief SHA-1 context setup
367
381
*
368
382
* \param ctx context to be initialized
383
+ *
384
+ * \return \c 0 if successful
385
+ *
369
386
*/
370
- void mbedtls_sha1_starts ( mbedtls_sha1_context * ctx )
387
+ int mbedtls_sha1_starts_ret ( mbedtls_sha1_context * ctx )
371
388
{
372
389
ctx -> total [0 ] = 0 ;
373
390
ctx -> total [1 ] = 0 ;
374
391
memcpy (ctx -> state , init_state_sha1 , 32 );
392
+ return 0 ;
375
393
}
376
394
377
395
/**
@@ -380,16 +398,19 @@ void mbedtls_sha1_starts( mbedtls_sha1_context *ctx )
380
398
* \param ctx SHA-1 context
381
399
* \param input buffer holding the data
382
400
* \param ilen length of the input data
401
+ *
402
+ * \return \c 0 if successful
403
+ *
383
404
*/
384
- void mbedtls_sha1_update ( mbedtls_sha1_context * ctx ,
385
- const unsigned char * input ,
386
- size_t ilen )
405
+ int mbedtls_sha1_update_ret ( mbedtls_sha1_context * ctx ,
406
+ const unsigned char * input ,
407
+ size_t ilen )
387
408
{
388
409
size_t fill ;
389
410
uint32_t left ;
390
411
391
412
if ( ilen == 0 ) {
392
- return ;
413
+ return 0 ;
393
414
}
394
415
395
416
left = ctx -> total [0 ] & 0x3F ;
@@ -420,20 +441,26 @@ void mbedtls_sha1_update( mbedtls_sha1_context *ctx,
420
441
if ( ilen > 0 ) {
421
442
memcpy ( (void * ) (ctx -> buffer + left ), input , ilen );
422
443
}
444
+
445
+ return 0 ;
423
446
}
424
447
425
448
/**
426
449
* \brief SHA-1 final digest
427
450
*
428
451
* \param ctx SHA-1 context
429
452
* \param output SHA-1 checksum result
453
+ *
454
+ * \return \c 0 if successful
455
+ *
430
456
*/
431
- void mbedtls_sha1_finish ( mbedtls_sha1_context * ctx ,
432
- unsigned char output [20 ] )
457
+ int mbedtls_sha1_finish_ret ( mbedtls_sha1_context * ctx ,
458
+ unsigned char output [20 ] )
433
459
{
434
460
uint32_t last , padn ;
435
461
uint32_t high , low ;
436
462
unsigned char msglen [8 ];
463
+ int err ;
437
464
438
465
high = ( ctx -> total [0 ] >> 29 )
439
466
| ( ctx -> total [1 ] << 3 );
@@ -445,12 +472,21 @@ void mbedtls_sha1_finish( mbedtls_sha1_context *ctx,
445
472
last = ctx -> total [0 ] & 0x3F ;
446
473
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
447
474
448
- mbedtls_sha1_update ( ctx , sha_padding , padn );
449
- mbedtls_sha1_update ( ctx , msglen , 8 );
475
+ err = mbedtls_sha1_update_ret ( ctx , sha_padding , padn );
476
+ if ( err != 0 ) {
477
+ return err ;
478
+ }
479
+
480
+ err = mbedtls_sha1_update_ret ( ctx , msglen , 8 );
481
+ if ( err != 0 ) {
482
+ return err ;
483
+ }
450
484
451
485
for ( size_t i = 0 ; i < 20 ; i += 4 ) {
452
486
* ((uint32_t * )(& output [i ])) = __REV (ctx -> state [i >> 2 ]);
453
487
}
488
+
489
+ return 0 ;
454
490
}
455
491
456
492
/* Internal use */
0 commit comments