Files
.github
CMakeModules
dist
externals
Vulkan-Headers
cmake-modules
cubeb
discord-rpc
dynarmic
find-modules
getopt
glad
httplib
inih
libressl
libusb
libzip
mbedtls
.github
configs
doxygen
include
library
programs
scripts
tests
data_files
git-scripts
scripts
suites
helpers.function
main_test.function
test_suite_aes.cbc.data
test_suite_aes.cfb.data
test_suite_aes.ecb.data
test_suite_aes.function
test_suite_aes.ofb.data
test_suite_aes.rest.data
test_suite_aes.xts.data
test_suite_arc4.data
test_suite_arc4.function
test_suite_aria.data
test_suite_aria.function
test_suite_asn1write.data
test_suite_asn1write.function
test_suite_base64.data
test_suite_base64.function
test_suite_blowfish.data
test_suite_blowfish.function
test_suite_camellia.data
test_suite_camellia.function
test_suite_ccm.data
test_suite_ccm.function
test_suite_chacha20.data
test_suite_chacha20.function
test_suite_chachapoly.data
test_suite_chachapoly.function
test_suite_cipher.aes.data
test_suite_cipher.arc4.data
test_suite_cipher.blowfish.data
test_suite_cipher.camellia.data
test_suite_cipher.ccm.data
test_suite_cipher.chacha20.data
test_suite_cipher.chachapoly.data
test_suite_cipher.des.data
test_suite_cipher.function
test_suite_cipher.gcm.data
test_suite_cipher.null.data
test_suite_cipher.padding.data
test_suite_cmac.data
test_suite_cmac.function
test_suite_ctr_drbg.data
test_suite_ctr_drbg.function
test_suite_debug.data
test_suite_debug.function
test_suite_des.data
test_suite_des.function
test_suite_dhm.data
test_suite_dhm.function
test_suite_ecdh.data
test_suite_ecdh.function
test_suite_ecdsa.data
test_suite_ecdsa.function
test_suite_ecjpake.data
test_suite_ecjpake.function
test_suite_ecp.data
test_suite_ecp.function
test_suite_entropy.data
test_suite_entropy.function
test_suite_error.data
test_suite_error.function
test_suite_gcm.aes128_de.data
test_suite_gcm.aes128_en.data
test_suite_gcm.aes192_de.data
test_suite_gcm.aes192_en.data
test_suite_gcm.aes256_de.data
test_suite_gcm.aes256_en.data
test_suite_gcm.camellia.data
test_suite_gcm.function
test_suite_hkdf.data
test_suite_hkdf.function
test_suite_hmac_drbg.function
test_suite_hmac_drbg.misc.data
test_suite_hmac_drbg.no_reseed.data
test_suite_hmac_drbg.nopr.data
test_suite_hmac_drbg.pr.data
test_suite_md.data
test_suite_md.function
test_suite_mdx.data
test_suite_mdx.function
test_suite_memory_buffer_alloc.data
test_suite_memory_buffer_alloc.function
test_suite_mpi.data
test_suite_mpi.function
test_suite_nist_kw.data
test_suite_nist_kw.function
test_suite_pem.data
test_suite_pem.function
test_suite_pk.data
test_suite_pk.function
test_suite_pkcs1_v15.data
test_suite_pkcs1_v15.function
test_suite_pkcs1_v21.data
test_suite_pkcs1_v21.function
test_suite_pkcs5.data
test_suite_pkcs5.function
test_suite_pkparse.data
test_suite_pkparse.function
test_suite_pkwrite.data
test_suite_pkwrite.function
test_suite_poly1305.data
test_suite_poly1305.function
test_suite_rsa.data
test_suite_rsa.function
test_suite_shax.data
test_suite_shax.function
test_suite_ssl.data
test_suite_ssl.function
test_suite_timing.data
test_suite_timing.function
test_suite_version.data
test_suite_version.function
test_suite_x509parse.data
test_suite_x509parse.function
test_suite_x509write.data
test_suite_x509write.function
test_suite_xtea.data
test_suite_xtea.function
.gitignore
CMakeLists.txt
Descriptions.txt
Makefile
compat.sh
ssl-opt.sh
visualc
.gitignore
.travis.yml
CMakeLists.txt
CONTRIBUTING.md
ChangeLog
DartConfiguration.tcl
LICENSE
Makefile
README.md
circle.yml
gpl-2.0.txt
microprofile
opus
sirit
soundtouch
xbyak
CMakeLists.txt
patches
src
CMakeLists.txt
LICENSE
README.md
license.txt
yuzu/externals/mbedtls/tests/suites/test_suite_pkcs5.function

88 lines
2.4 KiB
Plaintext
Raw Normal View History

2020-12-28 15:15:37 +00:00
/* BEGIN_HEADER */
#include "mbedtls/pkcs5.h"
/* END_HEADER */
/* BEGIN_DEPENDENCIES
* depends_on:MBEDTLS_PKCS5_C
* END_DEPENDENCIES
*/
/* BEGIN_CASE */
void pbkdf2_hmac( int hash, char *hex_password_string,
char *hex_salt_string, int it_cnt, int key_len,
char *result_key_string )
{
unsigned char pw_str[100];
unsigned char salt_str[100];
unsigned char dst_str[200];
mbedtls_md_context_t ctx;
const mbedtls_md_info_t *info;
int pw_len, salt_len;
unsigned char key[100];
mbedtls_md_init( &ctx );
memset(pw_str, 0x00, sizeof(pw_str));
memset(salt_str, 0x00, sizeof(salt_str));
memset(dst_str, 0x00, sizeof(dst_str));
pw_len = unhexify( pw_str, hex_password_string );
salt_len = unhexify( salt_str, hex_salt_string );
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 );
hexify( dst_str, key, key_len );
TEST_ASSERT( strcmp( (char *) dst_str, result_key_string ) == 0 );
exit:
mbedtls_md_free( &ctx );
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ASN1_PARSE_C */
void mbedtls_pkcs5_pbes2( int params_tag, char *params_hex, char *pw_hex,
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;
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 );
my_ret = mbedtls_pkcs5_pbes2( &params, MBEDTLS_PKCS5_DECRYPT,
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 );
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
void pkcs5_selftest( )
{
TEST_ASSERT( mbedtls_pkcs5_self_test( 1 ) == 0 );
}
/* END_CASE */