2020-12-28 19:15:37 +04:00
|
|
|
/* BEGIN_HEADER */
|
|
|
|
#include "mbedtls/pkcs5.h"
|
|
|
|
/* END_HEADER */
|
|
|
|
|
|
|
|
/* BEGIN_DEPENDENCIES
|
|
|
|
* depends_on:MBEDTLS_PKCS5_C
|
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2021-03-06 04:41:47 +04:00
|
|
|
void pbkdf2_hmac( int hash, data_t * pw_str, data_t * salt_str,
|
|
|
|
int it_cnt, int key_len, data_t * result_key_string )
|
2020-12-28 19:15:37 +04:00
|
|
|
{
|
|
|
|
mbedtls_md_context_t ctx;
|
|
|
|
const mbedtls_md_info_t *info;
|
|
|
|
|
|
|
|
unsigned char key[100];
|
|
|
|
|
|
|
|
mbedtls_md_init( &ctx );
|
|
|
|
|
|
|
|
info = mbedtls_md_info_from_type( hash );
|
|
|
|
TEST_ASSERT( info != NULL );
|
|
|
|
TEST_ASSERT( mbedtls_md_setup( &ctx, info, 1 ) == 0 );
|
2021-03-06 04:41:47 +04:00
|
|
|
TEST_ASSERT( mbedtls_pkcs5_pbkdf2_hmac( &ctx, pw_str->x, pw_str->len, salt_str->x, salt_str->len,
|
2020-12-28 19:15:37 +04:00
|
|
|
it_cnt, key_len, key ) == 0 );
|
|
|
|
|
2021-03-06 04:41:47 +04:00
|
|
|
TEST_ASSERT( mbedtls_test_hexcmp( key, result_key_string->x,
|
|
|
|
key_len, result_key_string->len ) == 0 );
|
2020-12-28 19:15:37 +04:00
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_md_free( &ctx );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_ASN1_PARSE_C */
|
2021-03-06 04:41:47 +04:00
|
|
|
void mbedtls_pkcs5_pbes2( int params_tag, data_t *params_hex, data_t *pw,
|
|
|
|
data_t *data, int ref_ret, data_t *ref_out )
|
2020-12-28 19:15:37 +04:00
|
|
|
{
|
|
|
|
int my_ret;
|
|
|
|
mbedtls_asn1_buf params;
|
2021-03-06 04:41:47 +04:00
|
|
|
unsigned char *my_out = NULL;
|
2020-12-28 19:15:37 +04:00
|
|
|
|
|
|
|
params.tag = params_tag;
|
2021-03-06 04:41:47 +04:00
|
|
|
params.p = params_hex->x;
|
|
|
|
params.len = params_hex->len;
|
2020-12-28 19:15:37 +04:00
|
|
|
|
2021-03-06 04:41:47 +04:00
|
|
|
my_out = zero_alloc( ref_out->len );
|
2020-12-28 19:15:37 +04:00
|
|
|
|
|
|
|
my_ret = mbedtls_pkcs5_pbes2( ¶ms, MBEDTLS_PKCS5_DECRYPT,
|
2021-03-06 04:41:47 +04:00
|
|
|
pw->x, pw->len, data->x, data->len, my_out );
|
2020-12-28 19:15:37 +04:00
|
|
|
TEST_ASSERT( my_ret == ref_ret );
|
|
|
|
|
|
|
|
if( ref_ret == 0 )
|
2021-03-06 04:41:47 +04:00
|
|
|
TEST_ASSERT( memcmp( my_out, ref_out->x, ref_out->len ) == 0 );
|
2020-12-28 19:15:37 +04:00
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_free( my_out );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
2021-03-06 04:41:47 +04:00
|
|
|
void pkcs5_selftest( )
|
2020-12-28 19:15:37 +04:00
|
|
|
{
|
|
|
|
TEST_ASSERT( mbedtls_pkcs5_self_test( 1 ) == 0 );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|