1/* BEGIN_HEADER */ 2#include "mbedtls/pkcs5.h" 3/* END_HEADER */ 4 5/* BEGIN_DEPENDENCIES 6 * depends_on:MBEDTLS_PKCS5_C 7 * END_DEPENDENCIES 8 */ 9 10/* BEGIN_CASE */ 11void pbkdf2_hmac( int hash, data_t * pw_str, data_t * salt_str, 12 int it_cnt, int key_len, data_t * result_key_string ) 13{ 14 mbedtls_md_context_t ctx; 15 const mbedtls_md_info_t *info; 16 17 unsigned char key[100]; 18 19 mbedtls_md_init( &ctx ); 20 21 info = mbedtls_md_info_from_type( hash ); 22 TEST_ASSERT( info != NULL ); 23 TEST_ASSERT( mbedtls_md_setup( &ctx, info, 1 ) == 0 ); 24 TEST_ASSERT( mbedtls_pkcs5_pbkdf2_hmac( &ctx, pw_str->x, pw_str->len, salt_str->x, salt_str->len, 25 it_cnt, key_len, key ) == 0 ); 26 27 TEST_ASSERT( mbedtls_test_hexcmp( key, result_key_string->x, 28 key_len, result_key_string->len ) == 0 ); 29 30exit: 31 mbedtls_md_free( &ctx ); 32} 33/* END_CASE */ 34 35/* BEGIN_CASE depends_on:MBEDTLS_ASN1_PARSE_C */ 36void mbedtls_pkcs5_pbes2( int params_tag, data_t *params_hex, data_t *pw, 37 data_t *data, int ref_ret, data_t *ref_out ) 38{ 39 int my_ret; 40 mbedtls_asn1_buf params; 41 unsigned char *my_out = NULL; 42 43 params.tag = params_tag; 44 params.p = params_hex->x; 45 params.len = params_hex->len; 46 47 my_out = mbedtls_test_zero_alloc( ref_out->len ); 48 49 my_ret = mbedtls_pkcs5_pbes2( ¶ms, MBEDTLS_PKCS5_DECRYPT, 50 pw->x, pw->len, data->x, data->len, my_out ); 51 TEST_ASSERT( my_ret == ref_ret ); 52 53 if( ref_ret == 0 ) 54 TEST_ASSERT( memcmp( my_out, ref_out->x, ref_out->len ) == 0 ); 55 56exit: 57 mbedtls_free( my_out ); 58} 59/* END_CASE */ 60 61/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ 62void pkcs5_selftest( ) 63{ 64 TEST_ASSERT( mbedtls_pkcs5_self_test( 1 ) == 0 ); 65} 66/* END_CASE */ 67