Skip to content

Commit 5e5286d

Browse files
author
gojimmypi
committed
Merge branch 'master' of https://github.com/wolfSSL/wolfssl into PR-Expressif-Benchmark
2 parents f3a9d4a + 5caa71e commit 5e5286d

9 files changed

Lines changed: 85 additions & 27 deletions

File tree

IDE/WIN10/wolfssl-fips.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@
272272
<ClCompile Include="..\..\wolfcrypt\src\hash.c" />
273273
<ClCompile Include="..\..\wolfcrypt\src\hmac.c" />
274274
<ClCompile Include="..\..\wolfcrypt\src\integer.c" />
275+
<ClCompile Include="..\..\wolfcrypt\src\pkcs7.c" />
275276
<ClCompile Include="..\..\wolfcrypt\src\tfm.c" />
276277
<ClCompile Include="..\..\src\internal.c" />
277278
<ClCompile Include="..\..\src\wolfio.c" />

src/internal.c

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19609,7 +19609,8 @@ int DoApplicationData(WOLFSSL* ssl, byte* input, word32* inOutIdx, int sniff)
1960919609
return BUFFER_ERROR;
1961019610
}
1961119611
#ifdef WOLFSSL_EARLY_DATA
19612-
if (ssl->earlyData > early_data_ext) {
19612+
if (ssl->options.side == WOLFSSL_SERVER_END &&
19613+
ssl->earlyData > early_data_ext) {
1961319614
if (ssl->earlyDataSz + dataSz > ssl->options.maxEarlyDataSz) {
1961419615
if (sniff == NO_SNIFF) {
1961519616
SendAlert(ssl, alert_fatal, unexpected_message);
@@ -19649,11 +19650,14 @@ int DoApplicationData(WOLFSSL* ssl, byte* input, word32* inOutIdx, int sniff)
1964919650
#endif
1965019651

1965119652
*inOutIdx = idx;
19653+
#ifdef WOLFSSL_DTLS13
19654+
if (ssl->options.connectState == WAIT_FINISHED_ACK) {
19655+
/* DTLS 1.3 is waiting for an ACK but we can still return app data. */
19656+
return APP_DATA_READY;
19657+
}
19658+
#endif
1965219659
#ifdef HAVE_SECURE_RENEGOTIATION
1965319660
if (IsSCR(ssl)) {
19654-
/* Reset the processReply state since
19655-
* we finished processing this message. */
19656-
ssl->options.processReply = doProcessInit;
1965719661
/* If we are in a secure renegotiation then APP DATA is treated
1965819662
* differently */
1965919663
return APP_DATA_READY;
@@ -20246,7 +20250,7 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2024620250
#endif
2024720251

2024820252
if (ssl->error != 0 && ssl->error != WANT_READ && ssl->error != WANT_WRITE
20249-
#ifdef HAVE_SECURE_RENEGOTIATION
20253+
#if defined(HAVE_SECURE_RENEGOTIATION) || defined(WOLFSSL_DTLS13)
2025020254
&& ssl->error != APP_DATA_READY
2025120255
#endif
2025220256
#ifdef WOLFSSL_ASYNC_CRYPT
@@ -21213,7 +21217,13 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2121321217
&ssl->buffers.inputBuffer.idx,
2121421218
NO_SNIFF)) != 0) {
2121521219
WOLFSSL_ERROR(ret);
21216-
return ret;
21220+
#if defined(WOLFSSL_DTLS13) || \
21221+
defined(HAVE_SECURE_RENEGOTIATION)
21222+
/* Not really an error. We will return after cleaning
21223+
* up the processReply state. */
21224+
if (ret != APP_DATA_READY)
21225+
#endif
21226+
return ret;
2121721227
}
2121821228
break;
2121921229

@@ -21270,9 +21280,18 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2127021280
/* input exhausted */
2127121281
if (ssl->buffers.inputBuffer.idx >= ssl->buffers.inputBuffer.length
2127221282
#ifdef WOLFSSL_DTLS
21273-
/* If app data was processed then return now to avoid
21274-
* dropping any app data. */
21275-
|| (ssl->options.dtls && ssl->curRL.type == application_data)
21283+
|| (ssl->options.dtls &&
21284+
/* If app data was processed then return now to avoid
21285+
* dropping any app data. */
21286+
(ssl->curRL.type == application_data ||
21287+
/* client: if we processed a finished message, return to
21288+
* allow higher layers to establish the crypto
21289+
* parameters of the connection. The remaining data
21290+
* may be app data that we would drop without the
21291+
* crypto setup. */
21292+
(ssl->options.side == WOLFSSL_CLIENT_END &&
21293+
ssl->options.serverState == SERVER_FINISHED_COMPLETE &&
21294+
ssl->options.handShakeState != HANDSHAKE_DONE)))
2127621295
#endif
2127721296
) {
2127821297
/* Shrink input buffer when we successfully finish record
@@ -21327,6 +21346,11 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2132721346
* by higher layers. */
2132821347
if (ret != 0)
2132921348
return ret;
21349+
#endif
21350+
#if defined(WOLFSSL_DTLS13) || defined(HAVE_SECURE_RENEGOTIATION)
21351+
/* Signal to user that we have application data ready to read */
21352+
if (ret == APP_DATA_READY)
21353+
return ret;
2133021354
#endif
2133121355
/* It is safe to shrink the input buffer here now. local vars will
2133221356
* be reset to the new starting value. */
@@ -23598,6 +23622,12 @@ int SendData(WOLFSSL* ssl, const void* data, int sz)
2359823622
groupMsgs = 1;
2359923623
#endif
2360023624
}
23625+
else if (IsAtLeastTLSv1_3(ssl->version) &&
23626+
ssl->options.side == WOLFSSL_SERVER_END &&
23627+
ssl->options.acceptState >= TLS13_ACCEPT_FINISHED_SENT) {
23628+
/* We can send data without waiting on peer finished msg */
23629+
WOLFSSL_MSG("server sending data before receiving client finished");
23630+
}
2360123631
else
2360223632
#endif
2360323633
if (ssl->options.handShakeState != HANDSHAKE_DONE && !IsSCR(ssl)) {
@@ -23835,7 +23865,7 @@ int ReceiveData(WOLFSSL* ssl, byte* output, int sz, int peek)
2383523865
#ifdef WOLFSSL_ASYNC_CRYPT
2383623866
&& ssl->error != WC_PENDING_E
2383723867
#endif
23838-
#ifdef HAVE_SECURE_RENEGOTIATION
23868+
#if defined(HAVE_SECURE_RENEGOTIATION) || defined(WOLFSSL_DTLS13)
2383923869
&& ssl->error != APP_DATA_READY
2384023870
#endif
2384123871
) {
@@ -27050,7 +27080,7 @@ int DecodePrivateKey(WOLFSSL *ssl, word16* length)
2705027080
|| wolfSSL_CTX_IsPrivatePkSet(ssl->ctx)
2705127081
#endif
2705227082
) {
27053-
*length = GetPrivateKeySigSize(ssl);
27083+
*length = (word16)GetPrivateKeySigSize(ssl);
2705427084
return 0;
2705527085
}
2705627086
else
@@ -31582,7 +31612,7 @@ int SendCertificateVerify(WOLFSSL* ssl)
3158231612
if (ssl->buffers.key == NULL) {
3158331613
#ifdef HAVE_PK_CALLBACKS
3158431614
if (wolfSSL_CTX_IsPrivatePkSet(ssl->ctx))
31585-
args->length = GetPrivateKeySigSize(ssl);
31615+
args->length = (word16)GetPrivateKeySigSize(ssl);
3158631616
else
3158731617
#endif
3158831618
ERROR_OUT(NO_PRIVATE_KEY, exit_scv);
@@ -33555,7 +33585,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3355533585
if (ssl->buffers.key == NULL) {
3355633586
#ifdef HAVE_PK_CALLBACKS
3355733587
if (wolfSSL_CTX_IsPrivatePkSet(ssl->ctx))
33558-
keySz = (word32)GetPrivateKeySigSize(ssl);
33588+
keySz = (word16)GetPrivateKeySigSize(ssl);
3355933589
else
3356033590
#endif
3356133591
ERROR_OUT(NO_PRIVATE_KEY, exit_sske);

src/ssl.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3233,7 +3233,14 @@ int wolfSSL_write(WOLFSSL* ssl, const void* data, int sz)
32333233
}
32343234
#endif
32353235
#ifdef WOLFSSL_EARLY_DATA
3236-
if (ssl->earlyData != no_early_data && (ret = wolfSSL_negotiate(ssl)) < 0) {
3236+
if (IsAtLeastTLSv1_3(ssl->version) &&
3237+
ssl->options.side == WOLFSSL_SERVER_END &&
3238+
ssl->options.acceptState >= TLS13_ACCEPT_FINISHED_SENT) {
3239+
/* We can send data without waiting on peer finished msg */
3240+
WOLFSSL_MSG("server sending data before receiving client finished");
3241+
}
3242+
else if (ssl->earlyData != no_early_data &&
3243+
(ret = wolfSSL_negotiate(ssl)) < 0) {
32373244
ssl->error = ret;
32383245
return WOLFSSL_FATAL_ERROR;
32393246
}
@@ -7779,11 +7786,11 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
77797786

77807787
#ifdef WOLF_PRIVATE_KEY_ID
77817788
if (ssl != NULL) {
7782-
ssl->buffers.keyType = keyType;
7789+
ssl->buffers.keyType = (byte)keyType;
77837790
ssl->buffers.keySz = keySz;
77847791
}
77857792
else if (ctx != NULL) {
7786-
ctx->privateKeyType = keyType;
7793+
ctx->privateKeyType = (byte)keyType;
77877794
ctx->privateKeySz = keySz;
77887795
}
77897796
#endif

src/tls13.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8633,7 +8633,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
86338633
if (ssl->buffers.key == NULL) {
86348634
#ifdef HAVE_PK_CALLBACKS
86358635
if (wolfSSL_CTX_IsPrivatePkSet(ssl->ctx))
8636-
args->length = GetPrivateKeySigSize(ssl);
8636+
args->length = (word16)GetPrivateKeySigSize(ssl);
86378637
else
86388638
#endif
86398639
ERROR_OUT(NO_PRIVATE_KEY, exit_scv);

tests/api.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68148,6 +68148,7 @@ static int test_dtls13_early_data(void)
6814868148
char msg[] = "This is early data";
6814968149
char msg2[] = "This is client data";
6815068150
char msg3[] = "This is server data";
68151+
char msg4[] = "This is server immediate data";
6815168152
char msgBuf[50];
6815268153

6815368154
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
@@ -68175,6 +68176,7 @@ static int test_dtls13_early_data(void)
6817568176
ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS);
6817668177
#endif
6817768178

68179+
/* Test 0-RTT data */
6817868180
ExpectIntEQ(wolfSSL_write_early_data(ssl_c, msg, sizeof(msg),
6817968181
&written), sizeof(msg));
6818068182
ExpectIntEQ(written, sizeof(msg));
@@ -68184,6 +68186,15 @@ static int test_dtls13_early_data(void)
6818468186
ExpectIntEQ(read, sizeof(msg));
6818568187
ExpectStrEQ(msg, msgBuf);
6818668188

68189+
/* Test 0.5-RTT data */
68190+
ExpectIntEQ(wolfSSL_write(ssl_s, msg4, sizeof(msg4)), sizeof(msg4));
68191+
68192+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
68193+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), APP_DATA_READY);
68194+
68195+
ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg4));
68196+
ExpectStrEQ(msg4, msgBuf);
68197+
6818768198
/* Complete handshake */
6818868199
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
6818968200
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
@@ -68195,11 +68206,14 @@ static int test_dtls13_early_data(void)
6819568206
* parsing logic. */
6819668207
ExpectFalse(wolfSSL_is_init_finished(ssl_s));
6819768208
ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
68198-
&read), WOLFSSL_FAILURE);
68199-
ExpectTrue(wolfSSL_is_init_finished(ssl_s));
68209+
&read), -1);
68210+
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
6820068211

6820168212
ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
6820268213

68214+
ExpectTrue(wolfSSL_is_init_finished(ssl_s));
68215+
68216+
6820368217
/* Test bi-directional write */
6820468218
ExpectIntEQ(wolfSSL_write(ssl_c, msg2, sizeof(msg2)), sizeof(msg2));
6820568219
ExpectIntEQ(wolfSSL_read(ssl_s, msgBuf, sizeof(msgBuf)), sizeof(msg2));

wolfcrypt/src/integer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4425,9 +4425,6 @@ int mp_add_d (mp_int* a, mp_digit b, mp_int* c) /* //NOLINT(misc-no-recursion) *
44254425
/* old number of used digits in c */
44264426
oldused = c->used;
44274427

4428-
/* sign always positive */
4429-
c->sign = MP_ZPOS;
4430-
44314428
/* source alias */
44324429
tmpa = a->dp;
44334430

@@ -4478,6 +4475,9 @@ int mp_add_d (mp_int* a, mp_digit b, mp_int* c) /* //NOLINT(misc-no-recursion) *
44784475
ix = 1;
44794476
}
44804477

4478+
/* sign always positive */
4479+
c->sign = MP_ZPOS;
4480+
44814481
/* now zero to oldused */
44824482
while (ix++ < oldused) {
44834483
*tmpc++ = 0;

wolfcrypt/src/pkcs7.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4627,7 +4627,7 @@ static int PKCS7_VerifySignedData(PKCS7* pkcs7, const byte* hashBuf,
46274627
WOLFSSL_MSG("PKCS#7 signedData needs to be version 1 or 3");
46284628
ret = ASN_VERSION_E;
46294629
}
4630-
pkcs7->version = version;
4630+
pkcs7->version = (byte)version;
46314631

46324632
/* Get the set of DigestAlgorithmIdentifiers */
46334633
if (ret == 0 && GetSet(pkiMsg, &idx, &length, pkiMsgSz) < 0)
@@ -4913,7 +4913,7 @@ static int PKCS7_VerifySignedData(PKCS7* pkcs7, const byte* hashBuf,
49134913
if (multiPart) {
49144914
pkcs7->stream->expected = contentLen + ASN_TAG_SZ;
49154915
}
4916-
pkcs7->stream->multi = multiPart;
4916+
pkcs7->stream->multi = (byte)multiPart;
49174917

49184918
#endif
49194919
wc_PKCS7_ChangeState(pkcs7, WC_PKCS7_VERIFY_STAGE3);
@@ -5221,7 +5221,7 @@ static int PKCS7_VerifySignedData(PKCS7* pkcs7, const byte* hashBuf,
52215221
pkcs7->stream = stream;
52225222
#endif
52235223
}
5224-
pkcs7->version = version;
5224+
pkcs7->version = (byte)version;
52255225
#ifdef ASN_BER_TO_DER
52265226
pkcs7->der = der;
52275227
#endif
@@ -7692,7 +7692,7 @@ static int wc_PKCS7_PwriKek_KeyWrap(PKCS7* pkcs7, const byte* kek, word32 kekSz,
76927692
if (*outSz < (word32)outLen)
76937693
return BUFFER_E;
76947694

7695-
out[0] = cekSz;
7695+
out[0] = (byte)cekSz;
76967696
out[1] = ~cek[0];
76977697
out[2] = ~cek[1];
76987698
out[3] = ~cek[2];
@@ -10845,7 +10845,7 @@ WOLFSSL_API int wc_PKCS7_DecodeEnvelopedData(PKCS7* pkcs7, byte* in,
1084510845
byte* encryptedContent = NULL;
1084610846
int explicitOctet = 0;
1084710847
word32 localIdx;
10848-
byte tag;
10848+
byte tag = 0;
1084910849

1085010850
if (pkcs7 == NULL)
1085110851
return BAD_FUNC_ARG;

wolfcrypt/src/sp_int.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17524,6 +17524,11 @@ int sp_mont_red_ex(sp_int* a, const sp_int* m, sp_int_digit mp, int ct)
1752417524
if ((a == NULL) || (m == NULL) || sp_iszero(m)) {
1752517525
err = MP_VAL;
1752617526
}
17527+
#ifdef WOLFSSL_SP_INT_NEGATIVE
17528+
else if ((a->sign == MP_NEG) || (m->sign == MP_NEG)) {
17529+
err = MP_VAL;
17530+
}
17531+
#endif
1752717532
/* Ensure a has enough space for calculation. */
1752817533
else if (a->size < m->used * 2 + 1) {
1752917534
err = MP_VAL;

wolfssl.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@
299299
<ClCompile Include="wolfcrypt\src\curve25519.c" />
300300
<ClCompile Include="wolfcrypt\src\curve448.c" />
301301
<ClCompile Include="wolfcrypt\src\cpuid.c" />
302+
<ClCompile Include="wolfcrypt\src\cryptocb.c" />
302303
<ClCompile Include="wolfcrypt\src\des3.c" />
303304
<ClCompile Include="wolfcrypt\src\dh.c" />
304305
<ClCompile Include="wolfcrypt\src\dsa.c" />

0 commit comments

Comments
 (0)