#include <tests/unit.h>
#ifdef NO_INLINE
#include <wolfssl/wolfcrypt/misc.h>
#else
#define WOLFSSL_MISC_INCLUDED
#include <wolfcrypt/src/misc.c>
#endif
#include <wolfssl/wolfcrypt/pkcs12.h>
#include <wolfssl/wolfcrypt/pwdbased.h>
#include <wolfssl/wolfcrypt/types.h>
#include <tests/api/api.h>
#include <tests/api/test_pkcs12.h>
int test_wc_i2d_PKCS12(void)
{
EXPECT_DECLS;
#if !defined(NO_ASN) && !defined(NO_PWDBASED) && defined(HAVE_PKCS12) \
&& !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
&& !defined(NO_AES) && !defined(NO_SHA) && !defined(NO_SHA256)
WC_PKCS12* pkcs12 = NULL;
unsigned char der[FOURK_BUF * 2];
unsigned char* pt;
int derSz = 0;
unsigned char out[FOURK_BUF * 2];
int outSz = FOURK_BUF * 2;
const char p12_f[] = "./certs/test-servercert.p12";
XFILE f = XBADFILE;
ExpectTrue((f = XFOPEN(p12_f, "rb")) != XBADFILE);
ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
if (f != XBADFILE)
XFCLOSE(f);
ExpectNotNull(pkcs12 = wc_PKCS12_new());
ExpectIntEQ(wc_d2i_PKCS12(der, (word32)derSz, pkcs12), 0);
ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
ExpectIntEQ(outSz, derSz);
outSz = derSz - 1;
pt = out;
ExpectIntLE(wc_i2d_PKCS12(pkcs12, &pt, &outSz), 0);
outSz = derSz;
ExpectIntEQ(wc_i2d_PKCS12(pkcs12, &pt, &outSz), derSz);
ExpectIntEQ((pt == out), 0);
pt = NULL;
ExpectIntEQ(wc_i2d_PKCS12(pkcs12, &pt, NULL), derSz);
XFREE(pt, NULL, DYNAMIC_TYPE_PKCS);
wc_PKCS12_free(pkcs12);
pkcs12 = NULL;
ExpectNotNull(pkcs12 = wc_PKCS12_new());
ExpectIntEQ(wc_d2i_PKCS12_fp("./certs/test-servercert.p12", &pkcs12), 0);
ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
ExpectIntEQ(outSz, derSz);
wc_PKCS12_free(pkcs12);
pkcs12 = NULL;
ExpectIntEQ(wc_d2i_PKCS12_fp("./certs/test-servercert.p12", &pkcs12), 0);
ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
ExpectIntEQ(outSz, derSz);
wc_PKCS12_free(pkcs12);
pkcs12 = NULL;
#endif
return EXPECT_RESULT();
}
static int test_wc_PKCS12_create_once(int keyEncType, int certEncType)
{
EXPECT_DECLS;
#if !defined(NO_ASN) && defined(HAVE_PKCS12) && !defined(NO_PWDBASED) && \
!defined(NO_RSA) && !defined(NO_ASN_CRYPT) && \
!defined(NO_HMAC) && !defined(NO_CERTS) && defined(USE_CERT_BUFFERS_2048)
byte* inKey = (byte*) server_key_der_2048;
const word32 inKeySz= sizeof_server_key_der_2048;
byte* inCert = (byte*) server_cert_der_2048;
const word32 inCertSz = sizeof_server_cert_der_2048;
WC_DerCertList inCa = {
(byte*)ca_cert_der_2048, sizeof_ca_cert_der_2048, NULL
};
char pkcs12Passwd[] = "test_wc_PKCS12_create";
WC_PKCS12* pkcs12Export = NULL;
WC_PKCS12* pkcs12Import = NULL;
byte* pkcs12Der = NULL;
byte* outKey = NULL;
byte* outCert = NULL;
WC_DerCertList* outCaList = NULL;
word32 pkcs12DerSz = 0;
word32 outKeySz = 0;
word32 outCertSz = 0;
ExpectNotNull(pkcs12Export = wc_PKCS12_create(pkcs12Passwd,
sizeof(pkcs12Passwd) - 1,
(char*) "friendlyName" ,
inKey, inKeySz, inCert, inCertSz, &inCa, keyEncType, certEncType,
2048, 2048, 0 , NULL));
pkcs12Der = NULL;
ExpectIntGE((pkcs12DerSz = wc_i2d_PKCS12(pkcs12Export, &pkcs12Der, NULL)),
0);
ExpectNotNull(pkcs12Import = wc_PKCS12_new_ex(NULL));
ExpectIntGE(wc_d2i_PKCS12(pkcs12Der, pkcs12DerSz, pkcs12Import), 0);
ExpectIntEQ(wc_PKCS12_parse(pkcs12Import, pkcs12Passwd, &outKey, &outKeySz,
&outCert, &outCertSz, &outCaList), 0);
ExpectIntEQ(outKeySz, inKeySz);
ExpectIntEQ(outCertSz, inCertSz);
ExpectNotNull(outCaList);
ExpectNotNull(outCaList->buffer);
ExpectIntEQ(outCaList->bufferSz, inCa.bufferSz);
ExpectNull(outCaList->next);
ExpectIntEQ(XMEMCMP(inKey, outKey, outKeySz), 0);
ExpectIntEQ(XMEMCMP(inCert, outCert, outCertSz), 0);
ExpectIntEQ(XMEMCMP(inCa.buffer, outCaList->buffer, outCaList->bufferSz),
0);
XFREE(outKey, NULL, DYNAMIC_TYPE_PUBLIC_KEY);
XFREE(outCert, NULL, DYNAMIC_TYPE_PKCS);
wc_FreeCertList(outCaList, NULL);
wc_PKCS12_free(pkcs12Import);
XFREE(pkcs12Der, NULL, DYNAMIC_TYPE_PKCS);
wc_PKCS12_free(pkcs12Export);
#endif
(void) keyEncType;
(void) certEncType;
return EXPECT_RESULT();
}
int test_wc_PKCS12_create(void)
{
EXPECT_DECLS;
#ifndef NO_SHA256
EXPECT_TEST(test_wc_PKCS12_create_once(-1, -1));
#if !defined(NO_RC4) && !defined(NO_SHA)
EXPECT_TEST(test_wc_PKCS12_create_once(PBE_SHA1_RC4_128, PBE_SHA1_RC4_128));
#endif
#if !defined(NO_DES3) && !defined(NO_SHA)
EXPECT_TEST(test_wc_PKCS12_create_once(PBE_SHA1_DES, PBE_SHA1_DES));
#endif
#if !defined(NO_DES3) && !defined(NO_SHA)
EXPECT_TEST(test_wc_PKCS12_create_once(PBE_SHA1_DES3, PBE_SHA1_DES3));
#endif
#if defined(HAVE_AES_CBC) && !defined(NO_AES) && !defined(NO_AES_256) && \
!defined(NO_SHA) && defined(WOLFSSL_ASN_TEMPLATE)
EXPECT_TEST(test_wc_PKCS12_create_once(PBE_AES256_CBC, PBE_AES256_CBC));
#endif
#if defined(HAVE_AES_CBC) && !defined(NO_AES) && !defined(NO_AES_128) && \
!defined(NO_SHA) && defined(WOLFSSL_ASN_TEMPLATE)
EXPECT_TEST(test_wc_PKCS12_create_once(PBE_AES128_CBC, PBE_AES128_CBC));
#endif
#if defined(HAVE_AES_CBC) && !defined(NO_AES) && !defined(NO_AES_256) && \
!defined(NO_SHA) && defined(WOLFSSL_ASN_TEMPLATE) && !defined(NO_DES3)
EXPECT_TEST(test_wc_PKCS12_create_once(PBE_AES256_CBC, PBE_SHA1_DES3));
#endif
#endif
(void) test_wc_PKCS12_create_once;
return EXPECT_RESULT();
}
int test_wc_d2i_PKCS12_bad_mac_salt(void)
{
EXPECT_DECLS;
#if !defined(NO_ASN) && !defined(NO_PWDBASED) && defined(HAVE_PKCS12) \
&& !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
&& !defined(NO_AES) && !defined(NO_SHA) && !defined(NO_SHA256)
WC_PKCS12* pkcs12 = NULL;
unsigned char der[FOURK_BUF * 2];
int derSz = 0;
const char p12_f[] = "./certs/test-servercert.p12";
XFILE f = XBADFILE;
int i;
int found = 0;
ExpectTrue((f = XFOPEN(p12_f, "rb")) != XBADFILE);
ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
if (f != XBADFILE)
XFCLOSE(f);
for (i = derSz - 2; i >= 0 && i >= derSz - 100; i--) {
if (der[i] == 0x04 && der[i + 1] == 0x08) {
der[i + 1] = 0xFF;
found = 1;
break;
}
}
ExpectIntEQ(found, 1);
ExpectNotNull(pkcs12 = wc_PKCS12_new());
ExpectIntNE(wc_d2i_PKCS12(der, (word32)derSz, pkcs12), 0);
wc_PKCS12_free(pkcs12);
#endif
return EXPECT_RESULT();
}
int test_wc_d2i_PKCS12_oid_underflow(void)
{
EXPECT_DECLS;
#if !defined(NO_ASN) && !defined(NO_PWDBASED) && defined(HAVE_PKCS12)
WC_PKCS12* pkcs12 = NULL;
static const byte crafted[] = {
0x30, 0x23,
0x02, 0x01, 0x03,
0x30, 0x1E,
0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
0x01, 0x07, 0x01,
0xA0, 0x11,
0x04, 0x0F,
0x30, 0x0D,
0x30, 0x05,
0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
0x01, 0x07, 0x01
};
ExpectNotNull(pkcs12 = wc_PKCS12_new());
ExpectIntEQ(wc_d2i_PKCS12(crafted, (word32)sizeof(crafted), pkcs12),
ASN_PARSE_E);
wc_PKCS12_free(pkcs12);
#endif
return EXPECT_RESULT();
}
int test_wc_PKCS12_PBKDF(void)
{
EXPECT_DECLS;
#if defined(HAVE_PKCS12) && !defined(NO_PWDBASED) && !defined(NO_SHA256)
static const byte passwd[] = {
0x00, 0x73, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x67,
0x00, 0x00
};
static const byte salt[] = {
0x0a, 0x58, 0xCF, 0x64, 0x53, 0x0d, 0x82, 0x3f
};
static const byte passwd2[] = {
0x00, 0x71, 0x00, 0x75, 0x00, 0x65, 0x00, 0x65,
0x00, 0x67, 0x00, 0x00
};
static const byte salt2[] = {
0x16, 0x82, 0xC0, 0xfC, 0x5b, 0x3f, 0x7e, 0xc5
};
static const byte verify[] = {
0x27, 0xE9, 0x0D, 0x7E, 0xD5, 0xA1, 0xC4, 0x11,
0xBA, 0x87, 0x8B, 0xC0, 0x90, 0xF5, 0xCE, 0xBE,
0x5E, 0x9D, 0x5F, 0xE3, 0xD6, 0x2B, 0x73, 0xAA
};
static const byte verify2[] = {
0x90, 0x1B, 0x49, 0x70, 0xF0, 0x94, 0xF0, 0xF8,
0x45, 0xC0, 0xF3, 0xF3, 0x13, 0x59, 0x18, 0x6A,
0x35, 0xE3, 0x67, 0xFE, 0xD3, 0x21, 0xFD, 0x7C
};
byte derived[24];
ExpectIntNE(wc_PKCS12_PBKDF(NULL, passwd, (int)sizeof(passwd),
salt, (int)sizeof(salt), 1, 24, WC_SHA256, 1), 0);
ExpectIntNE(wc_PKCS12_PBKDF(derived, passwd, 0,
salt, (int)sizeof(salt), 1, 24, WC_SHA256, 1), 0);
ExpectIntNE(wc_PKCS12_PBKDF(derived, passwd, (int)sizeof(passwd),
salt, 0, 1, 24, WC_SHA256, 1), 0);
ExpectIntEQ(wc_PKCS12_PBKDF(derived, passwd, (int)sizeof(passwd),
salt, (int)sizeof(salt), 1, 24, WC_SHA256, 1), 0);
ExpectIntEQ(XMEMCMP(derived, verify, 24), 0);
ExpectIntEQ(wc_PKCS12_PBKDF(derived, passwd2, (int)sizeof(passwd2),
salt2, (int)sizeof(salt2), 1000, 24, WC_SHA256, 1), 0);
ExpectIntEQ(XMEMCMP(derived, verify2, 24), 0);
ExpectIntEQ(wc_PKCS12_PBKDF(derived, passwd, (int)sizeof(passwd),
salt, (int)sizeof(salt), 0, 24, WC_SHA256, 1), 0);
ExpectIntEQ(XMEMCMP(derived, verify, 24), 0);
#endif
return EXPECT_RESULT();
}
int test_wc_PKCS12_PBKDF_ex(void)
{
EXPECT_DECLS;
#if defined(HAVE_PKCS12) && !defined(NO_PWDBASED) && !defined(NO_SHA256)
static const byte passwd[] = {
0x00, 0x73, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x67,
0x00, 0x00
};
static const byte salt[] = {
0x0a, 0x58, 0xCF, 0x64, 0x53, 0x0d, 0x82, 0x3f
};
static const byte passwd2[] = {
0x00, 0x71, 0x00, 0x75, 0x00, 0x65, 0x00, 0x65,
0x00, 0x67, 0x00, 0x00
};
static const byte salt2[] = {
0x16, 0x82, 0xC0, 0xfC, 0x5b, 0x3f, 0x7e, 0xc5
};
static const byte verify[] = {
0x27, 0xE9, 0x0D, 0x7E, 0xD5, 0xA1, 0xC4, 0x11,
0xBA, 0x87, 0x8B, 0xC0, 0x90, 0xF5, 0xCE, 0xBE,
0x5E, 0x9D, 0x5F, 0xE3, 0xD6, 0x2B, 0x73, 0xAA
};
static const byte verify2[] = {
0x90, 0x1B, 0x49, 0x70, 0xF0, 0x94, 0xF0, 0xF8,
0x45, 0xC0, 0xF3, 0xF3, 0x13, 0x59, 0x18, 0x6A,
0x35, 0xE3, 0x67, 0xFE, 0xD3, 0x21, 0xFD, 0x7C
};
byte derived[24];
byte derived2[24];
ExpectIntNE(wc_PKCS12_PBKDF_ex(NULL, passwd, (int)sizeof(passwd),
salt, (int)sizeof(salt), 1, 24, WC_SHA256, 1, NULL), 0);
ExpectIntNE(wc_PKCS12_PBKDF_ex(derived, passwd, 0,
salt, (int)sizeof(salt), 1, 24, WC_SHA256, 1, NULL), 0);
ExpectIntNE(wc_PKCS12_PBKDF_ex(derived, passwd, (int)sizeof(passwd),
salt, 0, 1, 24, WC_SHA256, 1, NULL), 0);
ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd, (int)sizeof(passwd),
salt, (int)sizeof(salt), 1, 24, WC_SHA256, 1, NULL), 0);
ExpectIntEQ(XMEMCMP(derived, verify, 24), 0);
ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd2, (int)sizeof(passwd2),
salt2, (int)sizeof(salt2), 1000, 24, WC_SHA256, 1, NULL), 0);
ExpectIntEQ(XMEMCMP(derived, verify2, 24), 0);
ExpectIntEQ(wc_PKCS12_PBKDF(derived2, passwd2, (int)sizeof(passwd2),
salt2, (int)sizeof(salt2), 1000, 24, WC_SHA256, 1), 0);
ExpectIntEQ(XMEMCMP(derived, derived2, 24), 0);
ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd, (int)sizeof(passwd),
salt, (int)sizeof(salt), 1, 24, WC_SHA256, 2, NULL), 0);
ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd, (int)sizeof(passwd),
salt, (int)sizeof(salt), 1, 24, WC_SHA256, 3, NULL), 0);
#endif
return EXPECT_RESULT();
}
int test_wc_PKCS12_PBKDF_ex_sha1(void)
{
EXPECT_DECLS;
#if defined(HAVE_PKCS12) && !defined(NO_PWDBASED) && !defined(NO_SHA)
static const byte passwd[] = {
0x00, 0x73, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x67,
0x00, 0x00
};
static const byte salt[] = {
0x0a, 0x58, 0xCF, 0x64, 0x53, 0x0d, 0x82, 0x3f
};
static const byte passwd2[] = {
0x00, 0x71, 0x00, 0x75, 0x00, 0x65, 0x00, 0x65,
0x00, 0x67, 0x00, 0x00
};
static const byte salt2[] = {
0x16, 0x82, 0xC0, 0xfC, 0x5b, 0x3f, 0x7e, 0xc5
};
static const byte verify[] = {
0x8A, 0xAA, 0xE6, 0x29, 0x7B, 0x6C, 0xB0, 0x46,
0x42, 0xAB, 0x5B, 0x07, 0x78, 0x51, 0x28, 0x4E,
0xB7, 0x12, 0x8F, 0x1A, 0x2A, 0x7F, 0xBC, 0xA3
};
static const byte verify2[] = {
0x48, 0x3D, 0xD6, 0xE9, 0x19, 0xD7, 0xDE, 0x2E,
0x8E, 0x64, 0x8B, 0xA8, 0xF8, 0x62, 0xF3, 0xFB,
0xFB, 0xDC, 0x2B, 0xCB, 0x2C, 0x02, 0x95, 0x7F
};
byte derived[24];
ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd, (int)sizeof(passwd),
salt, (int)sizeof(salt), 1, 24, WC_SHA, 1, NULL), 0);
ExpectIntEQ(XMEMCMP(derived, verify, 24), 0);
ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd2, (int)sizeof(passwd2),
salt2, (int)sizeof(salt2), 1000, 24, WC_SHA, 1, NULL), 0);
ExpectIntEQ(XMEMCMP(derived, verify2, 24), 0);
#endif
return EXPECT_RESULT();
}
int test_wc_PKCS12_PBKDF_ex_sha512(void)
{
EXPECT_DECLS;
#if defined(HAVE_PKCS12) && !defined(NO_PWDBASED) && defined(WOLFSSL_SHA512)
static const byte passwd[] = {
0x00, 0x73, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x67,
0x00, 0x00
};
static const byte salt[] = {
0x0a, 0x58, 0xCF, 0x64, 0x53, 0x0d, 0x82, 0x3f
};
static const byte passwd2[] = {
0x00, 0x71, 0x00, 0x75, 0x00, 0x65, 0x00, 0x65,
0x00, 0x67, 0x00, 0x00
};
static const byte salt2[] = {
0x16, 0x82, 0xC0, 0xfC, 0x5b, 0x3f, 0x7e, 0xc5
};
static const byte verify[] = {
0x13, 0x04, 0xA9, 0xF0, 0x01, 0x53, 0x74, 0x25,
0x24, 0x12, 0x7D, 0x51, 0xD5, 0x98, 0xBC, 0x04,
0x7E, 0x64, 0x09, 0x03, 0x09, 0xCA, 0x84, 0xEB,
0x31, 0x2E, 0xB3, 0xBA, 0xD5, 0x60, 0xDD, 0x8D,
0x2C, 0x71, 0xAB, 0xA4, 0xF2, 0x15, 0xAB, 0x31,
0xF3, 0xBC, 0x42, 0xB6, 0xE8, 0x5D, 0xBF, 0x89
};
static const byte verify2[] = {
0xBC, 0xD9, 0x78, 0x3D, 0x77, 0x8D, 0xA0, 0xE4,
0x69, 0x00, 0x0B, 0x28, 0xE0, 0xD5, 0xDF, 0xDA,
0xF3, 0xC9, 0x8D, 0x77, 0x39, 0xF9, 0x76, 0x84,
0x1D, 0xE9, 0x61, 0x79, 0x50, 0x16, 0x6B, 0xA5,
0x1B, 0x1D, 0x07, 0x65, 0x1B, 0x4B, 0x98, 0x91,
0xAF, 0xE1, 0x80, 0x15, 0x39, 0xA3, 0x42, 0xDD
};
byte derived[48];
ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd, (int)sizeof(passwd),
salt, (int)sizeof(salt), 1, 48, WC_SHA512, 1, NULL), 0);
ExpectIntEQ(XMEMCMP(derived, verify, 48), 0);
ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd2, (int)sizeof(passwd2),
salt2, (int)sizeof(salt2), 1000, 48, WC_SHA512, 1, NULL), 0);
ExpectIntEQ(XMEMCMP(derived, verify2, 48), 0);
#endif
return EXPECT_RESULT();
}
int test_wc_PKCS12_PBKDF_ex_sha224(void)
{
EXPECT_DECLS;
#if defined(HAVE_PKCS12) && !defined(NO_PWDBASED) && defined(WOLFSSL_SHA224)
static const byte passwd[] = {
0x00, 0x73, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x67,
0x00, 0x00
};
static const byte salt[] = {
0x0a, 0x58, 0xCF, 0x64, 0x53, 0x0d, 0x82, 0x3f
};
static const byte passwd2[] = {
0x00, 0x71, 0x00, 0x75, 0x00, 0x65, 0x00, 0x65,
0x00, 0x67, 0x00, 0x00
};
static const byte salt2[] = {
0x16, 0x82, 0xC0, 0xfC, 0x5b, 0x3f, 0x7e, 0xc5
};
static const byte verify[] = {
0x96, 0x22, 0xB0, 0x87, 0xFF, 0xE5, 0xDC, 0xB2,
0xA6, 0xE1, 0x67, 0x3A, 0x44, 0x11, 0x50, 0x00,
0x67, 0xE7, 0x10, 0xB4, 0xE6, 0x63, 0x4D, 0xCF,
0x37, 0x0C, 0x25, 0x3C
};
static const byte verify2[] = {
0x9A, 0x30, 0xD2, 0xD2, 0x14, 0x47, 0x64, 0x3D,
0x9B, 0xFA, 0x43, 0x49, 0x0F, 0x81, 0x3D, 0x9D,
0x5E, 0x0E, 0xB9, 0x0D, 0xAF, 0xA6, 0x80, 0x2C,
0xF9, 0x33, 0x3B, 0x9D
};
byte derived[28];
ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd, (int)sizeof(passwd),
salt, (int)sizeof(salt), 1, 28, WC_SHA224, 1, NULL), 0);
ExpectIntEQ(XMEMCMP(derived, verify, 28), 0);
ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd2, (int)sizeof(passwd2),
salt2, (int)sizeof(salt2), 1000, 28, WC_SHA224, 1, NULL), 0);
ExpectIntEQ(XMEMCMP(derived, verify2, 28), 0);
#endif
return EXPECT_RESULT();
}
int test_wc_PKCS12_PBKDF_ex_sha384(void)
{
EXPECT_DECLS;
#if defined(HAVE_PKCS12) && !defined(NO_PWDBASED) && defined(WOLFSSL_SHA384)
static const byte passwd[] = {
0x00, 0x73, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x67,
0x00, 0x00
};
static const byte salt[] = {
0x0a, 0x58, 0xCF, 0x64, 0x53, 0x0d, 0x82, 0x3f
};
static const byte passwd2[] = {
0x00, 0x71, 0x00, 0x75, 0x00, 0x65, 0x00, 0x65,
0x00, 0x67, 0x00, 0x00
};
static const byte salt2[] = {
0x16, 0x82, 0xC0, 0xfC, 0x5b, 0x3f, 0x7e, 0xc5
};
static const byte verify[] = {
0x17, 0xD5, 0x0F, 0x1F, 0x21, 0x8A, 0x3B, 0xC9,
0x6E, 0x10, 0x41, 0xBA, 0xEC, 0xF0, 0xA1, 0xF2,
0x11, 0x99, 0x56, 0x55, 0x2B, 0xD0, 0x38, 0x80,
0x9A, 0x40, 0x2F, 0x13, 0x0A, 0x24, 0x67, 0xFA,
0x49, 0xED, 0xFA, 0x6A, 0x83, 0xB5, 0x40, 0x69,
0xFB, 0x73, 0xB7, 0x48, 0x44, 0x33, 0x1A, 0xC3
};
static const byte verify2[] = {
0x7F, 0x50, 0xFB, 0x97, 0xF1, 0x7C, 0x01, 0x15,
0xA2, 0x0A, 0xCB, 0x88, 0x68, 0xFC, 0x37, 0xA7,
0x88, 0x8C, 0xD7, 0x1A, 0xF3, 0x1D, 0xB2, 0xDD,
0x93, 0xCF, 0x44, 0xED, 0xC9, 0xA4, 0x61, 0x04,
0xBE, 0x4E, 0x16, 0x86, 0x36, 0xF1, 0x6E, 0x65,
0x41, 0xE0, 0xD7, 0xC3, 0xE2, 0x4D, 0x95, 0x99
};
byte derived[48];
ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd, (int)sizeof(passwd),
salt, (int)sizeof(salt), 1, 48, WC_SHA384, 1, NULL), 0);
ExpectIntEQ(XMEMCMP(derived, verify, 48), 0);
ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd2, (int)sizeof(passwd2),
salt2, (int)sizeof(salt2), 1000, 48, WC_SHA384, 1, NULL), 0);
ExpectIntEQ(XMEMCMP(derived, verify2, 48), 0);
#endif
return EXPECT_RESULT();
}
int test_wc_PKCS12_PBKDF_ex_sha512_224(void)
{
EXPECT_DECLS;
#if defined(HAVE_PKCS12) && !defined(NO_PWDBASED) && \
defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
static const byte passwd[] = {
0x00, 0x73, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x67,
0x00, 0x00
};
static const byte salt[] = {
0x0a, 0x58, 0xCF, 0x64, 0x53, 0x0d, 0x82, 0x3f
};
static const byte passwd2[] = {
0x00, 0x71, 0x00, 0x75, 0x00, 0x65, 0x00, 0x65,
0x00, 0x67, 0x00, 0x00
};
static const byte salt2[] = {
0x16, 0x82, 0xC0, 0xfC, 0x5b, 0x3f, 0x7e, 0xc5
};
static const byte verify[] = {
0xE1, 0xAD, 0xB3, 0x9E, 0x3E, 0x72, 0x85, 0x11,
0x28, 0xFC, 0xF8, 0x5F, 0x4A, 0xBE, 0x74, 0x99,
0x7B, 0x02, 0xF0, 0x8B, 0x47, 0x1B, 0x71, 0x40,
0xB9, 0x7C, 0x03, 0x83
};
static const byte verify2[] = {
0xF0, 0x3F, 0x58, 0x16, 0x8B, 0x0C, 0xF5, 0x09,
0xC5, 0x7F, 0x20, 0xD2, 0x24, 0xEC, 0x27, 0xAE,
0xC2, 0xA6, 0xBB, 0x21, 0xE5, 0x76, 0x5A, 0xF8,
0x3C, 0xA6, 0x2A, 0xA6
};
byte derived[28];
ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd, (int)sizeof(passwd),
salt, (int)sizeof(salt), 1, 28, WC_SHA512_224, 1, NULL), 0);
ExpectIntEQ(XMEMCMP(derived, verify, 28), 0);
ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd2, (int)sizeof(passwd2),
salt2, (int)sizeof(salt2), 1000, 28, WC_SHA512_224, 1, NULL), 0);
ExpectIntEQ(XMEMCMP(derived, verify2, 28), 0);
#endif
return EXPECT_RESULT();
}
int test_wc_PKCS12_PBKDF_ex_sha512_256(void)
{
EXPECT_DECLS;
#if defined(HAVE_PKCS12) && !defined(NO_PWDBASED) && \
defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
static const byte passwd[] = {
0x00, 0x73, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x67,
0x00, 0x00
};
static const byte salt[] = {
0x0a, 0x58, 0xCF, 0x64, 0x53, 0x0d, 0x82, 0x3f
};
static const byte passwd2[] = {
0x00, 0x71, 0x00, 0x75, 0x00, 0x65, 0x00, 0x65,
0x00, 0x67, 0x00, 0x00
};
static const byte salt2[] = {
0x16, 0x82, 0xC0, 0xfC, 0x5b, 0x3f, 0x7e, 0xc5
};
static const byte verify[] = {
0x08, 0x41, 0xAA, 0x5C, 0xBC, 0xEE, 0xA4, 0x3F,
0x34, 0xA4, 0xDA, 0xB1, 0xEB, 0x83, 0x7E, 0xF1,
0x84, 0xBC, 0x30, 0x75, 0x40, 0x94, 0x95, 0x1F,
0xAE, 0x25, 0xAA, 0xD1, 0xFD, 0x80, 0x2B, 0x5B
};
static const byte verify2[] = {
0xC9, 0x44, 0xE9, 0x01, 0x53, 0x03, 0x64, 0xB9,
0x61, 0x6E, 0x7F, 0xAE, 0xAA, 0x8E, 0x2D, 0xBB,
0xE1, 0xAC, 0x45, 0x34, 0x58, 0x08, 0xB9, 0xE6,
0xFA, 0x61, 0xF6, 0x1D, 0x15, 0x84, 0x15, 0x75
};
byte derived[32];
ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd, (int)sizeof(passwd),
salt, (int)sizeof(salt), 1, 32, WC_SHA512_256, 1, NULL), 0);
ExpectIntEQ(XMEMCMP(derived, verify, 32), 0);
ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd2, (int)sizeof(passwd2),
salt2, (int)sizeof(salt2), 1000, 32, WC_SHA512_256, 1, NULL), 0);
ExpectIntEQ(XMEMCMP(derived, verify2, 32), 0);
#endif
return EXPECT_RESULT();
}