Skip to content

Commit b0741c8

Browse files
committed
Add fixed leave silent
1 parent 27ee99d commit b0741c8

File tree

7 files changed

+126
-96
lines changed

7 files changed

+126
-96
lines changed

include/wolfprovider/wp_logging.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ enum wolfProv_LogComponents {
201201

202202
/* Manually set the log level */
203203
#ifndef WOLFPROV_LOG_LEVEL_FILTER
204-
#define WOLFPROV_LOG_LEVEL_FILTER WP_LOG_LEVEL_ALL
204+
#define WOLFPROV_LOG_LEVEL_FILTER WP_LOG_LEVEL_DEFAULT
205205
#endif
206206

207207
/* Manually set the components */
208208
#ifndef WOLFPROV_LOG_COMPONENTS_FILTER
209-
#define WOLFPROV_LOG_COMPONENTS_FILTER WP_LOG_COMPONENTS_ALL
209+
#define WOLFPROV_LOG_COMPONENTS_FILTER WP_LOG_COMPONENTS_DEFAULT
210210
#endif
211211

212212
/* Conditional logging macro that checks compile-time configuration */
@@ -245,19 +245,15 @@ int wolfProv_SetLogComponents(int componentMask);
245245
WOLFPROV_ERROR_FUNC_LINE(type, funcName, ret, __FILE__, __LINE__)
246246
#define WOLFPROV_ERROR_FUNC_NULL(type, funcName, ret) \
247247
WOLFPROV_ERROR_FUNC_NULL_LINE(type, funcName, ret, __FILE__, __LINE__)
248-
249248
void WOLFPROV_ENTER(int type, const char* msg);
250249
void WOLFPROV_ENTER_SILENT(int type, const char* msg);
251-
252250
#define WOLFPROV_LEAVE(type, msg, ret) \
253251
WOLFPROV_LEAVE_EX(type, WOLFPROV_FUNC_NAME, msg, ret)
254252
void WOLFPROV_LEAVE_EX(int type, const char* func, const char* msg, int ret);
255-
256-
#define WOLFPROV_LEAVE_SILENT(type, msg, matched, ret) \
257-
WOLFPROV_LEAVE_SILENT_EX(type, WOLFPROV_FUNC_NAME, msg, matched, ret)
253+
#define WOLFPROV_LEAVE_SILENT(type, msg, ret) \
254+
WOLFPROV_LEAVE_SILENT_EX(type, WOLFPROV_FUNC_NAME, msg, ret)
258255
void WOLFPROV_LEAVE_SILENT_EX(int type, const char* func, const char* msg,
259-
int matched, int ret);
260-
256+
int ret);
261257
void WOLFPROV_MSG(int type, const char* fmt, ...);
262258
void WOLFPROV_MSG_VERBOSE(int type, const char* fmt, ...);
263259
void WOLFPROV_MSG_DEBUG(int type, const char* fmt, ...);
@@ -277,7 +273,7 @@ void WOLFPROV_BUFFER(int type, const unsigned char* buffer,
277273
#define WOLFPROV_ENTER(t, m)
278274
#define WOLFPROV_ENTER_SILENT(t, m)
279275
#define WOLFPROV_LEAVE(t, m, r)
280-
#define WOLFPROV_LEAVE_SILENT(t, f, m, r)
276+
#define WOLFPROV_LEAVE_SILENT(t, m, r)
281277
#define WOLFPROV_MSG(t, m, ...)
282278
#define WOLFPROV_MSG_VERBOSE(t, m, ...)
283279
#define WOLFPROV_MSG_DEBUG(t, m, ...)

scripts/build-wolfprovider.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ for arg in "$@"; do
116116
;;
117117
--leave-silent)
118118
WOLFPROV_LEAVE_SILENT=1
119-
if [ -z "$WOLFPROV_DEBUG" ] || [ -z "$debug" ]; then
120-
echo "Error: --leave-silent requires --debug to be set."
121-
args_wrong+="$arg, "
122-
fi
123119
;;
124120
*)
125121
args_wrong+="$arg, "
@@ -134,6 +130,12 @@ if [ -n "$args_wrong" ]; then
134130
exit 1
135131
fi
136132

133+
# Check if --leave-silent was used without debug mode
134+
if [ "${WOLFPROV_LEAVE_SILENT}" = "1" ] && [ -z "$WOLFPROV_DEBUG" ] && [ -z "$debug" ]; then
135+
echo "Error: --leave-silent requires --debug to be set."
136+
exit 1
137+
fi
138+
137139
if [ -n "$build_debian" ]; then
138140
echo "Building Debian package..."
139141
./scripts/build-debian.sh

src/wp_dh_kmgmt.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,7 @@ static int wp_dh_decode_spki(wp_Dh* dh, unsigned char* data, word32 len)
20302030
int rc;
20312031
word32 idx = 0;
20322032

2033-
WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_decode_spki");
2033+
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);
20342034

20352035
rc = wc_DhPublicKeyDecode(data, &idx, &dh->key, len);
20362036
if (rc != 0) {
@@ -2053,7 +2053,8 @@ static int wp_dh_decode_spki(wp_Dh* dh, unsigned char* data, word32 len)
20532053
dh->bits = mp_count_bits(&dh->key.p);
20542054
}
20552055

2056-
WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2056+
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2057+
ok);
20572058
return ok;
20582059
}
20592060
#else
@@ -2092,7 +2093,7 @@ static int wp_dh_decode_pki(wp_Dh* dh, unsigned char* data, word32 len)
20922093
word32 idx = 0;
20932094
unsigned char* base = NULL;
20942095

2095-
WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_decode_pki");
2096+
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);
20962097

20972098
rc = wc_DhKeyDecode(data, &idx, &dh->key, len);
20982099
if (rc != 0) {
@@ -2143,7 +2144,8 @@ static int wp_dh_decode_pki(wp_Dh* dh, unsigned char* data, word32 len)
21432144
}
21442145

21452146
OPENSSL_free(base);
2146-
WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2147+
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2148+
ok);
21472149
return ok;
21482150
}
21492151
#else
@@ -2180,7 +2182,7 @@ static int wp_dh_decode_params(wp_Dh* dh, unsigned char* data, word32 len)
21802182
int rc;
21812183
word32 idx = 0;
21822184

2183-
WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_decode_params");
2185+
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);
21842186

21852187
rc = wc_DhKeyDecode(data, &idx, &dh->key, len);
21862188
if (rc != 0) {
@@ -2190,7 +2192,8 @@ static int wp_dh_decode_params(wp_Dh* dh, unsigned char* data, word32 len)
21902192
dh->bits = mp_count_bits(&dh->key.p);
21912193
}
21922194

2193-
WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2195+
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2196+
ok);
21942197
return ok;
21952198
}
21962199

@@ -2821,7 +2824,7 @@ static int wp_dh_type_specific_does_selection(WOLFPROV_CTX* provCtx,
28212824
{
28222825
int ok;
28232826

2824-
WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_type_specific_does_selection");
2827+
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);
28252828

28262829
(void)provCtx;
28272830

@@ -2832,7 +2835,8 @@ static int wp_dh_type_specific_does_selection(WOLFPROV_CTX* provCtx,
28322835
ok = (selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0;
28332836
}
28342837

2835-
WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2838+
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2839+
ok);
28362840
return ok;
28372841
}
28382842

@@ -2937,7 +2941,7 @@ static int wp_dh_spki_does_selection(WOLFPROV_CTX* provCtx, int selection)
29372941
{
29382942
int ok;
29392943

2940-
WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_spki_does_selection");
2944+
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);
29412945

29422946
(void)provCtx;
29432947

@@ -2948,7 +2952,8 @@ static int wp_dh_spki_does_selection(WOLFPROV_CTX* provCtx, int selection)
29482952
ok = (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0;
29492953
}
29502954

2951-
WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2955+
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2956+
ok);
29522957
return ok;
29532958
}
29542959

@@ -3048,7 +3053,7 @@ static int wp_dh_pki_does_selection(WOLFPROV_CTX* provCtx, int selection)
30483053
{
30493054
int ok;
30503055

3051-
WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_pki_does_selection");
3056+
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);
30523057

30533058
(void)provCtx;
30543059

@@ -3059,7 +3064,8 @@ static int wp_dh_pki_does_selection(WOLFPROV_CTX* provCtx, int selection)
30593064
ok = (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0;
30603065
}
30613066

3062-
WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
3067+
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
3068+
ok);
30633069
return ok;
30643070
}
30653071

src/wp_ecc_kmgmt.c

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ static int wp_ecc_decode_params(wp_Ecc* ecc, unsigned char* data, word32 len)
20062006
int rc;
20072007
word32 oidLen;
20082008

2009-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_decode_params");
2009+
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
20102010

20112011
/* TODO: manually decoding as wolfSSL doesn't offer API to do this. */
20122012
if (len < 3) {
@@ -2047,16 +2047,26 @@ static int wp_ecc_decode_params(wp_Ecc* ecc, unsigned char* data, word32 len)
20472047
ok = 0;
20482048
}
20492049

2050-
WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2050+
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2051+
ok);
20512052
return ok;
20522053
}
20532054

2055+
/**
2056+
* Decode the DER encoded ECC parameters (OID) into the ECC key object.
2057+
*
2058+
* @param [in, out] ecc ECC key object.
2059+
* @param [in] data DER encoding of the parameters (OID).
2060+
* @param [in] len Length, in bytes, of DER encoding.
2061+
* @return 1 on success.
2062+
* @return 0 on failure.
2063+
*/
20542064
static int wp_ecc_decode_x963_pub(wp_Ecc* ecc, unsigned char* data, word32 len)
20552065
{
20562066
int ok = 1;
20572067
int rc;
20582068

2059-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_decode_x963_pub");
2069+
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
20602070

20612071
rc = wc_ecc_import_x963((const byte *)data, len, &ecc->key);
20622072
if (rc != 0) {
@@ -2071,7 +2081,8 @@ static int wp_ecc_decode_x963_pub(wp_Ecc* ecc, unsigned char* data, word32 len)
20712081
}
20722082
}
20732083

2074-
WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2084+
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2085+
ok);
20752086
return ok;
20762087
}
20772088

@@ -2090,7 +2101,7 @@ static int wp_ecc_decode_spki(wp_Ecc* ecc, unsigned char* data, word32 len)
20902101
int rc;
20912102
word32 idx = 0;
20922103

2093-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_decode_spki");
2104+
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
20942105

20952106
if (!wolfssl_prov_is_running()) {
20962107
ok = 0;
@@ -2110,7 +2121,8 @@ static int wp_ecc_decode_spki(wp_Ecc* ecc, unsigned char* data, word32 len)
21102121
}
21112122
}
21122123

2113-
WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2124+
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2125+
ok);
21142126
return ok;
21152127
}
21162128

@@ -2129,7 +2141,7 @@ static int wp_ecc_decode_pki(wp_Ecc* ecc, unsigned char* data, word32 len)
21292141
int rc;
21302142
word32 idx = 0;
21312143

2132-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_decode_pki");
2144+
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
21332145

21342146
if (!wolfssl_prov_is_running()) {
21352147
ok = 0;
@@ -2171,7 +2183,8 @@ static int wp_ecc_decode_pki(wp_Ecc* ecc, unsigned char* data, word32 len)
21712183
ecc->hasPub = 1;
21722184
}
21732185

2174-
WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2186+
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2187+
ok);
21752188
return ok;
21762189
}
21772190

@@ -2236,7 +2249,7 @@ static int wp_ecc_decode(wp_EccEncDecCtx* ctx, OSSL_CORE_BIO *cBio,
22362249
unsigned char* data = NULL;
22372250
word32 len = 0;
22382251

2239-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_decode");
2252+
WOLFPROV_ENTER(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
22402253

22412254
(void)pwCb;
22422255
(void)pwCbArg;
@@ -2921,7 +2934,7 @@ static int wp_ecc_type_specific_does_selection(WOLFPROV_CTX* provCtx,
29212934
{
29222935
int ok;
29232936

2924-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_type_specific_does_selection");
2937+
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
29252938

29262939
(void)provCtx;
29272940

@@ -2932,7 +2945,8 @@ static int wp_ecc_type_specific_does_selection(WOLFPROV_CTX* provCtx,
29322945
ok = (selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0;
29332946
}
29342947

2935-
WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2948+
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2949+
ok);
29362950
return ok;
29372951
}
29382952

@@ -3038,7 +3052,7 @@ static int wp_ecc_spki_does_selection(WOLFPROV_CTX* provCtx, int selection)
30383052
{
30393053
int ok;
30403054

3041-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_spki_does_selection");
3055+
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
30423056

30433057
(void)provCtx;
30443058

@@ -3049,7 +3063,8 @@ static int wp_ecc_spki_does_selection(WOLFPROV_CTX* provCtx, int selection)
30493063
ok = (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0;
30503064
}
30513065

3052-
WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
3066+
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
3067+
ok);
30533068
return ok;
30543069
}
30553070

@@ -3149,7 +3164,7 @@ static int wp_ecc_pki_does_selection(WOLFPROV_CTX* provCtx, int selection)
31493164
{
31503165
int ok;
31513166

3152-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_pki_does_selection");
3167+
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
31533168

31543169
(void)provCtx;
31553170

@@ -3160,7 +3175,8 @@ static int wp_ecc_pki_does_selection(WOLFPROV_CTX* provCtx, int selection)
31603175
ok = (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0;
31613176
}
31623177

3163-
WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
3178+
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
3179+
ok);
31643180
return ok;
31653181
}
31663182

@@ -3321,7 +3337,7 @@ static int wp_ecc_x9_62_does_selection(WOLFPROV_CTX* provCtx,
33213337
{
33223338
int ok;
33233339

3324-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_x9_62_does_selection");
3340+
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
33253341

33263342
(void)provCtx;
33273343

@@ -3333,7 +3349,8 @@ static int wp_ecc_x9_62_does_selection(WOLFPROV_CTX* provCtx,
33333349
OSSL_KEYMGMT_SELECT_PRIVATE_KEY)) != 0;
33343350
}
33353351

3336-
WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
3352+
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
3353+
ok);
33373354
return ok;
33383355
}
33393356

src/wp_ecx_kmgmt.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,7 @@ static int wp_ecx_spki_does_selection(WOLFPROV_CTX* provCtx, int selection)
21962196
{
21972197
int ok = 0;
21982198

2199-
WOLFPROV_ENTER(WP_LOG_KE, "wp_ecx_spki_does_selection");
2199+
WOLFPROV_ENTER_SILENT(WP_LOG_KE, WOLFPROV_FUNC_NAME);
22002200

22012201
(void)provCtx;
22022202

@@ -2207,7 +2207,8 @@ static int wp_ecx_spki_does_selection(WOLFPROV_CTX* provCtx, int selection)
22072207
ok = (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0;
22082208
}
22092209

2210-
WOLFPROV_LEAVE(WP_LOG_KE, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2210+
WOLFPROV_LEAVE_SILENT(WP_LOG_KE, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2211+
ok);
22112212
return ok;
22122213
}
22132214

@@ -2227,7 +2228,7 @@ static int wp_ecx_pki_does_selection(WOLFPROV_CTX* provCtx, int selection)
22272228
{
22282229
int ok;
22292230

2230-
WOLFPROV_ENTER(WP_LOG_KE, "wp_ecx_pki_does_selection");
2231+
WOLFPROV_ENTER_SILENT(WP_LOG_KE, WOLFPROV_FUNC_NAME);
22312232

22322233
(void)provCtx;
22332234

@@ -2238,7 +2239,8 @@ static int wp_ecx_pki_does_selection(WOLFPROV_CTX* provCtx, int selection)
22382239
ok = (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0;
22392240
}
22402241

2241-
WOLFPROV_LEAVE(WP_LOG_KE, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2242+
WOLFPROV_LEAVE_SILENT(WP_LOG_KE, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2243+
ok);
22422244
return ok;
22432245
}
22442246

0 commit comments

Comments
 (0)