SHA2 renamed to SHA256, SHA4 renamed to SHA512 and functions accordingly

The SHA4 name was not clear with regards to the new SHA-3 standard. So
SHA2 and SHA4 have been renamed to better represent what they are:
SHA256 and SHA512 modules.
This commit is contained in:
Paul Bakker 2013-06-30 14:34:05 +02:00
parent 3866b9f4b5
commit 9e36f0475f
32 changed files with 700 additions and 697 deletions

View file

@ -1,7 +1,7 @@
/*
* AES-256 file encryption program
*
* Copyright (C) 2006-2011, Brainspark B.V.
* Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@ -56,12 +56,12 @@
"\n example: aescrypt2 0 file file.aes hex:E76B2413958B00E193\n" \
"\n"
#if !defined(POLARSSL_AES_C) || !defined(POLARSSL_SHA2_C)
#if !defined(POLARSSL_AES_C) || !defined(POLARSSL_SHA256_C)
int main( int argc, char *argv[] )
{
((void) argc);
((void) argv);
printf("POLARSSL_AES_C and/or POLARSSL_SHA2_C not defined.\n");
printf("POLARSSL_AES_C and/or POLARSSL_SHA256_C not defined.\n");
return( 0 );
}
#else
@ -81,7 +81,7 @@ int main( int argc, char *argv[] )
unsigned char buffer[1024];
aes_context aes_ctx;
sha2_context sha_ctx;
sha256_context sha_ctx;
#if defined(_WIN32_WCE)
long filesize, offset;
@ -213,10 +213,10 @@ int main( int argc, char *argv[] )
p = argv[2];
sha2_starts( &sha_ctx, 0 );
sha2_update( &sha_ctx, buffer, 8 );
sha2_update( &sha_ctx, (unsigned char *) p, strlen( p ) );
sha2_finish( &sha_ctx, digest );
sha256_starts( &sha_ctx, 0 );
sha256_update( &sha_ctx, buffer, 8 );
sha256_update( &sha_ctx, (unsigned char *) p, strlen( p ) );
sha256_finish( &sha_ctx, digest );
memcpy( IV, digest, 16 );
@ -247,15 +247,15 @@ int main( int argc, char *argv[] )
for( i = 0; i < 8192; i++ )
{
sha2_starts( &sha_ctx, 0 );
sha2_update( &sha_ctx, digest, 32 );
sha2_update( &sha_ctx, key, keylen );
sha2_finish( &sha_ctx, digest );
sha256_starts( &sha_ctx, 0 );
sha256_update( &sha_ctx, digest, 32 );
sha256_update( &sha_ctx, key, keylen );
sha256_finish( &sha_ctx, digest );
}
memset( key, 0, sizeof( key ) );
aes_setkey_enc( &aes_ctx, digest, 256 );
sha2_hmac_starts( &sha_ctx, digest, 32, 0 );
aes_setkey_enc( &aes_ctx, digest, 256 );
sha256_hmac_starts( &sha_ctx, digest, 32, 0 );
/*
* Encrypt and write the ciphertext.
@ -275,7 +275,7 @@ int main( int argc, char *argv[] )
buffer[i] = (unsigned char)( buffer[i] ^ IV[i] );
aes_crypt_ecb( &aes_ctx, AES_ENCRYPT, buffer, buffer );
sha2_hmac_update( &sha_ctx, buffer, 16 );
sha256_hmac_update( &sha_ctx, buffer, 16 );
if( fwrite( buffer, 1, 16, fout ) != 16 )
{
@ -289,7 +289,7 @@ int main( int argc, char *argv[] )
/*
* Finally write the HMAC.
*/
sha2_hmac_finish( &sha_ctx, digest );
sha256_hmac_finish( &sha_ctx, digest );
if( fwrite( digest, 1, 32, fout ) != 32 )
{
@ -349,15 +349,15 @@ int main( int argc, char *argv[] )
for( i = 0; i < 8192; i++ )
{
sha2_starts( &sha_ctx, 0 );
sha2_update( &sha_ctx, digest, 32 );
sha2_update( &sha_ctx, key, keylen );
sha2_finish( &sha_ctx, digest );
sha256_starts( &sha_ctx, 0 );
sha256_update( &sha_ctx, digest, 32 );
sha256_update( &sha_ctx, key, keylen );
sha256_finish( &sha_ctx, digest );
}
memset( key, 0, sizeof( key ) );
aes_setkey_dec( &aes_ctx, digest, 256 );
sha2_hmac_starts( &sha_ctx, digest, 32, 0 );
sha256_hmac_starts( &sha_ctx, digest, 32, 0 );
/*
* Decrypt and write the plaintext.
@ -371,10 +371,10 @@ int main( int argc, char *argv[] )
}
memcpy( tmp, buffer, 16 );
sha2_hmac_update( &sha_ctx, buffer, 16 );
sha256_hmac_update( &sha_ctx, buffer, 16 );
aes_crypt_ecb( &aes_ctx, AES_DECRYPT, buffer, buffer );
for( i = 0; i < 16; i++ )
buffer[i] = (unsigned char)( buffer[i] ^ IV[i] );
@ -393,7 +393,7 @@ int main( int argc, char *argv[] )
/*
* Verify the message authentication code.
*/
sha2_hmac_finish( &sha_ctx, digest );
sha256_hmac_finish( &sha_ctx, digest );
if( fread( buffer, 1, 32, fin ) != 32 )
{
@ -421,8 +421,8 @@ exit:
memset( digest, 0, sizeof( digest ) );
memset( &aes_ctx, 0, sizeof( aes_context ) );
memset( &sha_ctx, 0, sizeof( sha2_context ) );
memset( &sha_ctx, 0, sizeof( sha256_context ) );
return( ret );
}
#endif /* POLARSSL_AES_C && POLARSSL_SHA2_C */
#endif /* POLARSSL_AES_C && POLARSSL_SHA256_C */

View file

@ -1,5 +1,5 @@
/*
* sha2sum demonstration program
* sha256sum demonstration program
*
* Copyright (C) 2006-2011, Brainspark B.V.
*
@ -34,19 +34,19 @@
#include "polarssl/sha2.h"
#if !defined(POLARSSL_SHA2_C) || !defined(POLARSSL_FS_IO)
#if !defined(POLARSSL_SHA256_C) || !defined(POLARSSL_FS_IO)
int main( int argc, char *argv[] )
{
((void) argc);
((void) argv);
printf("POLARSSL_SHA2_C and/or POLARSSL_FS_IO not defined.\n");
printf("POLARSSL_SHA256_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
#else
static int sha2_wrapper( char *filename, unsigned char *sum )
static int sha256_wrapper( char *filename, unsigned char *sum )
{
int ret = sha2_file( filename, sum, 0 );
int ret = sha256_file( filename, sum, 0 );
if( ret == 1 )
fprintf( stderr, "failed to open: %s\n", filename );
@ -57,12 +57,12 @@ static int sha2_wrapper( char *filename, unsigned char *sum )
return( ret );
}
static int sha2_print( char *filename )
static int sha256_print( char *filename )
{
int i;
unsigned char sum[32];
if( sha2_wrapper( filename, sum ) != 0 )
if( sha256_wrapper( filename, sum ) != 0 )
return( 1 );
for( i = 0; i < 32; i++ )
@ -72,7 +72,7 @@ static int sha2_print( char *filename )
return( 0 );
}
static int sha2_check( char *filename )
static int sha256_check( char *filename )
{
int i;
size_t n;
@ -110,7 +110,7 @@ static int sha2_check( char *filename )
nb_tot1++;
if( sha2_wrapper( line + 66, sum ) != 0 )
if( sha256_wrapper( line + 66, sum ) != 0 )
{
nb_err1++;
continue;
@ -151,8 +151,8 @@ int main( int argc, char *argv[] )
if( argc == 1 )
{
printf( "print mode: sha2sum <file> <file> ...\n" );
printf( "check mode: sha2sum -c <checksum file>\n" );
printf( "print mode: sha256sum <file> <file> ...\n" );
printf( "check mode: sha256sum -c <checksum file>\n" );
#if defined(_WIN32)
printf( "\n Press Enter to exit this program.\n" );
@ -163,12 +163,12 @@ int main( int argc, char *argv[] )
}
if( argc == 3 && strcmp( "-c", argv[1] ) == 0 )
return( sha2_check( argv[2] ) );
return( sha256_check( argv[2] ) );
ret = 0;
for( i = 1; i < argc; i++ )
ret |= sha2_print( argv[i] );
ret |= sha256_print( argv[i] );
return( ret );
}
#endif /* POLARSSL_SHA2_C && POLARSSL_FS_IO */
#endif /* POLARSSL_SHA256_C && POLARSSL_FS_IO */

View file

@ -181,33 +181,33 @@ int main( int argc, char *argv[] )
( hardclock() - tsc ) / ( j * BUFSIZE ) );
#endif
#if defined(POLARSSL_SHA2_C)
#if defined(POLARSSL_SHA256_C)
printf( HEADER_FORMAT, "SHA-256" );
fflush( stdout );
set_alarm( 1 );
for( i = 1; ! alarmed; i++ )
sha2( buf, BUFSIZE, tmp, 0 );
sha256( buf, BUFSIZE, tmp, 0 );
tsc = hardclock();
for( j = 0; j < 1024; j++ )
sha2( buf, BUFSIZE, tmp, 0 );
sha256( buf, BUFSIZE, tmp, 0 );
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
( hardclock() - tsc ) / ( j * BUFSIZE ) );
#endif
#if defined(POLARSSL_SHA4_C)
#if defined(POLARSSL_SHA512_C)
printf( HEADER_FORMAT, "SHA-512" );
fflush( stdout );
set_alarm( 1 );
for( i = 1; ! alarmed; i++ )
sha4( buf, BUFSIZE, tmp, 0 );
sha512( buf, BUFSIZE, tmp, 0 );
tsc = hardclock();
for( j = 0; j < 1024; j++ )
sha4( buf, BUFSIZE, tmp, 0 );
sha512( buf, BUFSIZE, tmp, 0 );
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
( hardclock() - tsc ) / ( j * BUFSIZE ) );

View file

@ -86,13 +86,13 @@ int main( int argc, char *argv[] )
return( ret );
#endif
#if defined(POLARSSL_SHA2_C)
if( ( ret = sha2_self_test( v ) ) != 0 )
#if defined(POLARSSL_SHA256_C)
if( ( ret = sha256_self_test( v ) ) != 0 )
return( ret );
#endif
#if defined(POLARSSL_SHA4_C)
if( ( ret = sha4_self_test( v ) ) != 0 )
#if defined(POLARSSL_SHA512_C)
if( ( ret = sha512_self_test( v ) ) != 0 )
return( ret );
#endif