Skip to content

Commit b413280

Browse files
authored
Merge pull request #113 from dgarske/alg_enables
Fixes to support build disables like SHA1, SHA3 and PRF
2 parents 7c09e2b + f147b45 commit b413280

File tree

9 files changed

+112
-41
lines changed

9 files changed

+112
-41
lines changed

examples/add_cert_file.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include <dlfcn.h>
4040
#endif
4141

42-
#ifndef WOLFPKCS11_NO_STORE
42+
#if !defined(WOLFPKCS11_NO_STORE) && !defined(NO_FILESYSTEM)
4343

4444
#ifdef DEBUG_WOLFPKCS11
4545
#define CHECK_CKR(rv, op) \
@@ -397,5 +397,4 @@ int add_cert(int argc, char* argv[])
397397
return 0;
398398
}
399399

400-
#endif
401-
400+
#endif /* !WOLFPKCS11_NO_STORE && !NO_FILESYSTEM */

examples/add_rsa_key_file.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include <dlfcn.h>
4141
#endif
4242

43-
#if !defined(WOLFPKCS11_NO_STORE) && !defined(NO_RSA)
43+
#if !defined(WOLFPKCS11_NO_STORE) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
4444

4545
#ifdef DEBUG_WOLFPKCS11
4646
#define CHECK_CKR(rv, op) \
@@ -422,5 +422,4 @@ int add_rsa_key_file(int argc, char* argv[])
422422
return 0;
423423
}
424424

425-
#endif
426-
425+
#endif /* !WOLFPKCS11_NO_STORE && !NO_RSA && !NO_FILESYSTEM */

src/crypto.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,8 +1088,8 @@ CK_RV C_CopyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
10881088
WOLFPKCS11_ENTER("C_CopyObject");
10891089
#ifdef DEBUG_WOLFPKCS11
10901090
if (wolfpkcs11_debugging) {
1091-
WOLFPKCS11_MSG(" hSession=%lu, hObject=%lu, ulCount=%lu",
1092-
(unsigned long)hSession, (unsigned long)hObject,
1091+
WOLFPKCS11_MSG(" hSession=%lu, hObject=%lu, ulCount=%lu",
1092+
(unsigned long)hSession, (unsigned long)hObject,
10931093
(unsigned long)ulCount);
10941094
}
10951095
#endif
@@ -1312,8 +1312,8 @@ CK_RV C_GetAttributeValue(CK_SESSION_HANDLE hSession,
13121312
WOLFPKCS11_ENTER("C_GetAttributeValue");
13131313
#ifdef DEBUG_WOLFPKCS11
13141314
if (wolfpkcs11_debugging) {
1315-
WOLFPKCS11_MSG(" hSession=%lu, hObject=%lu, ulCount=%lu",
1316-
(unsigned long)hSession, (unsigned long)hObject,
1315+
WOLFPKCS11_MSG(" hSession=%lu, hObject=%lu, ulCount=%lu",
1316+
(unsigned long)hSession, (unsigned long)hObject,
13171317
(unsigned long)ulCount);
13181318
}
13191319
#endif
@@ -1414,8 +1414,8 @@ CK_RV C_SetAttributeValue(CK_SESSION_HANDLE hSession,
14141414
WOLFPKCS11_ENTER("C_SetAttributeValue");
14151415
#ifdef DEBUG_WOLFPKCS11
14161416
if (wolfpkcs11_debugging) {
1417-
WOLFPKCS11_MSG(" hSession=%lu, hObject=%lu, ulCount=%lu",
1418-
(unsigned long)hSession, (unsigned long)hObject,
1417+
WOLFPKCS11_MSG(" hSession=%lu, hObject=%lu, ulCount=%lu",
1418+
(unsigned long)hSession, (unsigned long)hObject,
14191419
(unsigned long)ulCount);
14201420
}
14211421
#endif
@@ -6534,6 +6534,7 @@ CK_RV C_WrapKey(CK_SESSION_HANDLE hSession,
65346534
break;
65356535
}
65366536
(void)pWrappedKey;
6537+
(void)wrapkeyType;
65376538

65386539
err_out:
65396540

@@ -6724,6 +6725,7 @@ CK_RV C_UnwrapKey(CK_SESSION_HANDLE hSession,
67246725
rv = CKR_KEY_NOT_WRAPPABLE;
67256726
goto err_out;
67266727
}
6728+
(void)wrapkeyType;
67276729

67286730
err_out:
67296731

@@ -6772,6 +6774,7 @@ static int SymmKeyLen(WP11_Object* obj, word32 len, word32* symmKeyLen)
67726774
}
67736775
#endif
67746776

6777+
#ifdef WOLFSSL_HAVE_PRF
67756778
static int SetKeyExtract(WP11_Session* session, byte* ptr, CK_ULONG length,
67766779
CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulAttributeCount,
67776780
CK_BBOOL isMac, CK_OBJECT_HANDLE* handle)
@@ -6909,6 +6912,7 @@ static int Tls12_Extract_Keys(WP11_Session* session,
69096912
}
69106913
return ret;
69116914
}
6915+
#endif
69126916

69136917
/**
69146918
* Generate a symmetric key into a new key object.

src/internal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9570,6 +9570,7 @@ int WP11_AesCbc_DeriveKey(unsigned char* plain, word32 plainSz,
95709570
return ret;
95719571
}
95729572

9573+
#ifdef WOLFSSL_HAVE_PRF
95739574
/* Used for wc_PRF_TLS, less than sha256_mac not possible */
95749575
static enum wc_MACAlgorithm MechToMac(CK_MECHANISM_TYPE mech)
95759576
{
@@ -9589,7 +9590,6 @@ static enum wc_MACAlgorithm MechToMac(CK_MECHANISM_TYPE mech)
95899590
}
95909591
}
95919592

9592-
#ifdef WOLFSSL_HAVE_PRF
95939593
int WP11_Tls12_Master_Key_Derive(CK_SSL3_RANDOM_DATA* random,
95949594
CK_MECHANISM_TYPE mech, const char* label,
95959595
CK_ULONG ulLabelLen, byte* enc,
@@ -9667,7 +9667,7 @@ int WP11_Nss_Tls12_Master_Key_Derive(CK_BYTE_PTR pSessionHash,
96679667
return ret;
96689668
}
96699669
#endif
9670-
#endif
9670+
#endif /* WOLFSSL_HAVE_PRF */
96719671

96729672
/**
96739673
* Encrypt plain text with AES-CBC.

src/slot.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,11 @@ static CK_MECHANISM_INFO ssl3MasterKeyDeriveInfo = {
643643
48, 48, CKF_DERIVE
644644
};
645645
#endif
646+
#ifdef WOLFSSL_HAVE_PRF
646647
static CK_MECHANISM_INFO tlsMacMechInfo = {
647648
0, 512, CKF_SIGN | CKF_VERIFY
648649
};
650+
#endif
649651
#ifndef NO_AES
650652
static CK_MECHANISM_INFO aesKeyGenMechInfo = {
651653
16, 32, CKF_GENERATE
@@ -1295,7 +1297,7 @@ CK_RV C_SetPIN(CK_SESSION_HANDLE hSession, CK_UTF8CHAR_PTR pOldPin,
12951297
WOLFPKCS11_ENTER("C_SetPIN");
12961298
#ifdef DEBUG_WOLFPKCS11
12971299
if (wolfpkcs11_debugging) {
1298-
WOLFPKCS11_MSG(" hSession=%lu, ulOldLen=%lu, ulNewLen=%lu",
1300+
WOLFPKCS11_MSG(" hSession=%lu, ulOldLen=%lu, ulNewLen=%lu",
12991301
(unsigned long)hSession, (unsigned long)ulOldLen, (unsigned long)ulNewLen);
13001302
}
13011303
#endif
@@ -1658,7 +1660,7 @@ CK_RV C_SetOperationState(CK_SESSION_HANDLE hSession,
16581660
WOLFPKCS11_ENTER("C_SetOperationState");
16591661
#ifdef DEBUG_WOLFPKCS11
16601662
if (wolfpkcs11_debugging) {
1661-
WOLFPKCS11_MSG(" hSession=%lu, ulOperationStateLen=%lu",
1663+
WOLFPKCS11_MSG(" hSession=%lu, ulOperationStateLen=%lu",
16621664
(unsigned long)hSession, (unsigned long)ulOperationStateLen);
16631665
}
16641666
#endif
@@ -1719,7 +1721,7 @@ CK_RV C_Login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType,
17191721
WOLFPKCS11_ENTER("C_Login");
17201722
#ifdef DEBUG_WOLFPKCS11
17211723
if (wolfpkcs11_debugging) {
1722-
WOLFPKCS11_MSG(" hSession=%lu, userType=%lu, ulPinLen=%lu",
1724+
WOLFPKCS11_MSG(" hSession=%lu, userType=%lu, ulPinLen=%lu",
17231725
(unsigned long)hSession, (unsigned long)userType, (unsigned long)ulPinLen);
17241726
}
17251727
#endif

tests/debug_test.c

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,25 @@
2323
#include <stdio.h>
2424
#include <string.h>
2525
#include <stdlib.h>
26-
#include "wolfpkcs11/pkcs11.h"
26+
27+
#ifdef HAVE_CONFIG_H
28+
#include <wolfpkcs11/config.h>
29+
#endif
30+
31+
#ifndef WOLFSSL_USER_SETTINGS
32+
#include <wolfssl/options.h>
33+
#endif
34+
#include <wolfssl/wolfcrypt/settings.h>
35+
#include <wolfssl/wolfcrypt/types.h>
36+
37+
#ifndef WOLFPKCS11_USER_SETTINGS
38+
#include <wolfpkcs11/options.h>
39+
#endif
40+
#include <wolfpkcs11/pkcs11.h>
41+
42+
#ifndef HAVE_PKCS11_STATIC
43+
#include <dlfcn.h>
44+
#endif
2745

2846
#ifdef DEBUG_WOLFPKCS11
2947
static FILE* original_stdout = NULL;
@@ -42,23 +60,23 @@ static int check_debug_output(void)
4260
{
4361
char buffer[1024];
4462
int found_debug = 0;
45-
63+
4664
if (!capture_file) {
4765
return 0;
4866
}
49-
67+
5068
stdout = original_stdout;
5169
rewind(capture_file);
52-
70+
5371
while (fgets(buffer, sizeof(buffer), capture_file)) {
54-
if (strstr(buffer, "WOLFPKCS11 ENTER:") ||
72+
if (strstr(buffer, "WOLFPKCS11 ENTER:") ||
5573
strstr(buffer, "WOLFPKCS11 LEAVE:") ||
5674
strstr(buffer, "WOLFPKCS11:")) {
5775
found_debug = 1;
5876
break;
5977
}
6078
}
61-
79+
6280
fclose(capture_file);
6381
return found_debug;
6482
}
@@ -83,48 +101,48 @@ int main(void)
83101

84102
printf("=== wolfPKCS11 Debug Test Program ===\n");
85103
printf("Debug mode is ENABLED (DEBUG_WOLFPKCS11 defined)\n");
86-
104+
87105
printf("\nTesting debug control functions:\n");
88106
wolfPKCS11_Debugging_On();
89107
printf("Debug enabled\n");
90-
108+
91109
wolfPKCS11_Debugging_Off();
92110
printf("Debug disabled\n");
93-
111+
94112
wolfPKCS11_Debugging_On();
95113
printf("Debug re-enabled\n");
96-
114+
97115
printf("\nTesting PKCS#11 functions with debug output capture:\n");
98-
116+
99117
setup_output_capture();
100-
118+
101119
rv = C_GetFunctionList(&pFunctionList);
102-
120+
103121
if (rv == CKR_OK && pFunctionList != NULL) {
104122
rv = pFunctionList->C_Initialize(NULL);
105-
123+
106124
if (rv == CKR_OK) {
107125
CK_INFO info;
108126
rv = pFunctionList->C_GetInfo(&info);
109127
pFunctionList->C_Finalize(NULL);
110128
}
111129
}
112-
130+
113131
debug_found = check_debug_output();
114-
132+
115133
printf("C_GetFunctionList returned: %lu\n", (unsigned long)rv);
116134
printf("Debug output detection: %s\n", debug_found ? "PASS" : "FAIL");
117-
135+
118136
wolfPKCS11_Debugging_Off();
119137
printf("Debug disabled at end\n");
120-
138+
121139
printf("\n=== Test Complete ===\n");
122-
140+
123141
if (!debug_found) {
124142
printf("ERROR: No debug output was detected during PKCS#11 function calls\n");
125143
return 1;
126144
}
127-
145+
128146
printf("SUCCESS: Debug output was properly generated\n");
129147
return 0;
130148
#endif

tests/pkcs11mtt.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,26 +2766,34 @@ static CK_RV test_rsa_fixed_keys_oaep(void* args)
27662766
(unsigned char*)"aad", 3);
27672767
CHECK_CKR(ret, "SHA256 with AAD");
27682768
}
2769+
#ifndef NO_SHA
27692770
if (ret == CKR_OK) {
27702771
ret = rsa_oaep_test(session, priv, pub, CKM_SHA1, CKG_MGF1_SHA1, NULL,
27712772
0);
27722773
CHECK_CKR(ret, "SHA1 No AAD");
27732774
}
2775+
#endif
2776+
#ifdef WOLFSSL_SHA224
27742777
if (ret == CKR_OK) {
27752778
ret = rsa_oaep_test(session, priv, pub, CKM_SHA224, CKG_MGF1_SHA224,
27762779
NULL, 0);
27772780
CHECK_CKR(ret, "SHA224 No AAD");
27782781
}
2782+
#endif
2783+
#ifdef WOLFSSL_SHA384
27792784
if (ret == CKR_OK) {
27802785
ret = rsa_oaep_test(session, priv, pub, CKM_SHA384, CKG_MGF1_SHA384,
27812786
NULL, 0);
27822787
CHECK_CKR(ret, "SHA384 No AAD");
27832788
}
2789+
#endif
2790+
#ifdef WOLFSSL_SHA512
27842791
if (ret == CKR_OK) {
27852792
ret = rsa_oaep_test(session, priv, pub, CKM_SHA512, CKG_MGF1_SHA512,
27862793
NULL, 0);
27872794
CHECK_CKR(ret, "SHA512 No AAD");
27882795
}
2796+
#endif
27892797

27902798
funcList->C_DestroyObject(session, pub);
27912799
funcList->C_DestroyObject(session, priv);
@@ -2842,22 +2850,30 @@ static CK_RV test_rsa_fixed_keys_pss(void* args)
28422850
ret = rsa_pss_test(session, priv, pub, CKM_SHA256, CKG_MGF1_SHA256, 32);
28432851
CHECK_CKR(ret, "RSA PKCS#1 PSS - SHA256");
28442852
}
2853+
#ifndef NO_SHA
28452854
if (ret == CKR_OK) {
28462855
ret = rsa_pss_test(session, priv, pub, CKM_SHA1, CKG_MGF1_SHA1, 20);
28472856
CHECK_CKR(ret, "RSA PKCS#1 PSS - SHA1");
28482857
}
2858+
#endif
2859+
#ifdef WOLFSSL_SHA224
28492860
if (ret == CKR_OK) {
28502861
ret = rsa_pss_test(session, priv, pub, CKM_SHA224, CKG_MGF1_SHA224, 28);
28512862
CHECK_CKR(ret, "RSA PKCS#1 PSS - SHA224");
28522863
}
2864+
#endif
2865+
#ifdef WOLFSSL_SHA384
28532866
if (ret == CKR_OK) {
28542867
ret = rsa_pss_test(session, priv, pub, CKM_SHA384, CKG_MGF1_SHA384, 48);
28552868
CHECK_CKR(ret, "RSA PKCS#1 PSS - SHA384");
28562869
}
2870+
#endif
2871+
#ifdef WOLFSSL_SHA512
28572872
if (ret == CKR_OK) {
28582873
ret = rsa_pss_test(session, priv, pub, CKM_SHA512, CKG_MGF1_SHA512, 64);
28592874
CHECK_CKR(ret, "RSA PKCS#1 PSS - SHA512");
28602875
}
2876+
#endif
28612877

28622878
funcList->C_DestroyObject(session, pub);
28632879
funcList->C_DestroyObject(session, priv);

0 commit comments

Comments
 (0)