tls_record.c File Reference

TLS record protocol. More...

#include "tls.h"
#include "tls_record.h"
#include "tls_record_encryption.h"
#include "tls_record_decryption.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   TLS_TRACE_LEVEL
 

Functions

error_t tlsWriteProtocolData (TlsContext *context, const uint8_t *data, size_t length, TlsContentType contentType)
 Write protocol data. More...
 
error_t tlsReadProtocolData (TlsContext *context, uint8_t **data, size_t *length, TlsContentType *contentType)
 Read protocol data. More...
 
error_t tlsWriteRecord (TlsContext *context, const uint8_t *data, size_t length, TlsContentType contentType)
 Send a TLS record. More...
 
error_t tlsReadRecord (TlsContext *context, uint8_t *data, size_t size, size_t *length, TlsContentType *contentType)
 Receive a TLS record. More...
 
error_t tlsProcessRecord (TlsContext *context, TlsRecord *record)
 Process incoming TLS record. More...
 
void tlsSetRecordType (TlsContext *context, void *record, uint8_t type)
 Set TLS record type. More...
 
uint8_t tlsGetRecordType (TlsContext *context, void *record)
 Get TLS record type. More...
 
void tlsSetRecordLength (TlsContext *context, void *record, size_t length)
 Set TLS record length. More...
 
size_t tlsGetRecordLength (TlsContext *context, void *record)
 Get TLS record length. More...
 
uint8_t * tlsGetRecordData (TlsContext *context, void *record)
 Get TLS record payload. More...
 
void tlsFormatAad (TlsContext *context, TlsEncryptionEngine *encryptionEngine, const void *record, uint8_t *aad, size_t *aadLen)
 Format additional authenticated data (AAD) More...
 
void tlsFormatNonce (TlsContext *context, TlsEncryptionEngine *encryptionEngine, const void *record, const uint8_t *recordIv, uint8_t *nonce, size_t *nonceLen)
 Format nonce. More...
 
void tlsIncSequenceNumber (TlsSequenceNumber *seqNum)
 Increment sequence number. More...
 

Detailed Description

TLS record protocol.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneSSL Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file tls_record.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   TLS_TRACE_LEVEL

Definition at line 32 of file tls_record.c.

Function Documentation

◆ tlsFormatAad()

void tlsFormatAad ( TlsContext context,
TlsEncryptionEngine encryptionEngine,
const void *  record,
uint8_t *  aad,
size_t *  aadLen 
)

Format additional authenticated data (AAD)

Parameters
[in]contextPointer to the TLS context
[in]encryptionEnginePointer to the encryption engine
[in]recordPointer to the TLS record
[out]aadPointer to the buffer where to store the resulting AAD
[out]aadLenLength of the AAD, in bytes

Definition at line 905 of file tls_record.c.

◆ tlsFormatNonce()

void tlsFormatNonce ( TlsContext context,
TlsEncryptionEngine encryptionEngine,
const void *  record,
const uint8_t *  recordIv,
uint8_t *  nonce,
size_t *  nonceLen 
)

Format nonce.

Parameters
[in]contextPointer to the TLS context
[in]encryptionEnginePointer to the encryption engine
[in]recordPointer to the TLS record
[in]recordIvExplicit part of the nonce
[out]noncePointer to the buffer where to store the resulting nonce
[out]nonceLenLength of the nonce, in bytes

Definition at line 963 of file tls_record.c.

◆ tlsGetRecordData()

uint8_t* tlsGetRecordData ( TlsContext context,
void *  record 
)

Get TLS record payload.

Parameters
[in]contextPointer to the TLS context
[in]recordPointer to the TLS record
Returns
Pointer to the first byte of the payload

Definition at line 872 of file tls_record.c.

◆ tlsGetRecordLength()

size_t tlsGetRecordLength ( TlsContext context,
void *  record 
)

Get TLS record length.

Parameters
[in]contextPointer to the TLS context
[in]recordPointer to the TLS record
Returns
Record length

Definition at line 841 of file tls_record.c.

◆ tlsGetRecordType()

uint8_t tlsGetRecordType ( TlsContext context,
void *  record 
)

Get TLS record type.

Parameters
[in]contextPointer to the TLS context
[in]recordPointer to the TLS record
Returns
Record type

Definition at line 784 of file tls_record.c.

◆ tlsIncSequenceNumber()

void tlsIncSequenceNumber ( TlsSequenceNumber seqNum)

Increment sequence number.

Parameters
[in,out]seqNumPointer to the 64-bit sequence number

Definition at line 1030 of file tls_record.c.

◆ tlsProcessRecord()

error_t tlsProcessRecord ( TlsContext context,
TlsRecord record 
)

Process incoming TLS record.

Parameters
[in]contextPointer to the TLS context
[in]recordPointer to the received TLS record
Returns
Error code

Definition at line 626 of file tls_record.c.

◆ tlsReadProtocolData()

error_t tlsReadProtocolData ( TlsContext context,
uint8_t **  data,
size_t *  length,
TlsContentType contentType 
)

Read protocol data.

Parameters
[in]contextPointer to the TLS context
[out]dataPointer to the received data
[out]lengthNumber of data bytes that were received
[out]contentTypeHigher level protocol
Returns
Error code

Definition at line 157 of file tls_record.c.

◆ tlsReadRecord()

error_t tlsReadRecord ( TlsContext context,
uint8_t *  data,
size_t  size,
size_t *  length,
TlsContentType contentType 
)

Receive a TLS record.

Parameters
[in]contextPointer to the TLS context
[out]dataBuffer where to store the record data
[in]sizeMaximum acceptable size for the incoming record
[out]lengthLength of the record data
[out]contentTypeRecord type
Returns
Error code

Definition at line 455 of file tls_record.c.

◆ tlsSetRecordLength()

void tlsSetRecordLength ( TlsContext context,
void *  record,
size_t  length 
)

Set TLS record length.

Parameters
[in]contextPointer to the TLS context
[in]recordPointer to the TLS record
[in]lengthRecord length

Definition at line 815 of file tls_record.c.

◆ tlsSetRecordType()

void tlsSetRecordType ( TlsContext context,
void *  record,
uint8_t  type 
)

Set TLS record type.

Parameters
[in]contextPointer to the TLS context
[in]recordPointer to the TLS record
[in]typeRecord type

Definition at line 758 of file tls_record.c.

◆ tlsWriteProtocolData()

error_t tlsWriteProtocolData ( TlsContext context,
const uint8_t *  data,
size_t  length,
TlsContentType  contentType 
)

Write protocol data.

Parameters
[in]contextPointer to the TLS context
[in]dataPointer to the data buffer
[in]lengthNumber of data bytes to be written
[in]contentTypeHigher level protocol
Returns
Error code

Definition at line 54 of file tls_record.c.

◆ tlsWriteRecord()

error_t tlsWriteRecord ( TlsContext context,
const uint8_t *  data,
size_t  length,
TlsContentType  contentType 
)

Send a TLS record.

Parameters
[in]contextPointer to the TLS context
[in]dataPointer to the record data
[in]lengthLength of the record data
[in]contentTypeRecord type
Returns
Error code

Definition at line 350 of file tls_record.c.