2013-08-20 09:48:36 +00:00
|
|
|
/* BEGIN_HEADER */
|
2015-02-06 13:57:42 +00:00
|
|
|
#include "polarssl/pbkdf2.h"
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_HEADER */
|
2012-08-23 13:03:18 +00:00
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
/* BEGIN_DEPENDENCIES
|
2015-03-23 12:59:10 +00:00
|
|
|
* depends_on:POLARSSL_PBKDF2_C:!POLARSSL_DEPRECATED_REMOVED
|
2013-08-20 09:48:36 +00:00
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
2012-08-23 13:03:18 +00:00
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
/* BEGIN_CASE */
|
|
|
|
void pbkdf2_hmac( int hash, char *hex_password_string, char *hex_salt_string,
|
|
|
|
int it_cnt, int key_len, char *result_key_string )
|
2012-08-23 13:03:18 +00:00
|
|
|
{
|
|
|
|
unsigned char pw_str[100];
|
|
|
|
unsigned char salt_str[100];
|
|
|
|
unsigned char dst_str[100];
|
|
|
|
|
|
|
|
md_context_t ctx;
|
|
|
|
const md_info_t *info;
|
2014-07-01 13:45:49 +00:00
|
|
|
|
2012-08-23 13:03:18 +00:00
|
|
|
int pw_len, salt_len;
|
|
|
|
unsigned char key[100];
|
|
|
|
|
2014-07-01 13:45:49 +00:00
|
|
|
md_init( &ctx );
|
|
|
|
|
2012-08-23 13:03:18 +00:00
|
|
|
memset(pw_str, 0x00, 100);
|
|
|
|
memset(salt_str, 0x00, 100);
|
|
|
|
memset(dst_str, 0x00, 100);
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
pw_len = unhexify( pw_str, hex_password_string );
|
|
|
|
salt_len = unhexify( salt_str, hex_salt_string );
|
2012-08-23 13:03:18 +00:00
|
|
|
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
info = md_info_from_type( hash );
|
2012-08-23 13:03:18 +00:00
|
|
|
TEST_ASSERT( info != NULL );
|
2013-08-20 10:42:31 +00:00
|
|
|
if( info == NULL )
|
|
|
|
return;
|
2012-08-23 13:03:18 +00:00
|
|
|
TEST_ASSERT( md_init_ctx( &ctx, info ) == 0 );
|
|
|
|
TEST_ASSERT( pbkdf2_hmac( &ctx, pw_str, pw_len, salt_str, salt_len,
|
2013-08-20 09:48:36 +00:00
|
|
|
it_cnt, key_len, key ) == 0 );
|
2012-08-23 13:03:18 +00:00
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
hexify( dst_str, key, key_len );
|
|
|
|
TEST_ASSERT( strcmp( (char *) dst_str, result_key_string ) == 0 );
|
2014-07-10 13:26:12 +00:00
|
|
|
|
|
|
|
exit:
|
|
|
|
md_free( &ctx );
|
2012-08-23 13:03:18 +00:00
|
|
|
}
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_CASE */
|