adjust location used for writing to output buffer

pull/6508/head
JacobBarthelmeh 2023-06-14 21:01:12 -07:00
parent 0a860c793f
commit 5b81dc47d2
3 changed files with 30 additions and 48 deletions

View File

@ -9011,8 +9011,7 @@ int DtlsMsgPoolSend(WOLFSSL* ssl, int sendOnlyFirstPacket)
return ret;
}
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
if (inputSz != ENUM_LEN)
sendSz = BuildMessage(ssl, output, sendSz, input, inputSz,
handshake, 0, 0, 0, epochOrder);
@ -9743,8 +9742,7 @@ static int SendHandshakeMsg(WOLFSSL* ssl, byte* input, word32 inputSz,
return ret;
if (ssl->buffers.outputBuffer.buffer == NULL)
return MEMORY_E;
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
if (IsEncryptionOn(ssl, 1)) {
/* First we need to add the fragment header ourselves.
@ -10074,6 +10072,14 @@ int SendBuffered(WOLFSSL* ssl)
}
/* returns the current location in the output buffer to start writing to */
byte* GetOutputBuffer(WOLFSSL* ssl)
{
return ssl->buffers.outputBuffer.buffer + ssl->buffers.outputBuffer.idx +
ssl->buffers.outputBuffer.length;
}
/* Grow the output buffer */
static WC_INLINE int GrowOutputBuffer(WOLFSSL* ssl, int size)
{
@ -20337,8 +20343,7 @@ int SendChangeCipher(WOLFSSL* ssl)
return ret;
/* get output buffer */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
AddRecordHeader(output, 1, change_cipher_spec, ssl, CUR_ORDER);
@ -21265,9 +21270,7 @@ int SendFinished(WOLFSSL* ssl)
#endif
/* get output buffer */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
AddHandShakeHeader(input, finishedSz, 0, finishedSz, finished, ssl);
/* make finished hashes */
@ -21645,8 +21648,7 @@ int SendCertificate(WOLFSSL* ssl)
return ret;
/* get output buffer */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
/* Safe to use ssl->fragOffset since it will be incremented immediately
* after this block. This block needs to be entered only once to not
@ -22974,9 +22976,7 @@ static int SendAlert_ex(WOLFSSL* ssl, int severity, int type)
return BUFFER_E;
/* get output buffer */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
input[0] = (byte)severity;
input[1] = (byte)type;
ssl->alert_history.last_tx.code = type;
@ -30932,9 +30932,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
return ret;
/* get output buffer */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
AddHeaders(output, length, server_hello, ssl);
/* now write to output */
@ -34415,9 +34413,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
return ret;
/* get output buffer */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
AddHeaders(output, 0, server_hello_done, ssl);
if (IsEncryptionOn(ssl, 1)) {
@ -35265,9 +35261,7 @@ cleanup:
return ret;
/* get output buffer */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
AddHeaders(output, length, session_ticket, ssl);
/* hint */
@ -35806,9 +35800,7 @@ static int DefTicketEncCb(WOLFSSL* ssl, byte key_name[WOLFSSL_TICKET_NAME_SZ],
return ret;
/* get output buffer */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
AddHeaders(output, 0, hello_request, ssl);
if (IsEncryptionOn(ssl, 1)) {
@ -35880,8 +35872,7 @@ static int DefTicketEncCb(WOLFSSL* ssl, byte key_name[WOLFSSL_TICKET_NAME_SZ],
return ret;
/* get output buffer */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
/* Hello Verify Request should use the same sequence number
* as the Client Hello unless we are in renegotiation then

View File

@ -4210,8 +4210,7 @@ int SendTls13ClientHello(WOLFSSL* ssl)
return ret;
/* Get position in output buffer to write new message to. */
args->output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
args->output = GetOutputBuffer(ssl);
/* Put the record and handshake headers on. */
AddTls13Headers(args->output, args->length, client_hello, ssl);
@ -6935,8 +6934,7 @@ int SendTls13ServerHello(WOLFSSL* ssl, byte extMsgType)
return ret;
/* Get position in output buffer to write new message to. */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
/* Put the record and handshake headers on. */
AddTls13Headers(output, length, server_hello, ssl);
@ -7178,8 +7176,7 @@ static int SendTls13EncryptedExtensions(WOLFSSL* ssl)
return ret;
/* Get position in output buffer to write new message to. */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
/* Put the record and handshake headers on. */
AddTls13Headers(output, length, encrypted_extensions, ssl);
@ -7300,8 +7297,7 @@ static int SendTls13CertificateRequest(WOLFSSL* ssl, byte* reqCtx,
return ret;
/* Get position in output buffer to write new message to. */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
/* Put the record and handshake headers on. */
AddTls13Headers(output, reqSz, certificate_request, ssl);
@ -8024,8 +8020,7 @@ static int SendTls13Certificate(WOLFSSL* ssl)
return ret;
/* Get position in output buffer to write new message to. */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
if (ssl->fragOffset == 0) {
AddTls13FragHeaders(output, fragSz, 0, payloadSz, certificate, ssl);
@ -8278,8 +8273,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
}
/* get output buffer */
args->output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
args->output = GetOutputBuffer(ssl);
/* Advance state and proceed */
ssl->options.asyncState = TLS_ASYNC_BUILD;
@ -9491,8 +9485,7 @@ static int SendTls13Finished(WOLFSSL* ssl)
return ret;
/* get output buffer */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
input = output + RECORD_HEADER_SZ;
#ifdef WOLFSSL_DTLS13
@ -9748,8 +9741,7 @@ static int SendTls13KeyUpdate(WOLFSSL* ssl)
return ret;
/* get output buffer */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
input = output + RECORD_HEADER_SZ;
#ifdef WOLFSSL_DTLS13
@ -9941,8 +9933,7 @@ static int SendTls13EndOfEarlyData(WOLFSSL* ssl)
return ret;
/* Get position in output buffer to write new message to. */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
/* Put the record and handshake headers on. */
AddTls13Headers(output, length, end_of_early_data, ssl);
@ -10364,8 +10355,7 @@ static int SendTls13NewSessionTicket(WOLFSSL* ssl)
return ret;
/* Get position in output buffer to write new message to. */
output = ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.length;
output = GetOutputBuffer(ssl);
/* Put the record and handshake headers on. */
AddTls13Headers(output, length, session_ticket, ssl);

View File

@ -5857,6 +5857,7 @@ WOLFSSL_LOCAL int TLSv1_3_Capable(WOLFSSL* ssl);
WOLFSSL_LOCAL void FreeHandshakeResources(WOLFSSL* ssl);
WOLFSSL_LOCAL void ShrinkInputBuffer(WOLFSSL* ssl, int forcedFree);
WOLFSSL_LOCAL void ShrinkOutputBuffer(WOLFSSL* ssl);
WOLFSSL_LOCAL byte* GetOutputBuffer(WOLFSSL* ssl);
WOLFSSL_LOCAL int VerifyClientSuite(word16 havePSK, byte cipherSuite0,
byte cipherSuite);