mbedtls/tests/suites/test_suite_pkcs5.function

75 lines
2.1 KiB
Text
Raw Normal View History

/* BEGIN_HEADER */
2015-03-09 18:05:11 +01:00
#include "mbedtls/pkcs5.h"
/* END_HEADER */
/* BEGIN_DEPENDENCIES
* depends_on:MBEDTLS_PKCS5_C
* END_DEPENDENCIES
*/
/* BEGIN_CASE */
2017-05-30 15:23:15 +02:00
void pbkdf2_hmac( int hash, uint8_t * pw_str, uint32_t pw_len,
uint8_t * salt_str, uint32_t salt_len, int it_cnt,
int key_len, uint8_t * result_key_string,
uint32_t result_key_string_len )
{
mbedtls_md_context_t ctx;
const mbedtls_md_info_t *info;
unsigned char key[100];
mbedtls_md_init( &ctx );
2014-07-01 15:45:49 +02:00
info = mbedtls_md_info_from_type( hash );
TEST_ASSERT( info != NULL );
TEST_ASSERT( mbedtls_md_setup( &ctx, info, 1 ) == 0 );
TEST_ASSERT( mbedtls_pkcs5_pbkdf2_hmac( &ctx, pw_str, pw_len, salt_str, salt_len,
it_cnt, key_len, key ) == 0 );
2017-05-30 15:23:15 +02:00
TEST_ASSERT( hexcmp( key, result_key_string, key_len, result_key_string_len ) == 0 );
exit:
mbedtls_md_free( &ctx );
}
/* END_CASE */
2014-06-12 13:14:55 +02:00
/* BEGIN_CASE depends_on:MBEDTLS_ASN1_PARSE_C */
void mbedtls_pkcs5_pbes2( int params_tag, char *params_hex, char *pw_hex,
2014-06-12 13:14:55 +02:00
char *data_hex, int ref_ret, char *ref_out_hex )
{
int my_ret;
mbedtls_asn1_buf params;
unsigned char *my_out = NULL, *ref_out = NULL, *data = NULL, *pw = NULL;
2014-06-12 13:14:55 +02:00
size_t ref_out_len, data_len, pw_len;
params.tag = params_tag;
params.p = unhexify_alloc( params_hex, &params.len );
data = unhexify_alloc( data_hex, &data_len );
pw = unhexify_alloc( pw_hex, &pw_len );
ref_out = unhexify_alloc( ref_out_hex, &ref_out_len );
my_out = zero_alloc( ref_out_len );
2014-06-12 13:14:55 +02:00
my_ret = mbedtls_pkcs5_pbes2( &params, MBEDTLS_PKCS5_DECRYPT,
2014-06-12 13:14:55 +02:00
pw, pw_len, data, data_len, my_out );
TEST_ASSERT( my_ret == ref_ret );
if( ref_ret == 0 )
TEST_ASSERT( memcmp( my_out, ref_out, ref_out_len ) == 0 );
exit:
mbedtls_free( params.p );
mbedtls_free( data );
mbedtls_free( pw );
mbedtls_free( ref_out );
mbedtls_free( my_out );
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
{
TEST_ASSERT( mbedtls_pkcs5_self_test( 1 ) == 0 );
2016-07-19 15:54:57 +02:00
}
/* END_CASE */