MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / sha512_file

Function sha512_file

sha512.c:347–374  ·  view source on GitHub ↗

* output = SHA-512( file contents ) */

Source from the content-addressed store, hash-verified

345 * output = SHA-512( file contents )
346 */
347int 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/*

Callers

nothing calls this directly

Calls 5

sha512_initFunction · 0.85
sha512_startsFunction · 0.85
sha512_updateFunction · 0.85
sha512_finishFunction · 0.85
sha512_freeFunction · 0.85

Tested by

no test coverage detected