1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-30 22:43:08 +03:00

Merge pull request #265 from ARMmbed/iotssl-460-bugfixes

Iotssl 460 bugfixes
This commit is contained in:
Simon Butcher
2015-09-02 23:36:36 +01:00
25 changed files with 131 additions and 80 deletions

View File

@ -75,7 +75,7 @@ int main( void )
unsigned char *p, *end;
unsigned char buf[2048];
unsigned char hash[20];
unsigned char hash[32];
const char *pers = "dh_client";
mbedtls_entropy_context entropy;

View File

@ -74,7 +74,7 @@ int main( void )
mbedtls_net_context listen_fd, client_fd;
unsigned char buf[2048];
unsigned char hash[20];
unsigned char hash[32];
unsigned char buf2[2];
const char *pers = "dh_server";

View File

@ -151,8 +151,11 @@ exit:
mbedtls_entropy_free( &entropy );
#if defined(MBEDTLS_ERROR_C)
mbedtls_strerror( ret, (char *) buf, sizeof(buf) );
mbedtls_printf( " ! Last error was: %s\n", buf );
if( ret != 0 )
{
mbedtls_strerror( ret, (char *) buf, sizeof(buf) );
mbedtls_printf( " ! Last error was: %s\n", buf );
}
#endif
#if defined(_WIN32)

View File

@ -151,8 +151,11 @@ exit:
mbedtls_entropy_free( &entropy );
#if defined(MBEDTLS_ERROR_C)
mbedtls_strerror( ret, (char *) buf, sizeof(buf) );
mbedtls_printf( " ! Last error was: %s\n", buf );
if( ret != 0 )
{
mbedtls_strerror( ret, (char *) buf, sizeof(buf) );
mbedtls_printf( " ! Last error was: %s\n", buf );
}
#endif
#if defined(_WIN32)

View File

@ -64,7 +64,7 @@ int main( int argc, char *argv[] )
mbedtls_pk_context pk;
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
unsigned char hash[20];
unsigned char hash[32];
unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
char filename[512];
const char *pers = "mbedtls_pk_sign";
@ -129,7 +129,7 @@ int main( int argc, char *argv[] )
}
/*
* Write the signature into <filename>-sig.txt
* Write the signature into <filename>.sig
*/
mbedtls_snprintf( filename, sizeof(filename), "%s.sig", argv[2] );
@ -156,8 +156,11 @@ exit:
mbedtls_entropy_free( &entropy );
#if defined(MBEDTLS_ERROR_C)
mbedtls_strerror( ret, (char *) buf, sizeof(buf) );
mbedtls_printf( " ! Last error was: %s\n", buf );
if( ret != 0 )
{
mbedtls_strerror( ret, (char *) buf, sizeof(buf) );
mbedtls_printf( " ! Last error was: %s\n", buf );
}
#endif
#if defined(_WIN32)

View File

@ -59,7 +59,7 @@ int main( int argc, char *argv[] )
int ret = 1;
size_t i;
mbedtls_pk_context pk;
unsigned char hash[20];
unsigned char hash[32];
unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
char filename[512];
@ -86,7 +86,7 @@ int main( int argc, char *argv[] )
}
/*
* Extract the signature from the text file
* Extract the signature from the file
*/
ret = 1;
mbedtls_snprintf( filename, sizeof(filename), "%s.sig", argv[2] );
@ -103,8 +103,8 @@ int main( int argc, char *argv[] )
fclose( f );
/*
* Compute the SHA-256 hash of the input file and compare
* it with the hash decrypted from the signature.
* Compute the SHA-256 hash of the input file and
* verify the signature
*/
mbedtls_printf( "\n . Verifying the SHA-256 signature" );
fflush( stdout );
@ -124,7 +124,7 @@ int main( int argc, char *argv[] )
goto exit;
}
mbedtls_printf( "\n . OK (the decrypted SHA-256 hash matches)\n\n" );
mbedtls_printf( "\n . OK (the signature is valid)\n\n" );
ret = 0;
@ -132,8 +132,11 @@ exit:
mbedtls_pk_free( &pk );
#if defined(MBEDTLS_ERROR_C)
mbedtls_strerror( ret, (char *) buf, sizeof(buf) );
mbedtls_printf( " ! Last error was: %s\n", buf );
if( ret != 0 )
{
mbedtls_strerror( ret, (char *) buf, sizeof(buf) );
mbedtls_printf( " ! Last error was: %s\n", buf );
}
#endif
#if defined(_WIN32)

View File

@ -46,7 +46,7 @@
#include <string.h>
#endif
#define KEY_SIZE 1024
#define KEY_SIZE 2048
#define EXPONENT 65537
#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \

View File

@ -32,6 +32,7 @@
#include <stdio.h>
#define mbedtls_fprintf fprintf
#define mbedtls_printf printf
#define mbedtls_snprintf snprintf
#endif
#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_RSA_C) || \
@ -58,8 +59,9 @@ int main( int argc, char *argv[] )
int ret;
size_t i;
mbedtls_rsa_context rsa;
unsigned char hash[20];
unsigned char hash[32];
unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
char filename[512];
ret = 1;
@ -135,11 +137,11 @@ int main( int argc, char *argv[] )
}
/*
* Write the signature into <filename>-sig.txt
* Write the signature into <filename>.sig
*/
memcpy( argv[1] + strlen( argv[1] ), ".sig", 5 );
mbedtls_snprintf( filename, sizeof(filename), "%s.sig", argv[1] );
if( ( f = fopen( argv[1], "wb+" ) ) == NULL )
if( ( f = fopen( filename, "wb+" ) ) == NULL )
{
ret = 1;
mbedtls_printf( " failed\n ! Could not create %s\n\n", argv[1] );
@ -152,7 +154,7 @@ int main( int argc, char *argv[] )
fclose( f );
mbedtls_printf( "\n . Done (created \"%s\")\n\n", argv[1] );
mbedtls_printf( "\n . Done (created \"%s\")\n\n", filename );
exit:

View File

@ -65,7 +65,7 @@ int main( int argc, char *argv[] )
mbedtls_pk_context pk;
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
unsigned char hash[20];
unsigned char hash[32];
unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
char filename[512];
const char *pers = "rsa_sign_pss";
@ -140,7 +140,7 @@ int main( int argc, char *argv[] )
}
/*
* Write the signature into <filename>-sig.txt
* Write the signature into <filename>.sig
*/
mbedtls_snprintf( filename, 512, "%s.sig", argv[2] );

View File

@ -31,6 +31,7 @@
#else
#include <stdio.h>
#define mbedtls_printf printf
#define mbedtls_snprintf snprintf
#endif
#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_RSA_C) || \
@ -57,8 +58,9 @@ int main( int argc, char *argv[] )
int ret, c;
size_t i;
mbedtls_rsa_context rsa;
unsigned char hash[20];
unsigned char hash[32];
unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
char filename[512];
ret = 1;
if( argc != 2 )
@ -99,17 +101,15 @@ int main( int argc, char *argv[] )
* Extract the RSA signature from the text file
*/
ret = 1;
i = strlen( argv[1] );
memcpy( argv[1] + i, ".sig", 5 );
mbedtls_snprintf( filename, sizeof(filename), "%s.sig", argv[1] );
if( ( f = fopen( argv[1], "rb" ) ) == NULL )
if( ( f = fopen( filename, "rb" ) ) == NULL )
{
mbedtls_printf( "\n ! Could not open %s\n\n", argv[1] );
mbedtls_printf( "\n ! Could not open %s\n\n", filename );
goto exit;
}
argv[1][i] = '\0', i = 0;
i = 0;
while( fscanf( f, "%02X", &c ) > 0 &&
i < (int) sizeof( buf ) )
buf[i++] = (unsigned char) c;
@ -123,8 +123,8 @@ int main( int argc, char *argv[] )
}
/*
* Compute the SHA-256 hash of the input file and compare
* it with the hash decrypted from the RSA signature.
* Compute the SHA-256 hash of the input file and
* verify the signature
*/
mbedtls_printf( "\n . Verifying the RSA/SHA-256 signature" );
fflush( stdout );
@ -144,7 +144,7 @@ int main( int argc, char *argv[] )
goto exit;
}
mbedtls_printf( "\n . OK (the decrypted SHA-256 hash matches)\n\n" );
mbedtls_printf( "\n . OK (the signature is valid)\n\n" );
ret = 0;

View File

@ -63,7 +63,7 @@ int main( int argc, char *argv[] )
int ret = 1;
size_t i;
mbedtls_pk_context pk;
unsigned char hash[20];
unsigned char hash[32];
unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
char filename[512];
@ -100,7 +100,7 @@ int main( int argc, char *argv[] )
mbedtls_rsa_set_padding( mbedtls_pk_rsa( pk ), MBEDTLS_RSA_PKCS_V21, MBEDTLS_MD_SHA256 );
/*
* Extract the RSA signature from the text file
* Extract the RSA signature from the file
*/
ret = 1;
mbedtls_snprintf( filename, 512, "%s.sig", argv[2] );
@ -117,8 +117,8 @@ int main( int argc, char *argv[] )
fclose( f );
/*
* Compute the SHA-256 hash of the input file and compare
* it with the hash decrypted from the RSA signature.
* Compute the SHA-256 hash of the input file and
* verify the signature
*/
mbedtls_printf( "\n . Verifying the RSA/SHA-256 signature" );
fflush( stdout );
@ -138,7 +138,7 @@ int main( int argc, char *argv[] )
goto exit;
}
mbedtls_printf( "\n . OK (the decrypted SHA-256 hash matches)\n\n" );
mbedtls_printf( "\n . OK (the signature is valid)\n\n" );
ret = 0;

View File

@ -1925,7 +1925,7 @@ reset:
if( ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED )
{
char vrfy_buf[512];
uint32_t flags = mbedtls_ssl_get_verify_result( &ssl );
flags = mbedtls_ssl_get_verify_result( &ssl );
mbedtls_x509_crt_verify_info( vrfy_buf, sizeof( vrfy_buf ), " ! ", flags );

View File

@ -108,31 +108,31 @@ int main( void )
#define TIME_AND_TSC( TITLE, CODE ) \
do { \
unsigned long i, j, tsc; \
unsigned long ii, jj, tsc; \
\
mbedtls_printf( HEADER_FORMAT, TITLE ); \
mbedtls_printf( HEADER_FORMAT, TITLE ); \
fflush( stdout ); \
\
mbedtls_set_alarm( 1 ); \
for( i = 1; ! mbedtls_timing_alarmed; i++ ) \
mbedtls_set_alarm( 1 ); \
for( ii = 1; ! mbedtls_timing_alarmed; ii++ ) \
{ \
CODE; \
} \
\
tsc = mbedtls_timing_hardclock(); \
for( j = 0; j < 1024; j++ ) \
tsc = mbedtls_timing_hardclock(); \
for( jj = 0; jj < 1024; jj++ ) \
{ \
CODE; \
} \
\
mbedtls_printf( "%9lu Kb/s, %9lu cycles/byte\n", \
i * BUFSIZE / 1024, \
( mbedtls_timing_hardclock() - tsc ) / ( j * BUFSIZE ) ); \
mbedtls_printf( "%9lu Kb/s, %9lu cycles/byte\n", \
ii * BUFSIZE / 1024, \
( mbedtls_timing_hardclock() - tsc ) / ( jj * BUFSIZE ) ); \
} while( 0 )
#if defined(MBEDTLS_ERROR_C)
#define PRINT_ERROR \
mbedtls_strerror( ret, ( char * )tmp, sizeof( tmp ) ); \
mbedtls_strerror( ret, ( char * )tmp, sizeof( tmp ) ); \
mbedtls_printf( "FAILED: %s\n", tmp );
#else
#define PRINT_ERROR \
@ -144,12 +144,12 @@ do { \
#define MEMORY_MEASURE_INIT \
size_t max_used, max_blocks, max_bytes; \
size_t prv_used, prv_blocks; \
mbedtls_memory_buffer_alloc_cur_get( &prv_used, &prv_blocks ); \
mbedtls_memory_buffer_alloc_cur_get( &prv_used, &prv_blocks ); \
mbedtls_memory_buffer_alloc_max_reset( );
#define MEMORY_MEASURE_PRINT( title_len ) \
mbedtls_memory_buffer_alloc_max_get( &max_used, &max_blocks ); \
for( i = 12 - title_len; i != 0; i-- ) mbedtls_printf( " " ); \
mbedtls_memory_buffer_alloc_max_get( &max_used, &max_blocks ); \
for( ii = 12 - title_len; ii != 0; ii-- ) mbedtls_printf( " " ); \
max_used -= prv_used; \
max_blocks -= prv_blocks; \
max_bytes = max_used + MEM_BLOCK_OVERHEAD * max_blocks; \
@ -162,16 +162,16 @@ do { \
#define TIME_PUBLIC( TITLE, TYPE, CODE ) \
do { \
unsigned long i; \
unsigned long ii; \
int ret; \
MEMORY_MEASURE_INIT; \
\
mbedtls_printf( HEADER_FORMAT, TITLE ); \
mbedtls_printf( HEADER_FORMAT, TITLE ); \
fflush( stdout ); \
mbedtls_set_alarm( 3 ); \
mbedtls_set_alarm( 3 ); \
\
ret = 0; \
for( i = 1; ! mbedtls_timing_alarmed && ! ret ; i++ ) \
for( ii = 1; ! mbedtls_timing_alarmed && ! ret ; ii++ ) \
{ \
CODE; \
} \
@ -182,9 +182,9 @@ do { \
} \
else \
{ \
mbedtls_printf( "%6lu " TYPE "/s", i / 3 ); \
mbedtls_printf( "%6lu " TYPE "/s", ii / 3 ); \
MEMORY_MEASURE_PRINT( sizeof( TYPE ) + 1 ); \
mbedtls_printf( "\n" ); \
mbedtls_printf( "\n" ); \
} \
} while( 0 )

View File

@ -389,7 +389,7 @@ void update_dropped( const packet *p )
while( cur < end )
{
size_t len = ( ( cur[11] << 8 ) | cur[12] ) + 13;
len = ( ( cur[11] << 8 ) | cur[12] ) + 13;
id = len % sizeof( dropped );
++dropped[id];