2013-08-20 11:48:36 +02:00
|
|
|
/* BEGIN_HEADER */
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/pkcs5.h"
|
2022-09-15 11:29:35 +02:00
|
|
|
#include "mbedtls/legacy_or_psa.h"
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_HEADER */
|
2013-06-24 19:26:38 +02:00
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
/* BEGIN_DEPENDENCIES
|
2015-04-08 12:49:31 +02:00
|
|
|
* depends_on:MBEDTLS_PKCS5_C
|
2013-08-20 11:48:36 +02:00
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
2013-06-24 19:26:38 +02:00
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
/* BEGIN_CASE */
|
2018-06-29 12:05:32 +02: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 )
|
2013-06-24 19:26:38 +02:00
|
|
|
{
|
|
|
|
unsigned char key[100];
|
|
|
|
|
2022-09-01 15:23:09 +02:00
|
|
|
PSA_INIT_IF_NO_MD();
|
2022-08-31 19:29:38 +02:00
|
|
|
TEST_ASSERT( mbedtls_pkcs5_pbkdf2_hmac_ext( hash, pw_str->x, pw_str->len,
|
|
|
|
salt_str->x, salt_str->len,
|
|
|
|
it_cnt, key_len, key ) == 0 );
|
2013-06-24 19:26:38 +02:00
|
|
|
|
2020-06-10 11:42:32 +02:00
|
|
|
TEST_ASSERT( mbedtls_test_hexcmp( key, result_key_string->x,
|
|
|
|
key_len, result_key_string->len ) == 0 );
|
2022-09-01 15:23:09 +02:00
|
|
|
PSA_DONE_IF_NO_MD();
|
2013-06-24 19:26:38 +02:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|
2014-06-12 13:14:55 +02:00
|
|
|
|
2018-03-27 21:53:56 +02:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_ASN1_PARSE_C */
|
2018-06-29 12:05:32 +02: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 )
|
2014-06-12 13:14:55 +02:00
|
|
|
{
|
|
|
|
int my_ret;
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_asn1_buf params;
|
2017-06-09 05:32:58 +02:00
|
|
|
unsigned char *my_out = NULL;
|
2014-06-12 13:14:55 +02:00
|
|
|
|
2022-09-01 15:23:09 +02:00
|
|
|
PSA_INIT_IF_NO_MD();
|
2022-08-31 21:10:50 +02:00
|
|
|
|
2014-06-12 13:14:55 +02:00
|
|
|
params.tag = params_tag;
|
2017-06-09 05:32:58 +02:00
|
|
|
params.p = params_hex->x;
|
|
|
|
params.len = params_hex->len;
|
2014-06-12 13:14:55 +02:00
|
|
|
|
2020-06-10 10:42:18 +02:00
|
|
|
my_out = mbedtls_test_zero_alloc( ref_out->len );
|
2014-06-12 13:14:55 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
my_ret = mbedtls_pkcs5_pbes2( ¶ms, MBEDTLS_PKCS5_DECRYPT,
|
2017-06-09 05:32:58 +02:00
|
|
|
pw->x, pw->len, data->x, data->len, my_out );
|
2014-06-12 13:14:55 +02:00
|
|
|
TEST_ASSERT( my_ret == ref_ret );
|
|
|
|
|
|
|
|
if( ref_ret == 0 )
|
2017-06-09 05:32:58 +02:00
|
|
|
TEST_ASSERT( memcmp( my_out, ref_out->x, ref_out->len ) == 0 );
|
2014-06-12 13:14:55 +02:00
|
|
|
|
2014-07-10 15:26:12 +02:00
|
|
|
exit:
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_free( my_out );
|
2022-09-01 15:23:09 +02:00
|
|
|
PSA_DONE_IF_NO_MD();
|
2014-06-12 13:14:55 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
2016-07-19 15:54:57 +02:00
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
2017-05-30 15:23:15 +02:00
|
|
|
void pkcs5_selftest( )
|
2016-07-19 15:54:57 +02:00
|
|
|
{
|
2016-09-09 10:10:28 +02:00
|
|
|
TEST_ASSERT( mbedtls_pkcs5_self_test( 1 ) == 0 );
|
2016-07-19 15:54:57 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|