This commit is contained in:
wangyu- 2018-06-24 08:22:26 -05:00
parent d3cbbe8085
commit 232ec4f339
2 changed files with 10 additions and 12 deletions

View File

@ -64,10 +64,10 @@ int my_init_keys(const char * user_passwd,int is_client)
//unsigned char pbkdf2_output2[400]=""; //unsigned char pbkdf2_output2[400]="";
//PKCS5_PBKDF2_HMAC_SHA256(pbkdf2_output1,32,0,0,1, hmac_key_len*2+cipher_key_len*2,pbkdf2_output2); //stretch it //PKCS5_PBKDF2_HMAC_SHA256(pbkdf2_output1,32,0,0,1, hmac_key_len*2+cipher_key_len*2,pbkdf2_output2); //stretch it
const char *info_hmac_encrypt="server-->client hmac"; const char *info_hmac_encrypt="hmac_key server-->client";
const char *info_hmac_decrypt="client-->server hmac"; const char *info_hmac_decrypt="hmac_key client-->server";
const char *info_cipher_encrypt="server-->client cipher"; const char *info_cipher_encrypt="cipher_key server-->client";
const char *info_cipher_decrypt="client-->server cipher"; const char *info_cipher_decrypt="cipher_key client-->server";
if(is_client) if(is_client)
{ {
@ -84,10 +84,6 @@ int my_init_keys(const char * user_passwd,int is_client)
assert( hkdf_sha256_expand( pbkdf2_output1,32, (unsigned char *)info_cipher_decrypt,strlen(info_cipher_decrypt), cipher_key_decrypt, cipher_key_len ) ==0); assert( hkdf_sha256_expand( pbkdf2_output1,32, (unsigned char *)info_cipher_decrypt,strlen(info_cipher_decrypt), cipher_key_decrypt, cipher_key_len ) ==0);
assert( hkdf_sha256_expand( pbkdf2_output1,32, (unsigned char *)info_hmac_encrypt,strlen(info_hmac_encrypt), hmac_key_encrypt, hmac_key_len ) ==0); assert( hkdf_sha256_expand( pbkdf2_output1,32, (unsigned char *)info_hmac_encrypt,strlen(info_hmac_encrypt), hmac_key_encrypt, hmac_key_len ) ==0);
assert( hkdf_sha256_expand( pbkdf2_output1,32, (unsigned char *)info_hmac_decrypt,strlen(info_hmac_decrypt), hmac_key_decrypt, hmac_key_len ) ==0); assert( hkdf_sha256_expand( pbkdf2_output1,32, (unsigned char *)info_hmac_decrypt,strlen(info_hmac_decrypt), hmac_key_decrypt, hmac_key_len ) ==0);
} }
print_binary_chars(normal_key,16); print_binary_chars(normal_key,16);

View File

@ -956,14 +956,16 @@ int hkdf_sha256_expand( const unsigned char *prk,
return( MBEDTLS_ERR_HKDF_BAD_INPUT_DATA ); return( MBEDTLS_ERR_HKDF_BAD_INPUT_DATA );
} }
/* //mbedtls_md_init( &ctx ); //old code
mbedtls_md_init( &ctx ); memset( &ctx, 0, sizeof( ctx) ); //its not necessary
/*
if( (ret = mbedtls_md_setup( &ctx, md, 1) ) != 0 ) if( (ret = mbedtls_md_setup( &ctx, md, 1) ) != 0 )
{ {
goto exit; goto exit;
}*/ }*/
/* RFC 5869 Section 2.3. */ /* RFC 5869 Section 2.3. */
for( i = 1; i <= n; i++ ) for( i = 1; i <= n; i++ )
{ {
@ -988,8 +990,8 @@ int hkdf_sha256_expand( const unsigned char *prk,
} }
//exit: //exit:
//mbedtls_md_free( &ctx ); //mbedtls_md_free( &ctx ); //old code
mbedtls_platform_zeroize( &ctx, sizeof( ctx ) ); mbedtls_platform_zeroize( &ctx, sizeof( ctx ) ); //not necessary too
mbedtls_platform_zeroize( t, sizeof( t ) ); mbedtls_platform_zeroize( t, sizeof( t ) );