* output = SHA-512( file contents ) */
| 345 | * output = SHA-512( file contents ) |
| 346 | */ |
| 347 | int sha512_file( const char *path, unsigned char output[64], int is384 ) |
| 348 | { |
| 349 | FILE *f; |
| 350 | size_t n; |
| 351 | sha512_context ctx; |
| 352 | unsigned char buf[1024]; |
| 353 | |
| 354 | if( ( f = fopen( path, "rb" ) ) == NULL ) |
| 355 | return( POLARSSL_ERR_SHA512_FILE_IO_ERROR ); |
| 356 | |
| 357 | sha512_init( &ctx ); |
| 358 | sha512_starts( &ctx, is384 ); |
| 359 | |
| 360 | while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 ) |
| 361 | sha512_update( &ctx, buf, n ); |
| 362 | |
| 363 | sha512_finish( &ctx, output ); |
| 364 | sha512_free( &ctx ); |
| 365 | |
| 366 | if( ferror( f ) != 0 ) |
| 367 | { |
| 368 | fclose( f ); |
| 369 | return( POLARSSL_ERR_SHA512_FILE_IO_ERROR ); |
| 370 | } |
| 371 | |
| 372 | fclose( f ); |
| 373 | return( 0 ); |
| 374 | } |
| 375 | #endif /* POLARSSL_FS_IO */ |
| 376 | |
| 377 | /* |
nothing calls this directly
no test coverage detected