blob: bd52bf91e6fe6323858ffef771ca9374bc607d24 [file] [log] [blame]
Paul Bakker33b43f12013-08-20 11:48:36 +02001/* BEGIN_HEADER */
Paul Bakkerf518b162012-08-23 13:03:18 +00002#include <polarssl/pbkdf2.h>
Paul Bakker33b43f12013-08-20 11:48:36 +02003/* END_HEADER */
Paul Bakkerf518b162012-08-23 13:03:18 +00004
Paul Bakker33b43f12013-08-20 11:48:36 +02005/* BEGIN_DEPENDENCIES
6 * depends_on:POLARSSL_PBKDF2_C
7 * END_DEPENDENCIES
8 */
Paul Bakkerf518b162012-08-23 13:03:18 +00009
Paul Bakker33b43f12013-08-20 11:48:36 +020010/* BEGIN_CASE */
11void pbkdf2_hmac( int hash, char *hex_password_string, char *hex_salt_string,
12 int it_cnt, int key_len, char *result_key_string )
Paul Bakkerf518b162012-08-23 13:03:18 +000013{
14 unsigned char pw_str[100];
15 unsigned char salt_str[100];
16 unsigned char dst_str[100];
17
18 md_context_t ctx;
19 const md_info_t *info;
20
21 int pw_len, salt_len;
22 unsigned char key[100];
23
24 memset(pw_str, 0x00, 100);
25 memset(salt_str, 0x00, 100);
26 memset(dst_str, 0x00, 100);
27
Paul Bakker33b43f12013-08-20 11:48:36 +020028 pw_len = unhexify( pw_str, hex_password_string );
29 salt_len = unhexify( salt_str, hex_salt_string );
Paul Bakkerf518b162012-08-23 13:03:18 +000030
31
Paul Bakker33b43f12013-08-20 11:48:36 +020032 info = md_info_from_type( hash );
Paul Bakkerf518b162012-08-23 13:03:18 +000033 TEST_ASSERT( info != NULL );
Paul Bakker68a4fce2013-08-20 12:42:31 +020034 if( info == NULL )
35 return;
Paul Bakkerf518b162012-08-23 13:03:18 +000036 TEST_ASSERT( md_init_ctx( &ctx, info ) == 0 );
37 TEST_ASSERT( pbkdf2_hmac( &ctx, pw_str, pw_len, salt_str, salt_len,
Paul Bakker33b43f12013-08-20 11:48:36 +020038 it_cnt, key_len, key ) == 0 );
Paul Bakker92b8dc02013-07-03 14:45:46 +020039 TEST_ASSERT( md_free_ctx( &ctx ) == 0 );
Paul Bakkerf518b162012-08-23 13:03:18 +000040
Paul Bakker33b43f12013-08-20 11:48:36 +020041 hexify( dst_str, key, key_len );
42 TEST_ASSERT( strcmp( (char *) dst_str, result_key_string ) == 0 );
Paul Bakkerf518b162012-08-23 13:03:18 +000043}
Paul Bakker33b43f12013-08-20 11:48:36 +020044/* END_CASE */