Update external polarssl to 1.3.8

There were some fixes back on March 13th, 2014 for fixing compiling on MIPS64.
Also some fixes on June 25th, 2014 for SPARC64 fixes.

Probably more things, but those are what I care about.
This commit is contained in:
Ryan Houdek
2014-09-08 01:58:33 -05:00
parent 6ea82790ba
commit a48e284317
130 changed files with 12346 additions and 4632 deletions

View File

@ -1,7 +1,7 @@
/*
* FIPS-180-2 compliant SHA-256 implementation
*
* Copyright (C) 2006-2013, Brainspark B.V.
* Copyright (C) 2006-2014, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@ -28,7 +28,11 @@
* http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
*/
#if !defined(POLARSSL_CONFIG_FILE)
#include "polarssl/config.h"
#else
#include POLARSSL_CONFIG_FILE
#endif
#if defined(POLARSSL_SHA256_C)
@ -38,6 +42,17 @@
#include <stdio.h>
#endif
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#define polarssl_printf printf
#endif
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
}
#if !defined(POLARSSL_SHA256_ALT)
/*
@ -63,6 +78,19 @@
}
#endif
void sha256_init( sha256_context *ctx )
{
memset( ctx, 0, sizeof( sha256_context ) );
}
void sha256_free( sha256_context *ctx )
{
if( ctx == NULL )
return;
polarssl_zeroize( ctx, sizeof( sha256_context ) );
}
/*
* SHA-256 context setup
*/
@ -233,12 +261,13 @@ void sha256_process( sha256_context *ctx, const unsigned char data[64] )
/*
* SHA-256 process buffer
*/
void sha256_update( sha256_context *ctx, const unsigned char *input, size_t ilen )
void sha256_update( sha256_context *ctx, const unsigned char *input,
size_t ilen )
{
size_t fill;
uint32_t left;
if( ilen <= 0 )
if( ilen == 0 )
return;
left = ctx->total[0] & 0x3F;
@ -322,11 +351,11 @@ void sha256( const unsigned char *input, size_t ilen,
{
sha256_context ctx;
sha256_init( &ctx );
sha256_starts( &ctx, is224 );
sha256_update( &ctx, input, ilen );
sha256_finish( &ctx, output );
memset( &ctx, 0, sizeof( sha256_context ) );
sha256_free( &ctx );
}
#if defined(POLARSSL_FS_IO)
@ -343,14 +372,14 @@ int sha256_file( const char *path, unsigned char output[32], int is224 )
if( ( f = fopen( path, "rb" ) ) == NULL )
return( POLARSSL_ERR_SHA256_FILE_IO_ERROR );
sha256_init( &ctx );
sha256_starts( &ctx, is224 );
while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
sha256_update( &ctx, buf, n );
sha256_finish( &ctx, output );
memset( &ctx, 0, sizeof( sha256_context ) );
sha256_free( &ctx );
if( ferror( f ) != 0 )
{
@ -391,13 +420,14 @@ void sha256_hmac_starts( sha256_context *ctx, const unsigned char *key,
sha256_starts( ctx, is224 );
sha256_update( ctx, ctx->ipad, 64 );
memset( sum, 0, sizeof( sum ) );
polarssl_zeroize( sum, sizeof( sum ) );
}
/*
* SHA-256 HMAC process buffer
*/
void sha256_hmac_update( sha256_context *ctx, const unsigned char *input, size_t ilen )
void sha256_hmac_update( sha256_context *ctx, const unsigned char *input,
size_t ilen )
{
sha256_update( ctx, input, ilen );
}
@ -419,7 +449,7 @@ void sha256_hmac_finish( sha256_context *ctx, unsigned char output[32] )
sha256_update( ctx, tmpbuf, hlen );
sha256_finish( ctx, output );
memset( tmpbuf, 0, sizeof( tmpbuf ) );
polarssl_zeroize( tmpbuf, sizeof( tmpbuf ) );
}
/*
@ -440,18 +470,18 @@ void sha256_hmac( const unsigned char *key, size_t keylen,
{
sha256_context ctx;
sha256_init( &ctx );
sha256_hmac_starts( &ctx, key, keylen, is224 );
sha256_hmac_update( &ctx, input, ilen );
sha256_hmac_finish( &ctx, output );
memset( &ctx, 0, sizeof( sha256_context ) );
sha256_free( &ctx );
}
#if defined(POLARSSL_SELF_TEST)
/*
* FIPS-180-2 test vectors
*/
static unsigned char sha256_test_buf[3][57] =
static unsigned char sha256_test_buf[3][57] =
{
{ "abc" },
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
@ -615,18 +645,20 @@ static const unsigned char sha256_hmac_test_sum[14][32] =
*/
int sha256_self_test( int verbose )
{
int i, j, k, buflen;
int i, j, k, buflen, ret = 0;
unsigned char buf[1024];
unsigned char sha256sum[32];
sha256_context ctx;
sha256_init( &ctx );
for( i = 0; i < 6; i++ )
{
j = i % 3;
k = i < 3;
if( verbose != 0 )
printf( " SHA-%d test #%d: ", 256 - k * 32, j + 1 );
polarssl_printf( " SHA-%d test #%d: ", 256 - k * 32, j + 1 );
sha256_starts( &ctx, k );
@ -646,17 +678,18 @@ int sha256_self_test( int verbose )
if( memcmp( sha256sum, sha256_test_sum[i], 32 - k * 4 ) != 0 )
{
if( verbose != 0 )
printf( "failed\n" );
polarssl_printf( "failed\n" );
return( 1 );
ret = 1;
goto exit;
}
if( verbose != 0 )
printf( "passed\n" );
polarssl_printf( "passed\n" );
}
if( verbose != 0 )
printf( "\n" );
polarssl_printf( "\n" );
for( i = 0; i < 14; i++ )
{
@ -664,7 +697,7 @@ int sha256_self_test( int verbose )
k = i < 7;
if( verbose != 0 )
printf( " HMAC-SHA-%d test #%d: ", 256 - k * 32, j + 1 );
polarssl_printf( " HMAC-SHA-%d test #%d: ", 256 - k * 32, j + 1 );
if( j == 5 || j == 6 )
{
@ -685,21 +718,25 @@ int sha256_self_test( int verbose )
if( memcmp( sha256sum, sha256_hmac_test_sum[i], buflen ) != 0 )
{
if( verbose != 0 )
printf( "failed\n" );
polarssl_printf( "failed\n" );
return( 1 );
ret = 1;
goto exit;
}
if( verbose != 0 )
printf( "passed\n" );
polarssl_printf( "passed\n" );
}
if( verbose != 0 )
printf( "\n" );
polarssl_printf( "\n" );
return( 0 );
exit:
sha256_free( &ctx );
return( ret );
}
#endif
#endif /* POLARSSL_SELF_TEST */
#endif
#endif /* POLARSSL_SHA256_C */