tls_record.c File Reference

TLS record protocol. More...

#include <string.h>
#include "tls.h"
#include "tls_common.h"
#include "tls_record.h"
#include "tls_misc.h"
#include "ssl_misc.h"
#include "cipher_mode/cbc.h"
#include "aead/ccm.h"
#include "aead/gcm.h"
#include "aead/chacha20_poly1305.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...
 
error_t tlsEncryptRecord (TlsContext *context, TlsEncryptionEngine *encryptionEngine, void *record)
 Encrypt an outgoing TLS record. More...
 
error_t tlsDecryptRecord (TlsContext *context, TlsEncryptionEngine *decryptionEngine, void *record)
 Decrypt an 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...
 
error_t tlsComputeMac (TlsContext *context, TlsEncryptionEngine *encryptionEngine, void *record, const uint8_t *data, size_t dataLen, uint8_t *mac)
 Compute message authentication code. 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

Copyright (C) 2010-2018 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
1.9.0

Definition in file tls_record.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   TLS_TRACE_LEVEL

Definition at line 30 of file tls_record.c.

Function Documentation

◆ tlsComputeMac()

error_t tlsComputeMac ( TlsContext context,
TlsEncryptionEngine encryptionEngine,
void *  record,
const uint8_t *  data,
size_t  dataLen,
uint8_t *  mac 
)

Compute message authentication code.

Parameters
[in]contextPointer to the TLS context
[in]encryptionEnginePointer to the encryption/decryption engine
[in]recordPointer to the TLS record
[in]dataPointer to the record data
[in]dataLenLength of the data
[out]macThe computed MAC value
Returns
Error code

Definition at line 1455 of file tls_record.c.

◆ tlsDecryptRecord()

error_t tlsDecryptRecord ( TlsContext context,
TlsEncryptionEngine decryptionEngine,
void *  record 
)

Decrypt an incoming TLS record.

Parameters
[in]contextPointer to the TLS context
[in]decryptionEnginePointer to the decryption engine
[in,out]recordTLS record to be decrypted
Returns
Error code

Definition at line 995 of file tls_record.c.

◆ tlsEncryptRecord()

error_t tlsEncryptRecord ( TlsContext context,
TlsEncryptionEngine encryptionEngine,
void *  record 
)

Encrypt an outgoing TLS record.

Parameters
[in]contextPointer to the TLS context
[in]encryptionEnginePointer to the encryption engine
[in,out]recordTLS record to be encrypted
Returns
Error code

Definition at line 729 of file tls_record.c.

◆ 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 1516 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 1580 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 1420 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 1389 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 1332 of file tls_record.c.

◆ tlsIncSequenceNumber()

void tlsIncSequenceNumber ( TlsSequenceNumber seqNum)

Increment sequence number.

Parameters
[in]seqNumSequence number to increment

Definition at line 1647 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 614 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 151 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 443 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 1363 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 1306 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 58 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 338 of file tls_record.c.