Skip to content

Commit c335f7d

Browse files
padelsbachJacobBarthelmeh
authored andcommitted
Remove UTF-8 chars
Get rid of weird character Fix warning found by CI Style changes Addressed 1 and 2.
1 parent 2e32094 commit c335f7d

File tree

5 files changed

+60
-44
lines changed

5 files changed

+60
-44
lines changed

src/ssl_sess.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,12 @@ int wolfSSL_memsave_session_cache(void* mem, int sz)
487487
int wolfSSL_memrestore_session_cache(const void* mem, int sz)
488488
{
489489
int i;
490+
#ifndef SESSION_CACHE_DYNAMIC_MEM
491+
#if defined(HAVE_SESSION_TICKET) || \
492+
(defined(SESSION_CERTS) && defined(OPENSSL_EXTRA))
493+
int j;
494+
#endif
495+
#endif
490496
cache_header_t cache_header;
491497
SessionRow* row = (SessionRow*)((byte*)mem + sizeof(cache_header));
492498

@@ -523,21 +529,24 @@ int wolfSSL_memrestore_session_cache(const void* mem, int sz)
523529

524530
XMEMCPY(&SessionCache[i], row++, SIZEOF_SESSION_ROW);
525531
#ifndef SESSION_CACHE_DYNAMIC_MEM
532+
#if defined(HAVE_SESSION_TICKET) || \
533+
(defined(SESSION_CERTS) && defined(OPENSSL_EXTRA))
526534
/* Reset pointers to safe values after raw copy */
527-
{
528-
int j;
529-
for (j = 0; j < SESSIONS_PER_ROW; j++) {
530-
WOLFSSL_SESSION* s = &SessionCache[i].Sessions[j];
535+
for (j = 0; j < SESSIONS_PER_ROW; j++) {
536+
WOLFSSL_SESSION* s = &SessionCache[i].Sessions[j];
531537
#ifdef HAVE_SESSION_TICKET
532-
s->ticket = s->staticTicket;
533-
s->ticketLenAlloc = 0;
538+
s->ticket = s->staticTicket;
539+
s->ticketLenAlloc = 0;
540+
if (s->ticketLen > SESSION_TICKET_LEN) {
541+
s->ticketLen = SESSION_TICKET_LEN;
542+
}
534543
#endif
535544
#if defined(SESSION_CERTS) && defined(OPENSSL_EXTRA)
536-
s->peer = NULL;
545+
s->peer = NULL;
537546
#endif
538-
}
539547
}
540548
#endif
549+
#endif
541550
#ifdef ENABLE_SESSION_CACHE_ROW_LOCK
542551
SESSION_ROW_UNLOCK(&SessionCache[i]);
543552
#endif
@@ -698,6 +707,8 @@ int wolfSSL_restore_session_cache(const char *fname)
698707

699708
ret = (int)XFREAD(&SessionCache[i], SIZEOF_SESSION_ROW, 1, file);
700709
#ifndef SESSION_CACHE_DYNAMIC_MEM
710+
#if defined(HAVE_SESSION_TICKET) || \
711+
(defined(SESSION_CERTS) && defined(OPENSSL_EXTRA))
701712
/* Reset pointers to safe values after raw copy */
702713
{
703714
int j;
@@ -706,13 +717,17 @@ int wolfSSL_restore_session_cache(const char *fname)
706717
#ifdef HAVE_SESSION_TICKET
707718
s->ticket = s->staticTicket;
708719
s->ticketLenAlloc = 0;
720+
if (s->ticketLen > SESSION_TICKET_LEN) {
721+
s->ticketLen = SESSION_TICKET_LEN;
722+
}
709723
#endif
710724
#if defined(SESSION_CERTS) && defined(OPENSSL_EXTRA)
711725
s->peer = NULL;
712726
#endif
713727
}
714728
}
715729
#endif
730+
#endif
716731
#ifdef ENABLE_SESSION_CACHE_ROW_LOCK
717732
SESSION_ROW_UNLOCK(&SessionCache[i]);
718733
#endif

tests/api.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35020,7 +35020,7 @@ static int test_dilithium_hash(void)
3502035020
ExpectIntEQ(wc_dilithium_make_key(&key, &rng), 0);
3502135021

3502235022
ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sizeof(sig), NULL, 0,
35023-
msg, 0xFFFFFFC0u, &res, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
35023+
msg, 0xFFFFFFC0, &res, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3502435024

3502535025
wc_dilithium_free(&key);
3502635026
DoExpectIntEQ(wc_FreeRng(&rng), 0);
@@ -35036,11 +35036,11 @@ static int test_pkcs7_padding(void)
3503635036
defined(WOLFSSL_AES_256) && !defined(NO_PKCS7_ENCRYPTED_DATA)
3503735037
PKCS7 pkcs7;
3503835038
byte key[32];
35039-
byte plaintext[27]; /* 27 bytes padded to 32 padding = 05 05 05 05 05 */
35039+
byte plaintext[27]; /* 27 bytes -> padded to 32 -> padding = 05 05 05 05 05 */
3504035040
byte encoded[4096];
3504135041
byte output[256];
3504235042
byte modified[4096];
35043-
int encodedSz;
35043+
int encodedSz = 0;
3504435044
int outSz;
3504535045
int ctOff = -1;
3504635046
int ctLen = 0;
@@ -35100,15 +35100,15 @@ static int test_pkcs7_padding(void)
3510035100
/* Flip byte in penultimate block to corrupt interior padding */
3510135101
modified[ctOff + ctLen - 32 + 11] ^= 0x42;
3510235102

35103-
/* Decrypt modified ciphertext must fail, not succeed */
35103+
/* Decrypt modified ciphertext - must fail, not succeed */
3510435104
XMEMSET(&pkcs7, 0, sizeof(pkcs7));
3510535105
ExpectIntEQ(wc_PKCS7_Init(&pkcs7, NULL, 0), 0);
3510635106
pkcs7.encryptionKey = key;
3510735107
pkcs7.encryptionKeySz = sizeof(key);
3510835108

3510935109
outSz = wc_PKCS7_DecodeEncryptedData(&pkcs7, modified,
3511035110
(word32)encodedSz, output, sizeof(output));
35111-
/* Must return an error if it returns plaintext size, padding
35111+
/* Must return an error - if it returns plaintext size, padding
3511235112
* oracle vulnerability exists */
3511335113
ExpectIntLT(outSz, 0);
3511435114
wc_PKCS7_Free(&pkcs7);

wolfcrypt/src/evp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11877,7 +11877,7 @@ static int PrintHexWithColon(WOLFSSL_BIO* out, const byte* input,
1187711877
static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
1187811878
int indent, int bitlen, WOLFSSL_ASN1_PCTX* pctx)
1187911879
{
11880-
byte buff[24] = { 0 };
11880+
byte buff[EVP_EXPONENT_PRINT_MAX] = { 0 };
1188111881
int res = WC_NO_ERR_TRACE(WOLFSSL_FAILURE);
1188211882
word32 inOutIdx = 0;
1188311883
word32 nSz; /* size of modulus */
@@ -12021,7 +12021,7 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
1202112021
{
1202212022
byte* pub = NULL;
1202312023
word32 pubSz = 0;
12024-
byte buff[24] = { 0 };
12024+
byte buff[EVP_EXPONENT_PRINT_MAX] = { 0 };
1202512025
int res = WOLFSSL_SUCCESS;
1202612026
word32 inOutIdx = 0;
1202712027
int curveId = 0;
@@ -12210,7 +12210,7 @@ static int PrintPubKeyDSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
1221012210
int indent, int bitlen, WOLFSSL_ASN1_PCTX* pctx)
1221112211
{
1221212212

12213-
byte buff[24] = { 0 };
12213+
byte buff[EVP_EXPONENT_PRINT_MAX] = { 0 };
1221412214
int length;
1221512215
int res = WC_NO_ERR_TRACE(WOLFSSL_FAILURE);
1221612216
word32 inOutIdx = 0;
@@ -12417,7 +12417,7 @@ static int PrintPubKeyDH(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
1241712417
int indent, int bitlen, WOLFSSL_ASN1_PCTX* pctx)
1241812418
{
1241912419

12420-
byte buff[24] = { 0 };
12420+
byte buff[EVP_EXPONENT_PRINT_MAX] = { 0 };
1242112421
int res = WC_NO_ERR_TRACE(WOLFSSL_FAILURE);
1242212422
word32 length;
1242312423
word32 inOutIdx;

wolfcrypt/src/pkcs7.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12759,7 +12759,9 @@ int wc_PKCS7_DecodeEnvelopedData(wc_PKCS7* pkcs7, byte* in,
1275912759
byte* encryptedContent = NULL;
1276012760
int explicitOctet = 0;
1276112761
word32 localIdx = 0;
12762-
byte tag = 0;
12762+
byte tag = 0;
12763+
byte padCheck = 0;
12764+
int padIndex;
1276312765

1276412766
if (pkcs7 == NULL)
1276512767
return BAD_FUNC_ARG;
@@ -13267,18 +13269,16 @@ int wc_PKCS7_DecodeEnvelopedData(wc_PKCS7* pkcs7, byte* in,
1326713269
ret = BUFFER_E;
1326813270
break;
1326913271
}
13270-
/* Constant-time check all padding bytes */
13271-
{
13272-
byte padCheck = 0;
13273-
int pi;
13274-
for (pi = encryptedContentSz - padLen;
13275-
pi < encryptedContentSz; pi++) {
13276-
padCheck |= encryptedContent[pi] ^ padLen;
13277-
}
13278-
if (padCheck != 0) {
13279-
ret = BUFFER_E;
13280-
break;
13281-
}
13272+
13273+
/* Check all padding bytes. Better implementation would be to run
13274+
* through the entire block. */
13275+
for (padIndex = encryptedContentSz - padLen;
13276+
padIndex < encryptedContentSz; padIndex++) {
13277+
padCheck |= encryptedContent[padIndex] ^ padLen;
13278+
}
13279+
if (padCheck != 0) {
13280+
ret = BUFFER_E;
13281+
break;
1328213282
}
1328313283

1328413284
#ifdef ASN_BER_TO_DER
@@ -15052,6 +15052,8 @@ int wc_PKCS7_DecodeEncryptedData(wc_PKCS7* pkcs7, byte* in, word32 inSz,
1505215052
byte* pkiMsg = in;
1505315053
word32 pkiMsgSz = inSz;
1505415054
byte tag = 0;
15055+
byte padCheck = 0;
15056+
int padIndex;
1505515057

1505615058
if (pkcs7 == NULL ||
1505715059
((pkcs7->encryptionKey == NULL || pkcs7->encryptionKeySz == 0) &&
@@ -15336,20 +15338,18 @@ int wc_PKCS7_DecodeEncryptedData(wc_PKCS7* pkcs7, byte* in, word32 inSz,
1533615338
XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
1533715339
break;
1533815340
}
15339-
/* Constant-time check all padding bytes */
15340-
{
15341-
byte padCheck = 0;
15342-
int pi;
15343-
for (pi = encryptedContentSz - padLen;
15344-
pi < encryptedContentSz; pi++) {
15345-
padCheck |= encryptedContent[pi] ^ padLen;
15346-
}
15347-
if (padCheck != 0) {
15348-
WOLFSSL_MSG("Bad padding bytes found");
15349-
ret = BUFFER_E;
15350-
XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
15351-
break;
15352-
}
15341+
15342+
/* Check all padding bytes. Better implementation would be to
15343+
* run through the entire block. */
15344+
for (padIndex = encryptedContentSz - padLen;
15345+
padIndex < encryptedContentSz; padIndex++) {
15346+
padCheck |= encryptedContent[padIndex] ^ padLen;
15347+
}
15348+
if (padCheck != 0) {
15349+
WOLFSSL_MSG("Bad padding bytes found");
15350+
ret = BUFFER_E;
15351+
XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
15352+
break;
1535315353
}
1535415354

1535515355
/* copy plaintext to output */

wolfssl/wolfcrypt/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,6 +2423,7 @@ enum Max_ASN {
24232423

24242424
#endif /* WOLFSSL_CERT_GEN */
24252425

2426+
#define EVP_EXPONENT_PRINT_MAX 24
24262427

24272428
#ifdef __cplusplus
24282429
} /* extern "C" */

0 commit comments

Comments
 (0)