mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-07-08 09:40:50 +02:00
SP int: fixes from AI review
Re-implemented wc_PKCS12_PBKDF() to not use MP. Added tests to unit.test. sp_int.c: Fixes to comments. Added more define build options documentation to top of file. Fixes for builds with WOLFSSL_SP_INT_NEGATIVE defined. Fixes for when a->used is 0 and no underflow - not actually a problem but cleaner code. sp_sub has different checks on a->used when values are only positive. sp_dic_2d missing check for e less than zero. sp_to_unsigned_bin_len_ct: remove redundant check of outSz. Change i to int to handle a->used of 0 and make code tidier. Configuration testing fixes. Fix formatting in test.c. Added 128-bit types word128 and sword128 for cleaner PKCS#12 code.
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#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>
|
||||
@@ -271,3 +272,407 @@ int test_wc_d2i_PKCS12_oid_underflow(void)
|
||||
return EXPECT_RESULT();
|
||||
}
|
||||
|
||||
int test_wc_PKCS12_PBKDF(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_PKCS12) && !defined(NO_PWDBASED) && !defined(NO_SHA256)
|
||||
/* Test vectors from RFC 7292 Appendix B (SHA-256 based) */
|
||||
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];
|
||||
|
||||
/* bad args */
|
||||
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);
|
||||
|
||||
/* 1 iteration */
|
||||
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);
|
||||
|
||||
/* 1000 iterations */
|
||||
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);
|
||||
|
||||
/* iterations <= 0 treated as 1 */
|
||||
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];
|
||||
|
||||
/* bad args */
|
||||
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);
|
||||
|
||||
/* 1 iteration, NULL heap */
|
||||
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);
|
||||
|
||||
/* 1000 iterations, NULL heap */
|
||||
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);
|
||||
|
||||
/* _ex and non-_ex produce identical output */
|
||||
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);
|
||||
|
||||
/* id 2 (IV) and id 3 (MAC) also accepted */
|
||||
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)
|
||||
/* Test vectors generated with OpenSSL PKCS12_key_gen_uni / SHA-1 */
|
||||
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];
|
||||
|
||||
/* 1 iteration, NULL heap */
|
||||
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);
|
||||
|
||||
/* 1000 iterations, NULL heap */
|
||||
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)
|
||||
/* Test vectors generated with OpenSSL PKCS12_key_gen_uni / SHA-512 */
|
||||
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];
|
||||
|
||||
/* 1 iteration, NULL heap */
|
||||
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);
|
||||
|
||||
/* 1000 iterations, NULL heap */
|
||||
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)
|
||||
/* Test vectors generated with OpenSSL PKCS12_key_gen_uni / SHA-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[] = {
|
||||
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];
|
||||
|
||||
/* 1 iteration, NULL heap */
|
||||
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);
|
||||
|
||||
/* 1000 iterations, NULL heap */
|
||||
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)
|
||||
/* Test vectors generated with OpenSSL PKCS12_key_gen_uni / SHA-384 */
|
||||
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];
|
||||
|
||||
/* 1 iteration, NULL heap */
|
||||
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);
|
||||
|
||||
/* 1000 iterations, NULL heap */
|
||||
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)
|
||||
/* Test vectors generated with OpenSSL PKCS12_key_gen_uni / SHA-512/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];
|
||||
|
||||
/* 1 iteration, NULL heap */
|
||||
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);
|
||||
|
||||
/* 1000 iterations, NULL heap */
|
||||
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)
|
||||
/* Test vectors generated with OpenSSL PKCS12_key_gen_uni / SHA-512/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];
|
||||
|
||||
/* 1 iteration, NULL heap */
|
||||
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);
|
||||
|
||||
/* 1000 iterations, NULL heap */
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
+21
-5
@@ -28,11 +28,27 @@ int test_wc_i2d_PKCS12(void);
|
||||
int test_wc_PKCS12_create(void);
|
||||
int test_wc_d2i_PKCS12_bad_mac_salt(void);
|
||||
int test_wc_d2i_PKCS12_oid_underflow(void);
|
||||
int test_wc_PKCS12_PBKDF(void);
|
||||
int test_wc_PKCS12_PBKDF_ex(void);
|
||||
int test_wc_PKCS12_PBKDF_ex_sha1(void);
|
||||
int test_wc_PKCS12_PBKDF_ex_sha512(void);
|
||||
int test_wc_PKCS12_PBKDF_ex_sha224(void);
|
||||
int test_wc_PKCS12_PBKDF_ex_sha384(void);
|
||||
int test_wc_PKCS12_PBKDF_ex_sha512_224(void);
|
||||
int test_wc_PKCS12_PBKDF_ex_sha512_256(void);
|
||||
|
||||
#define TEST_PKCS12_DECLS \
|
||||
TEST_DECL_GROUP("pkcs12", test_wc_i2d_PKCS12), \
|
||||
TEST_DECL_GROUP("pkcs12", test_wc_PKCS12_create), \
|
||||
TEST_DECL_GROUP("pkcs12", test_wc_d2i_PKCS12_bad_mac_salt), \
|
||||
TEST_DECL_GROUP("pkcs12", test_wc_d2i_PKCS12_oid_underflow)
|
||||
#define TEST_PKCS12_DECLS \
|
||||
TEST_DECL_GROUP("pkcs12", test_wc_i2d_PKCS12), \
|
||||
TEST_DECL_GROUP("pkcs12", test_wc_PKCS12_create), \
|
||||
TEST_DECL_GROUP("pkcs12", test_wc_d2i_PKCS12_bad_mac_salt), \
|
||||
TEST_DECL_GROUP("pkcs12", test_wc_d2i_PKCS12_oid_underflow), \
|
||||
TEST_DECL_GROUP("pkcs12", test_wc_PKCS12_PBKDF), \
|
||||
TEST_DECL_GROUP("pkcs12", test_wc_PKCS12_PBKDF_ex), \
|
||||
TEST_DECL_GROUP("pkcs12", test_wc_PKCS12_PBKDF_ex_sha1), \
|
||||
TEST_DECL_GROUP("pkcs12", test_wc_PKCS12_PBKDF_ex_sha512), \
|
||||
TEST_DECL_GROUP("pkcs12", test_wc_PKCS12_PBKDF_ex_sha224), \
|
||||
TEST_DECL_GROUP("pkcs12", test_wc_PKCS12_PBKDF_ex_sha384), \
|
||||
TEST_DECL_GROUP("pkcs12", test_wc_PKCS12_PBKDF_ex_sha512_224), \
|
||||
TEST_DECL_GROUP("pkcs12", test_wc_PKCS12_PBKDF_ex_sha512_256)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_PKCS12_H */
|
||||
|
||||
Reference in New Issue
Block a user