blob: 4b31896b82024523a76091687c45a4abab9a9be6 [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;
Paul Bakkerd2a2d612014-07-01 15:45:49 +020020
Paul Bakkerf518b162012-08-23 13:03:18 +000021 int pw_len, salt_len;
22 unsigned char key[100];
23
Paul Bakkerd2a2d612014-07-01 15:45:49 +020024 md_init( &ctx );
25
Paul Bakkerf518b162012-08-23 13:03:18 +000026 memset(pw_str, 0x00, 100);
27 memset(salt_str, 0x00, 100);
28 memset(dst_str, 0x00, 100);
29
Paul Bakker33b43f12013-08-20 11:48:36 +020030 pw_len = unhexify( pw_str, hex_password_string );
31 salt_len = unhexify( salt_str, hex_salt_string );
Paul Bakkerf518b162012-08-23 13:03:18 +000032
33
Paul Bakker33b43f12013-08-20 11:48:36 +020034 info = md_info_from_type( hash );
Paul Bakkerf518b162012-08-23 13:03:18 +000035 TEST_ASSERT( info != NULL );
Paul Bakker68a4fce2013-08-20 12:42:31 +020036 if( info == NULL )
37 return;
Paul Bakkerf518b162012-08-23 13:03:18 +000038 TEST_ASSERT( md_init_ctx( &ctx, info ) == 0 );
39 TEST_ASSERT( pbkdf2_hmac( &ctx, pw_str, pw_len, salt_str, salt_len,
Paul Bakker33b43f12013-08-20 11:48:36 +020040 it_cnt, key_len, key ) == 0 );
Paul Bakkerd2a2d612014-07-01 15:45:49 +020041 md_free( &ctx );
Paul Bakkerf518b162012-08-23 13:03:18 +000042
Paul Bakker33b43f12013-08-20 11:48:36 +020043 hexify( dst_str, key, key_len );
44 TEST_ASSERT( strcmp( (char *) dst_str, result_key_string ) == 0 );
Paul Bakkerf518b162012-08-23 13:03:18 +000045}
Paul Bakker33b43f12013-08-20 11:48:36 +020046/* END_CASE */