test_suite_pbkdf2.function 1.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
BEGIN_HEADER
#include <polarssl/pbkdf2.h>
END_HEADER

BEGIN_DEPENDENCIES
depends_on:POLARSSL_PBKDF2_C
END_DEPENDENCIES

BEGIN_CASE
pbkdf2_hmac:hash:hex_password_string:hex_salt_string:it_cnt:key_len:result_key_string
{
    unsigned char pw_str[100];
    unsigned char salt_str[100];
    unsigned char dst_str[100];

    md_context_t ctx;
    const md_info_t *info;
    
    int pw_len, salt_len;
    unsigned char key[100];

    memset(pw_str, 0x00, 100);
    memset(salt_str, 0x00, 100);
    memset(dst_str, 0x00, 100);

    pw_len = unhexify( pw_str, {hex_password_string} );
    salt_len = unhexify( salt_str, {hex_salt_string} );


    info = md_info_from_type( {hash} );
    TEST_ASSERT( info != NULL );
    TEST_ASSERT( md_init_ctx( &ctx, info ) == 0 );
    TEST_ASSERT( pbkdf2_hmac( &ctx, pw_str, pw_len, salt_str, salt_len,
                              {it_cnt}, {key_len}, key ) == 0 );
Paul Bakker's avatar
Paul Bakker committed
35
    TEST_ASSERT( md_free_ctx( &ctx ) == 0 );
36 37 38 39 40

    hexify( dst_str, key, {key_len} );
    TEST_ASSERT( strcmp( (char *) dst_str, {result_key_string} ) == 0 );
}
END_CASE