Skip to content

Commit 9ff0150

Browse files
committed
Fix build issues and findings
1 parent 99ebafd commit 9ff0150

3 files changed

Lines changed: 19 additions & 49 deletions

File tree

src/crypto.c

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6760,37 +6760,21 @@ CK_RV C_GenerateKey(CK_SESSION_HANDLE hSession,
67606760
ret = WP11_Object_SetSecretKey(pbkdf2Key, secretKeyData, secretKeyLen);
67616761
if (ret == 0) {
67626762
WP11_Object_SetKeyGeneration(pbkdf2Key, pMechanism->mechanism);
6763-
rv = AddObject(session, pbkdf2Key, pTemplate, ulCount, phKey);
6764-
if (rv != CKR_OK) {
6765-
WP11_Object_Free(pbkdf2Key);
6766-
}
6763+
rv = SetInitialStates(pbkdf2Key);
67676764
} else {
6768-
WP11_Object_Free(pbkdf2Key);
67696765
rv = CKR_FUNCTION_FAILED;
67706766
}
6767+
if (rv == CKR_OK) {
6768+
rv = AddObject(session, pbkdf2Key, pTemplate, ulCount, phKey);
6769+
}
6770+
if (rv != CKR_OK) {
6771+
WP11_Object_Free(pbkdf2Key);
6772+
}
67716773
}
67726774

67736775
wc_ForceZero(derivedKey, derivedKeyLen);
67746776
XFREE(derivedKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
67756777

6776-
if (rv == CKR_OK) {
6777-
rv = WP11_Object_GetAttr(pbkdf2Key, CKA_SENSITIVE, &getVar,
6778-
&getVarLen);
6779-
if ((rv == CKR_OK) && (getVar == CK_TRUE)) {
6780-
rv = WP11_Object_SetAttr(pbkdf2Key, CKA_ALWAYS_SENSITIVE,
6781-
&trueVar, sizeof(CK_BBOOL));
6782-
}
6783-
if (rv == CKR_OK) {
6784-
rv = WP11_Object_GetAttr(pbkdf2Key, CKA_EXTRACTABLE,
6785-
&getVar, &getVarLen);
6786-
if ((rv == CKR_OK) && (getVar == CK_FALSE)) {
6787-
rv = WP11_Object_SetAttr(pbkdf2Key,
6788-
CKA_NEVER_EXTRACTABLE,
6789-
&trueVar, sizeof(CK_BBOOL));
6790-
}
6791-
}
6792-
}
6793-
67946778
return rv;
67956779
}
67966780
#ifdef WOLFPKCS11_NSS
@@ -6877,37 +6861,21 @@ CK_RV C_GenerateKey(CK_SESSION_HANDLE hSession,
68776861
ret = WP11_Object_SetSecretKey(pbeKey, secretKeyData, secretKeyLen);
68786862
if (ret == 0) {
68796863
WP11_Object_SetKeyGeneration(pbeKey, pMechanism->mechanism);
6880-
rv = AddObject(session, pbeKey, pTemplate, ulCount, phKey);
6881-
if (rv != CKR_OK) {
6882-
WP11_Object_Free(pbeKey);
6883-
}
6864+
rv = SetInitialStates(pbeKey);
68846865
} else {
6885-
WP11_Object_Free(pbeKey);
68866866
rv = CKR_FUNCTION_FAILED;
68876867
}
6868+
if (rv == CKR_OK) {
6869+
rv = AddObject(session, pbeKey, pTemplate, ulCount, phKey);
6870+
}
6871+
if (rv != CKR_OK) {
6872+
WP11_Object_Free(pbeKey);
6873+
}
68886874
}
68896875

68906876
wc_ForceZero(derivedKey, derivedKeyLen);
68916877
XFREE(derivedKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
68926878

6893-
if (rv == CKR_OK) {
6894-
rv = WP11_Object_GetAttr(pbeKey, CKA_SENSITIVE, &getVar,
6895-
&getVarLen);
6896-
if ((rv == CKR_OK) && (getVar == CK_TRUE)) {
6897-
rv = WP11_Object_SetAttr(pbeKey, CKA_ALWAYS_SENSITIVE,
6898-
&trueVar, sizeof(CK_BBOOL));
6899-
}
6900-
if (rv == CKR_OK) {
6901-
rv = WP11_Object_GetAttr(pbeKey, CKA_EXTRACTABLE,
6902-
&getVar, &getVarLen);
6903-
if ((rv == CKR_OK) && (getVar == CK_FALSE)) {
6904-
rv = WP11_Object_SetAttr(pbeKey,
6905-
CKA_NEVER_EXTRACTABLE,
6906-
&trueVar, sizeof(CK_BBOOL));
6907-
}
6908-
}
6909-
}
6910-
69116879
return rv;
69126880
}
69136881
#endif

tests/pbkdf2_keygen_attrs_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
#include "testdata.h"
4747

48-
#ifndef NO_PWDBASED
48+
#if !defined(NO_PWDBASED) && !defined(NO_HMAC)
4949

5050
#define TEST_DIR "./store/pbkdf2_keygen_attrs_test"
5151
#define WOLFPKCS11_TOKEN_FILENAME "wp11_token_0000000000000001"
@@ -428,14 +428,14 @@ int main(int argc, char* argv[])
428428
return (test_failed == 0) ? 0 : 1;
429429
}
430430

431-
#else /* NO_PWDBASED */
431+
#else /* NO_PWDBASED || NO_HMAC */
432432

433433
int main(int argc, char* argv[])
434434
{
435435
(void)argc;
436436
(void)argv;
437437

438-
printf("PWDBASED not available, skipping PBKDF2 keygen attributes test\n");
438+
printf("PWDBASED/HMAC not available, skipping PBKDF2 keygen attributes test\n");
439439
return 0;
440440
}
441441

tests/pkcs11test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,12 @@ static CK_RV test_token(void* args)
697697
ret = funcList->C_InitToken(slot, soPin, soPinLen, NULL);
698698
CHECK_CKR_FAIL(ret, CKR_ARGUMENTS_BAD, "Init Token no label");
699699
}
700+
#if WP11_MIN_PIN_LEN > 3
700701
if (ret == CKR_OK) {
701702
ret = funcList->C_InitToken(slot, soPin, 3, label);
702703
CHECK_CKR_FAIL(ret, CKR_PIN_LEN_RANGE, "Init Token too short PIN");
703704
}
705+
#endif
704706
if (ret == CKR_OK) {
705707
ret = funcList->C_InitToken(slot, soPin, 33, label);
706708
CHECK_CKR_FAIL(ret, CKR_PIN_LEN_RANGE, "Init Token too long PIN");

0 commit comments

Comments
 (0)