Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/build-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ on:
required: false
type: string
default: 'make check'
wolfssl_config:
required: false
type: string
default: ''
wolfssl_cflags:
required: false
type: string
default: ''

jobs:
build:
Expand All @@ -36,7 +44,8 @@ jobs:
working-directory: ./wolfssl
run: |
./configure --enable-cryptocb --enable-aescfb --enable-rsapss --enable-keygen --enable-pwdbased --enable-scrypt --enable-md5 \
--enable-mldsa --enable-lms=verify-only --enable-xmss=verify-only C_EXTRA_FLAGS="-DWOLFSSL_PUBLIC_MP -DWC_RSA_DIRECT -DHAVE_AES_ECB -DHAVE_AES_KEYWRAP"
--enable-mldsa --enable-lms=verify-only --enable-xmss=verify-only ${{inputs.wolfssl_config}} \
C_EXTRA_FLAGS="-DWOLFSSL_PUBLIC_MP -DWC_RSA_DIRECT -DHAVE_AES_ECB -DHAVE_AES_KEYWRAP ${{inputs.wolfssl_cflags}}"
- name: wolfssl make
working-directory: ./wolfssl
run: make
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ jobs:
uses: ./.github/workflows/build-workflow.yml
with:
config: --disable-hmac --disable-hkdf
no_concatenate:
uses: ./.github/workflows/build-workflow.yml
with:
config: --disable-concatenate
no_derive_secret_key:
uses: ./.github/workflows/build-workflow.yml
with:
config: --disable-ecc --disable-dh --disable-hkdf --disable-aescbc --disable-concatenate
wolfssl_config: --enable-cryptonly --disable-crypttests --disable-examples
wolfssl_cflags: -DNO_KDF
with_nss:
uses: ./.github/workflows/build-workflow.yml
with:
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,16 @@ if(WOLFPKCS11_HKDF)
endif()


# Concatenation key derivation
add_option("WOLFPKCS11_CONCATENATE"
"Enable wolfPKCS11 CKM_CONCATENATE_* key derivation (default: enabled)"
"yes" "yes;no")

if(WOLFPKCS11_CONCATENATE)
list(APPEND WOLFPKCS11_DEFINITIONS "-DWOLFPKCS11_CONCATENATE")
endif()


# PBKDF2
add_option("WOLFPKCS11_PBKDF2"
"Enable wolfPKCS11 PBKDF2 support (default: disabled)"
Expand Down
1 change: 1 addition & 0 deletions IDE/VisualStudio/user_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ extern "C" {
#define WOLFSSL_KEY_GEN
//#define HAVE_SCRYPT /* For PKCS11 Pin. Scrypt uses massive memory */
//#define WOLFPKCS11_USER_ENV
#define WOLFPKCS11_CONCATENATE

/* PKCS11 TPM */
#define WOLFPKCS11_TPM
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ cmake -DCMAKE_PREFIX_PATH=/path/to/wolfssl/install ..
| `WOLFPKCS11_AESCMAC` | `no` | AES-CMAC support |
| `WOLFPKCS11_HMAC` | `yes` | HMAC support |
| `WOLFPKCS11_HKDF` | `yes` | HKDF support |
| `WOLFPKCS11_CONCATENATE` | `yes` | `CKM_CONCATENATE_*` key derivation |
| `WOLFPKCS11_PBKDF2` | `no` | PBKDF2 for PIN hashing |
| `PBKDF2_ITERATIONS` | `600000` | PBKDF2 iteration count (used when `WOLFPKCS11_PBKDF2=yes`) |
| `WOLFPKCS11_MD5` | `yes` | MD5 support |
Expand Down
2 changes: 2 additions & 0 deletions cmake/options.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ extern "C" {
#cmakedefine NO_HMAC
#undef WOLFPKCS11_HKDF
#cmakedefine WOLFPKCS11_HKDF
#undef WOLFPKCS11_CONCATENATE
#cmakedefine WOLFPKCS11_CONCATENATE
#undef WOLFPKCS11_PBKDF2
#cmakedefine WOLFPKCS11_PBKDF2
#undef PBKDF2_ITERATIONS
Expand Down
11 changes: 11 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,16 @@ then
AM_CFLAGS="$AM_CFLAGS -DWOLFPKCS11_HKDF"
fi

AC_ARG_ENABLE([concatenate],
[AS_HELP_STRING([--enable-concatenate],[Enable CKM_CONCATENATE_* key derivation (default: enabled)])],
[ ENABLED_CONCATENATE=$enableval ],
[ ENABLED_CONCATENATE=yes ]
)
if test "$ENABLED_CONCATENATE" = "yes"
then
AM_CFLAGS="$AM_CFLAGS -DWOLFPKCS11_CONCATENATE"
fi

AC_ARG_ENABLE([pbkdf2],
[AS_HELP_STRING([--enable-pbkdf2],[Enable internal PBKDF2 for PIN hashing (default: disabled)])],
[ ENABLED_PBKDF2=$enableval ],
Expand Down Expand Up @@ -851,6 +861,7 @@ echo " * RSA-PSS: $ENABLED_RSAPSS"
echo " * DH: $ENABLED_DH"
echo " * ECC: $ENABLED_ECC"
echo " * HKDF: $ENABLED_HKDF"
echo " * Concatenate derive: $ENABLED_CONCATENATE"
echo " * ML-DSA: $ENABLED_MLDSA"
echo " * ML-KEM: $ENABLED_MLKEM"
echo " * LMS/HSS verify: $ENABLED_LMS"
Expand Down
19 changes: 19 additions & 0 deletions src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@

#define PRF_KEY_SIZE 48

/* Derive mechanisms that build their output into a secret key object. */
#if defined(HAVE_ECC) || !defined(NO_DH) || defined(WOLFPKCS11_HKDF) || \
(!defined(NO_AES) && defined(HAVE_AES_CBC)) || \
defined(WOLFSSL_HAVE_PRF) || defined(WOLFPKCS11_CONCATENATE)
#define WP11_DERIVE_SECRET_KEY
#endif

/* Check that a CK_ULONG value fits in word32 with room for overhead such as
* authentication tags, key wrap blocks, or padding. On LP64 platforms CK_ULONG
* is 64-bit but wolfCrypt functions use word32/int for lengths. */
Expand Down Expand Up @@ -650,6 +657,7 @@ static CK_RV SetInitialStates(WP11_Object* key)
return rv;
}

#ifdef WP11_DERIVE_SECRET_KEY
/* PKCS#11 derive rules: the historical flags also need the base key's. */
static CK_RV SetDerivedStates(WP11_Object* key, CK_BBOOL baseAlwaysSensitive,
CK_BBOOL baseNeverExtractable)
Expand Down Expand Up @@ -678,6 +686,7 @@ static CK_RV SetDerivedStates(WP11_Object* key, CK_BBOOL baseAlwaysSensitive,
}
return rv;
}
#endif

static CK_RV TemplateHasAttribute(CK_ATTRIBUTE_TYPE type,
CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount)
Expand Down Expand Up @@ -10164,6 +10173,7 @@ CK_RV C_UnwrapKey(CK_SESSION_HANDLE hSession,
return rv;
}

#ifdef WP11_DERIVE_SECRET_KEY
/**
* Determine the key length of the object.
*
Expand Down Expand Up @@ -10213,6 +10223,7 @@ static int SymmKeyLen(WP11_Object* obj, word32 len, CK_ULONG* symmKeyLen)

return ret;
}
#endif

#ifdef WOLFSSL_HAVE_PRF
static int SetKeyExtract(WP11_Session* session, byte* ptr, CK_ULONG length,
Expand Down Expand Up @@ -10365,6 +10376,7 @@ static int Tls12_Extract_Keys(WP11_Session* session,
}
#endif

#ifdef WOLFPKCS11_CONCATENATE
static CK_RV ConcatKeyRv(WP11_Session* session, int ret)
{
if (ret == 0)
Expand Down Expand Up @@ -10394,6 +10406,7 @@ static int ConcatCutsProtectedKey(WP11_Object* key, CK_ULONG off,
extractable = CK_FALSE;
return sensitive == CK_TRUE || extractable == CK_FALSE;
}
#endif

/**
* Generate a symmetric key into a new key object.
Expand Down Expand Up @@ -10437,6 +10450,7 @@ static CK_RV wp11_C_DeriveKey(CK_SESSION_HANDLE hSession,
CK_RV rv = CKR_OK;
WP11_Session* session;
WP11_Object* obj = NULL;
#ifdef WP11_DERIVE_SECRET_KEY
WP11_Object* otherKey = NULL;
byte* derivedKey = NULL;
word32 keyLen;
Expand All @@ -10463,6 +10477,7 @@ static CK_RV wp11_C_DeriveKey(CK_SESSION_HANDLE hSession,
#if !defined(NO_AES) && !defined(WOLFPKCS11_NSS)
CK_ATTRIBUTE* keyTypeAttr = NULL;
#endif
#endif
#ifndef NO_DH
CK_ULONG dhPrimeLen = 0;
#endif
Expand Down Expand Up @@ -10873,6 +10888,7 @@ static CK_RV wp11_C_DeriveKey(CK_SESSION_HANDLE hSession,
}
#endif
#endif
#ifdef WOLFPKCS11_CONCATENATE
case CKM_CONCATENATE_BASE_AND_KEY:
case CKM_CONCATENATE_BASE_AND_DATA:
case CKM_CONCATENATE_DATA_AND_BASE: {
Expand Down Expand Up @@ -10982,11 +10998,13 @@ static CK_RV wp11_C_DeriveKey(CK_SESSION_HANDLE hSession,
rv = ConcatKeyRv(session, ret);
break;
}
#endif
default:
(void)ulAttributeCount;
return CKR_MECHANISM_INVALID;
}

#ifdef WP11_DERIVE_SECRET_KEY
if ((ret == 0) && (derivedKey != NULL)) {
/* F-4533: read the base key's protection bits while `obj' still
* refers to it, before CreateObject reuses `obj' for the new key. */
Expand Down Expand Up @@ -11132,6 +11150,7 @@ static CK_RV wp11_C_DeriveKey(CK_SESSION_HANDLE hSession,
wc_ForceZero(derivedKey, keyLen);
XFREE(derivedKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
#endif

return rv;
}
Expand Down
2 changes: 2 additions & 0 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -19174,6 +19174,7 @@ int WP11_KDF_Derive(WP11_Session* session, CK_HKDF_PARAMS_PTR params,

#endif

#ifdef WOLFPKCS11_CONCATENATE
/* Call with the object lock held when the key is on the token. */
static int wp11_Concat_KeyState(WP11_Object* key)
{
Expand Down Expand Up @@ -19294,6 +19295,7 @@ int WP11_Concat_Derive(WP11_Object* base, WP11_Object* other,
ret = BAD_FUNC_ARG;
return ret;
}
#endif /* WOLFPKCS11_CONCATENATE */

#ifndef NO_DH
/**
Expand Down
6 changes: 6 additions & 0 deletions src/slot.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,11 @@ static CK_MECHANISM_TYPE mechanismList[] = {
CKM_TLS_MAC,
#endif
CKM_GENERIC_SECRET_KEY_GEN,
#ifdef WOLFPKCS11_CONCATENATE
CKM_CONCATENATE_BASE_AND_KEY,
CKM_CONCATENATE_BASE_AND_DATA,
CKM_CONCATENATE_DATA_AND_BASE,
#endif
#ifndef NO_HMAC
CKM_PKCS5_PBKD2
#endif
Expand Down Expand Up @@ -912,9 +914,11 @@ static CK_MECHANISM_INFO sha3MechInfo = {
static CK_MECHANISM_INFO genSecKeyGenMechInfo = {
8, WP11_MAX_SYM_KEY_SZ * 8, CKF_GENERATE
};
#ifdef WOLFPKCS11_CONCATENATE
static CK_MECHANISM_INFO concatMechInfo = {
8, WP11_MAX_SYM_KEY_SZ * 8, CKF_DERIVE
};
#endif

#ifndef NO_HMAC
static CK_MECHANISM_INFO pkcs5Pbkdf2MechInfo = {
Expand Down Expand Up @@ -1299,11 +1303,13 @@ CK_RV C_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type,
XMEMCPY(pInfo, &genSecKeyGenMechInfo,
sizeof(CK_MECHANISM_INFO));
break;
#ifdef WOLFPKCS11_CONCATENATE
case CKM_CONCATENATE_BASE_AND_KEY:
case CKM_CONCATENATE_BASE_AND_DATA:
case CKM_CONCATENATE_DATA_AND_BASE:
XMEMCPY(pInfo, &concatMechInfo, sizeof(CK_MECHANISM_INFO));
break;
#endif
#ifndef NO_HMAC
case CKM_PKCS5_PBKD2:
XMEMCPY(pInfo, &pkcs5Pbkdf2MechInfo,
Expand Down
6 changes: 6 additions & 0 deletions tests/decrypt_final_bufsize_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

#define TEST_DIR "./store/decrypt_final_bufsize_test"

#if !defined(NO_AES) && !defined(NO_AES_CBC)
static int run_test(void)
{
CK_RV rv;
Expand Down Expand Up @@ -182,6 +183,7 @@ static int run_test(void)
pkcs11_unload();
return 0;
}
#endif

int main(int argc, char* argv[])
{
Expand All @@ -193,6 +195,10 @@ int main(int argc, char* argv[])
#endif

printf("=== wolfPKCS11 C_DecryptFinal CBC-PAD buffer-size test ===\n");
#if !defined(NO_AES) && !defined(NO_AES_CBC)
run_test();
#else
printf("AES-CBC not available, skipping\n");
#endif
return pkcs11_test_summary();
}
4 changes: 2 additions & 2 deletions tests/object_store_decode_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ static CK_RV create_aes_key(CK_SESSION_HANDLE session)
}
#endif

#ifndef NO_AES
#if !defined(NO_AES) && !defined(NO_AES_CBC)
/* Count the AES keys visible after a login and check one still encrypts. */
static CK_RV use_stored_aes_key(CK_SESSION_HANDLE session)
{
Expand Down Expand Up @@ -1259,7 +1259,7 @@ int main(int argc, char* argv[])
#ifdef HAVE_ALLOC_TRACKING
test_failed_decrypt_scrubbed();
test_failed_key_decrypt_scrubbed();
#ifndef NO_AES
#if !defined(NO_AES) && !defined(NO_AES_CBC)
test_login_after_failed_encode();
#endif
#endif
Expand Down
2 changes: 0 additions & 2 deletions tests/pkcs11mtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ static CK_OBJECT_CLASS pubKeyClass = CKO_PUBLIC_KEY;
static CK_OBJECT_CLASS privKeyClass = CKO_PRIVATE_KEY;
static CK_OBJECT_CLASS secretKeyClass = CKO_SECRET_KEY;

#if defined(HAVE_ECC) || !defined(NO_DH)
static CK_BBOOL ckFalse = CK_FALSE;
#endif
static CK_BBOOL ckTrue = CK_TRUE;

#ifndef NO_RSA
Expand Down
Loading
Loading