tls_misc.h File Reference

TLS helper functions. More...

#include "tls.h"

Go to the source code of this file.

Functions

void tlsChangeState (TlsContext *context, TlsState newState)
 Update TLS state. More...
 
void tlsProcessError (TlsContext *context, error_t errorCode)
 Translate an error code to an alert message. More...
 
error_t tlsGenerateRandomValue (TlsContext *context, uint8_t *random)
 Generate client or server random value. More...
 
error_t tlsGenerateSessionId (TlsContext *context, size_t length)
 Generate a random session identifier. More...
 
error_t tlsSelectVersion (TlsContext *context, uint16_t version)
 Set the TLS version to be used. More...
 
error_t tlsSelectCipherSuite (TlsContext *context, uint16_t identifier)
 Set cipher suite. More...
 
error_t tlsSaveSessionId (const TlsContext *context, TlsSessionState *session)
 Save session ID. More...
 
error_t tlsSaveSessionTicket (const TlsContext *context, TlsSessionState *session)
 Save session ticket. More...
 
error_t tlsRestoreSessionId (TlsContext *context, const TlsSessionState *session)
 Restore a TLS session using session ID. More...
 
error_t tlsRestoreSessionTicket (TlsContext *context, const TlsSessionState *session)
 Restore a TLS session using session ticket. More...
 
error_t tlsInitEncryptionEngine (TlsContext *context, TlsEncryptionEngine *encryptionEngine, TlsConnectionEnd entity, const uint8_t *secret)
 Initialize encryption engine. More...
 
void tlsFreeEncryptionEngine (TlsEncryptionEngine *encryptionEngine)
 Release encryption engine. More...
 
error_t tlsWriteMpi (const Mpi *a, uint8_t *data, size_t *length)
 Encode a multiple precision integer to an opaque vector. More...
 
error_t tlsReadMpi (Mpi *a, const uint8_t *data, size_t size, size_t *length)
 Read a multiple precision integer from an opaque vector. More...
 
error_t tlsWriteEcPoint (const EcDomainParameters *params, const EcPoint *a, uint8_t *data, size_t *length)
 Encode an EC point to an opaque vector. More...
 
error_t tlsReadEcPoint (const EcDomainParameters *params, EcPoint *a, const uint8_t *data, size_t size, size_t *length)
 Read an EC point from an opaque vector. More...
 
const char_ttlsGetVersionName (uint16_t version)
 Convert TLS version to string representation. More...
 
const HashAlgotlsGetHashAlgo (TlsHashAlgo hashAlgoId)
 Get the hash algorithm that matches the specified identifier. More...
 
const EcCurveInfotlsGetCurveInfo (TlsContext *context, uint16_t namedCurve)
 Get the EC domain parameters that match the specified named curve. More...
 
TlsNamedGroup tlsGetNamedCurve (const uint8_t *oid, size_t length)
 Get the named curve that matches the specified OID. More...
 
size_t tlsComputeEncryptionOverhead (TlsEncryptionEngine *encryptionEngine, size_t payloadLen)
 Compute overhead caused by encryption. More...
 
bool_t tlsCheckDnsHostname (const char_t *name, size_t length)
 DNS hostname verification. More...
 

Detailed Description

TLS helper functions.

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_misc.h.

Function Documentation

◆ tlsChangeState()

void tlsChangeState ( TlsContext context,
TlsState  newState 
)

Update TLS state.

Parameters
[in]contextPointer to the TLS context
[in]newStateNew state to switch to

Definition at line 54 of file tls_misc.c.

◆ tlsCheckDnsHostname()

bool_t tlsCheckDnsHostname ( const char_t name,
size_t  length 
)

DNS hostname verification.

Parameters
[in]namePointer to the hostname
[in]lengthLength of the hostname
Returns
The function returns TRUE is the name is a valid DNS hostname

Definition at line 1585 of file tls_misc.c.

◆ tlsComputeEncryptionOverhead()

size_t tlsComputeEncryptionOverhead ( TlsEncryptionEngine encryptionEngine,
size_t  payloadLen 
)

Compute overhead caused by encryption.

Parameters
[in]encryptionEnginePointer to the encryption engine
[in]payloadLenLength of the payload, in bytes
Returns
Overhead, in bytes, caused by encryption

Definition at line 1531 of file tls_misc.c.

◆ tlsFreeEncryptionEngine()

void tlsFreeEncryptionEngine ( TlsEncryptionEngine encryptionEngine)

Release encryption engine.

Parameters
[in]encryptionEnginePointer to the encryption/decryption engine

Definition at line 917 of file tls_misc.c.

◆ tlsGenerateRandomValue()

error_t tlsGenerateRandomValue ( TlsContext context,
uint8_t *  random 
)

Generate client or server random value.

Parameters
[in]contextPointer to the TLS context
[out]randomPointer to the random value
Returns
Error code

Definition at line 207 of file tls_misc.c.

◆ tlsGenerateSessionId()

error_t tlsGenerateSessionId ( TlsContext context,
size_t  length 
)

Generate a random session identifier.

Parameters
[in]contextPointer to the TLS context
[out]lengthDesired length of the session ID
Returns
Error code

Definition at line 268 of file tls_misc.c.

◆ tlsGetCurveInfo()

const EcCurveInfo* tlsGetCurveInfo ( TlsContext context,
uint16_t  namedCurve 
)

Get the EC domain parameters that match the specified named curve.

Parameters
[in]contextPointer to the TLS context
[in]namedCurveElliptic curve identifier
Returns
Elliptic curve domain parameters

Definition at line 1240 of file tls_misc.c.

◆ tlsGetHashAlgo()

const HashAlgo* tlsGetHashAlgo ( TlsHashAlgo  hashAlgoId)

Get the hash algorithm that matches the specified identifier.

Parameters
[in]hashAlgoIdHash algorithm identifier
Returns
Pointer to the hash algorithm

Definition at line 1173 of file tls_misc.c.

◆ tlsGetNamedCurve()

TlsNamedGroup tlsGetNamedCurve ( const uint8_t *  oid,
size_t  length 
)

Get the named curve that matches the specified OID.

Parameters
[in]oidObject identifier
[in]lengthOID length
Returns
Named curve

Definition at line 1394 of file tls_misc.c.

◆ tlsGetVersionName()

const char_t* tlsGetVersionName ( uint16_t  version)

Convert TLS version to string representation.

Parameters
[in]versionVersion number
Returns
String representation

Definition at line 1112 of file tls_misc.c.

◆ tlsInitEncryptionEngine()

error_t tlsInitEncryptionEngine ( TlsContext context,
TlsEncryptionEngine encryptionEngine,
TlsConnectionEnd  entity,
const uint8_t *  secret 
)

Initialize encryption engine.

Parameters
[in]contextPointer to the TLS context
[in]encryptionEnginePointer to the encryption/decryption engine to be initialized
[in]entitySpecifies whether client or server write keys shall be used
[in]secretPointer to the secret value
Returns
Error code

Definition at line 670 of file tls_misc.c.

◆ tlsProcessError()

void tlsProcessError ( TlsContext context,
error_t  errorCode 
)

Translate an error code to an alert message.

Parameters
[in]contextPointer to the TLS context
[in]errorCodeInternal error code

Definition at line 74 of file tls_misc.c.

◆ tlsReadEcPoint()

error_t tlsReadEcPoint ( const EcDomainParameters params,
EcPoint a,
const uint8_t *  data,
size_t  size,
size_t *  length 
)

Read an EC point from an opaque vector.

Parameters
[in]paramsEC domain parameters
[out]aResulting EC point
[in]dataBuffer where to read the opaque vector
[in]sizeTotal number of bytes available in the buffer
[out]lengthTotal number of bytes that have been read
Returns
Error code

Definition at line 1066 of file tls_misc.c.

◆ tlsReadMpi()

error_t tlsReadMpi ( Mpi a,
const uint8_t *  data,
size_t  size,
size_t *  length 
)

Read a multiple precision integer from an opaque vector.

Parameters
[out]aResulting multiple precision integer
[in]dataBuffer where to read the opaque vector
[in]sizeTotal number of bytes available in the buffer
[out]lengthTotal number of bytes that have been read
Returns
Error code

Definition at line 991 of file tls_misc.c.

◆ tlsRestoreSessionId()

error_t tlsRestoreSessionId ( TlsContext context,
const TlsSessionState session 
)

Restore a TLS session using session ID.

Parameters
[in]contextPointer to the TLS context
[in]sessionPointer to the session state
Returns
Error code

Definition at line 554 of file tls_misc.c.

◆ tlsRestoreSessionTicket()

error_t tlsRestoreSessionTicket ( TlsContext context,
const TlsSessionState session 
)

Restore a TLS session using session ticket.

Parameters
[in]contextPointer to the TLS context
[in]sessionPointer to the session state
Returns
Error code

Definition at line 603 of file tls_misc.c.

◆ tlsSaveSessionId()

error_t tlsSaveSessionId ( const TlsContext context,
TlsSessionState session 
)

Save session ID.

Parameters
[in]contextPointer to the TLS context
[out]sessionPointer to the session state
Returns
Error code

Definition at line 428 of file tls_misc.c.

◆ tlsSaveSessionTicket()

error_t tlsSaveSessionTicket ( const TlsContext context,
TlsSessionState session 
)

Save session ticket.

Parameters
[in]contextPointer to the TLS context
[out]sessionPointer to the session state
Returns
Error code

Definition at line 500 of file tls_misc.c.

◆ tlsSelectCipherSuite()

error_t tlsSelectCipherSuite ( TlsContext context,
uint16_t  identifier 
)

Set cipher suite.

Parameters
[in]contextPointer to the TLS context
[in]identifierCipher suite identifier
Returns
Error code

Definition at line 333 of file tls_misc.c.

◆ tlsSelectVersion()

error_t tlsSelectVersion ( TlsContext context,
uint16_t  version 
)

Set the TLS version to be used.

Parameters
[in]contextPointer to the TLS context
[in]versionTLS version
Returns
Error code

Definition at line 305 of file tls_misc.c.

◆ tlsWriteEcPoint()

error_t tlsWriteEcPoint ( const EcDomainParameters params,
const EcPoint a,
uint8_t *  data,
size_t *  length 
)

Encode an EC point to an opaque vector.

Parameters
[in]paramsEC domain parameters
[in]aPointer to an EC point
[out]dataBuffer where to store the opaque vector
[out]lengthTotal number of bytes that have been written
Returns
Error code

Definition at line 1029 of file tls_misc.c.

◆ tlsWriteMpi()

error_t tlsWriteMpi ( const Mpi a,
uint8_t *  data,
size_t *  length 
)

Encode a multiple precision integer to an opaque vector.

Parameters
[in]aPointer to a multiple precision integer
[out]dataBuffer where to store the opaque vector
[out]lengthTotal number of bytes that have been written
Returns
Error code

Definition at line 958 of file tls_misc.c.