Add SHA3-HMAC support to PKCS#8

This also enables testing of PKCS#8 keys using modern hash algos with
LTC_EASY.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
Steffen Jaeckel 2025-10-28 15:49:57 +01:00
parent 934bd7e0fe
commit e2d0935792
18 changed files with 13 additions and 2 deletions

View file

@ -91,6 +91,8 @@
#define LTC_SHA1
#define LTC_SHA3
#define LTC_SHA512
#define LTC_SHA512_256
#define LTC_SHA512_224
#define LTC_SHA384
#define LTC_SHA256
#define LTC_SHA224

View file

@ -20,6 +20,10 @@ static const oid_id_st s_hmac_oid_names[] = {
{ "1.2.840.113549.2.11", "sha512" },
{ "1.2.840.113549.2.12", "sha512-224" },
{ "1.2.840.113549.2.13", "sha512-256" },
{ "2.16.840.1.101.3.4.2.13", "sha3-224" },
{ "2.16.840.1.101.3.4.2.14", "sha3-256" },
{ "2.16.840.1.101.3.4.2.15", "sha3-384" },
{ "2.16.840.1.101.3.4.2.16", "sha3-512" },
};
static int s_pkcs_5_alg2_wrap(const struct password *pwd,

View file

@ -27,3 +27,7 @@ openssl pkcs8 -topk8 -inform PEM -outform DER -passout pass:secret -in ../test.k
openssl pkcs8 -topk8 -inform PEM -outform DER -passout pass:secret -in ../test.key -v2 rc2-40 -v2prf hmacWithSHA512-256 -out key_pkcs8_pbkdf2_sha512_256_rc2_40_cbc.der
openssl pkcs8 -topk8 -inform PEM -outform DER -passout pass:secret -in ../test.key -v2 rc2-64 -v2prf hmacWithSHA512 -out key_pkcs8_pbkdf2_sha512_rc2_64_cbc.der
openssl pkcs8 -topk8 -inform PEM -outform DER -passout pass:secret -in ../test.key -v2 rc2-64 -v2prf hmacWithSHA512-256 -out key_pkcs8_pbkdf2_sha512_256_rc2_64_cbc.der
openssl pkcs8 -topk8 -inform PEM -outform DER -passout pass:secret -in ../test.key -v2 aes256 -v2prf id-hmacWithSHA3-224 -out key_pkcs8_pbkdf2_sha3_224_aes256_cbc.der
openssl pkcs8 -topk8 -inform PEM -outform DER -passout pass:secret -in ../test.key -v2 aes256 -v2prf id-hmacWithSHA3-256 -out key_pkcs8_pbkdf2_sha3_256_aes256_cbc.der
openssl pkcs8 -topk8 -inform PEM -outform DER -passout pass:secret -in ../test.key -v2 aes256 -v2prf id-hmacWithSHA3-384 -out key_pkcs8_pbkdf2_sha3_384_aes256_cbc.der
openssl pkcs8 -topk8 -inform PEM -outform DER -passout pass:secret -in ../test.key -v2 aes256 -v2prf id-hmacWithSHA3-512 -out key_pkcs8_pbkdf2_sha3_512_aes256_cbc.der

View file

@ -431,7 +431,7 @@ static int s_rsa_import_x509(const void *in, unsigned long inlen, void *key)
return rsa_import_x509(in, inlen, key);
}
#if defined(LTC_MD2) && defined(LTC_MD5) && defined(LTC_RC2)
#if defined(LTC_TEST_READDIR)
static int password_get(void **p, unsigned long *l, void *u)
{
LTC_UNUSED_PARAM(u);
@ -476,8 +476,9 @@ int rsa_test(void)
#ifdef LTC_TEST_READDIR
DO(test_process_dir("tests/rsa", &key, s_rsa_import_x509, NULL, (dir_cleanup_cb)rsa_free, "rsa_test"));
#if defined(LTC_MD2) && defined(LTC_MD5) && defined(LTC_RC2)
DO(test_process_dir("tests/rsa-pkcs8", &key, s_rsa_import_pkcs8, NULL, (dir_cleanup_cb)rsa_free, "rsa_pkcs8_test"));
DO(test_process_dir("tests/rsa-pkcs8/old", &key, s_rsa_import_pkcs8, NULL, (dir_cleanup_cb)rsa_free, "rsa_pkcs8_test"));
#endif
DO(test_process_dir("tests/rsa-pkcs8", &key, s_rsa_import_pkcs8, NULL, (dir_cleanup_cb)rsa_free, "rsa_pkcs8_test"));
#endif
DO(s_rsa_cryptx_issue_69());