TLS helper functions. More...
#include "tls.h"#include "tls_cipher_suites.h"#include "tls_common.h"#include "tls_ffdhe.h"#include "tls_misc.h"#include "tls13_key_material.h"#include "encoding/oid.h"#include "debug.h"Go to the source code of this file.
Macros | |
| #define | TRACE_LEVEL TLS_TRACE_LEVEL |
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... | |
| __weak_func error_t | tlsInitEncryptionEngine (TlsContext *context, TlsEncryptionEngine *encryptionEngine, TlsConnectionEnd entity, TlsEncryptionLevel level, 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 EcPublicKey *publicKey, uint8_t *data, size_t *length) |
| Encode an EC point to an opaque vector. More... | |
| error_t | tlsReadEcPoint (EcPublicKey *publicKey, const EcCurve *curve, const uint8_t *data, size_t size, size_t *length) |
| Read an EC point from an opaque vector. More... | |
| const char_t * | tlsGetVersionName (uint16_t version) |
| Convert TLS version to string representation. More... | |
| const HashAlgo * | tlsGetHashAlgo (TlsHashAlgo hashAlgoId) |
| Get the hash algorithm that matches the specified identifier. More... | |
| const EcCurve * | tlsGetCurve (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-2025 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.
- Version
- 2.5.4
Definition in file tls_misc.c.
Macro Definition Documentation
◆ TRACE_LEVEL
| #define TRACE_LEVEL TLS_TRACE_LEVEL |
Definition at line 32 of file tls_misc.c.
Function Documentation
◆ tlsChangeState()
| void tlsChangeState | ( | TlsContext * | context, |
| TlsState | newState | ||
| ) |
Update TLS state.
- Parameters
-
[in] context Pointer to the TLS context [in] newState New state to switch to
Definition at line 54 of file tls_misc.c.
◆ tlsCheckDnsHostname()
DNS hostname verification.
- Parameters
-
[in] name Pointer to the hostname [in] length Length of the hostname
- Returns
- The function returns TRUE is the name is a valid DNS hostname
Definition at line 1605 of file tls_misc.c.
◆ tlsComputeEncryptionOverhead()
| size_t tlsComputeEncryptionOverhead | ( | TlsEncryptionEngine * | encryptionEngine, |
| size_t | payloadLen | ||
| ) |
Compute overhead caused by encryption.
- Parameters
-
[in] encryptionEngine Pointer to the encryption engine [in] payloadLen Length of the payload, in bytes
- Returns
- Overhead, in bytes, caused by encryption
Definition at line 1551 of file tls_misc.c.
◆ tlsFreeEncryptionEngine()
| void tlsFreeEncryptionEngine | ( | TlsEncryptionEngine * | encryptionEngine | ) |
Release encryption engine.
- Parameters
-
[in] encryptionEngine Pointer to the encryption/decryption engine
Definition at line 928 of file tls_misc.c.
◆ tlsGenerateRandomValue()
| error_t tlsGenerateRandomValue | ( | TlsContext * | context, |
| uint8_t * | random | ||
| ) |
Generate client or server random value.
- Parameters
-
[in] context Pointer to the TLS context [out] random Pointer 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] context Pointer to the TLS context [out] length Desired length of the session ID
- Returns
- Error code
Definition at line 270 of file tls_misc.c.
◆ tlsGetCurve()
| const EcCurve* tlsGetCurve | ( | TlsContext * | context, |
| uint16_t | namedCurve | ||
| ) |
Get the EC domain parameters that match the specified named curve.
- Parameters
-
[in] context Pointer to the TLS context [in] namedCurve Elliptic curve identifier
- Returns
- Elliptic curve parameters
Definition at line 1260 of file tls_misc.c.
◆ tlsGetHashAlgo()
| const HashAlgo* tlsGetHashAlgo | ( | TlsHashAlgo | hashAlgoId | ) |
Get the hash algorithm that matches the specified identifier.
- Parameters
-
[in] hashAlgoId Hash algorithm identifier
- Returns
- Pointer to the hash algorithm
Definition at line 1193 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] oid Object identifier [in] length OID length
- Returns
- Named curve
Definition at line 1414 of file tls_misc.c.
◆ tlsGetVersionName()
| const char_t* tlsGetVersionName | ( | uint16_t | version | ) |
Convert TLS version to string representation.
- Parameters
-
[in] version Version number
- Returns
- String representation
Definition at line 1132 of file tls_misc.c.
◆ tlsInitEncryptionEngine()
| __weak_func error_t tlsInitEncryptionEngine | ( | TlsContext * | context, |
| TlsEncryptionEngine * | encryptionEngine, | ||
| TlsConnectionEnd | entity, | ||
| TlsEncryptionLevel | level, | ||
| const uint8_t * | secret | ||
| ) |
Initialize encryption engine.
- Parameters
-
[in] context Pointer to the TLS context [in] encryptionEngine Pointer to the encryption/decryption engine to be initialized [in] entity Specifies whether client or server write keys shall be used [in] level Encryption level [in] secret Pointer to the secret value
- Returns
- Error code
Definition at line 675 of file tls_misc.c.
◆ tlsProcessError()
| void tlsProcessError | ( | TlsContext * | context, |
| error_t | errorCode | ||
| ) |
Translate an error code to an alert message.
- Parameters
-
[in] context Pointer to the TLS context [in] errorCode Internal error code
Definition at line 74 of file tls_misc.c.
◆ tlsReadEcPoint()
| error_t tlsReadEcPoint | ( | EcPublicKey * | publicKey, |
| const EcCurve * | curve, | ||
| const uint8_t * | data, | ||
| size_t | size, | ||
| size_t * | length | ||
| ) |
Read an EC point from an opaque vector.
- Parameters
-
[out] publicKey Resulting EC public key [in] curve Elliptic curve parameters [in] data Buffer where to read the opaque vector [in] size Total number of bytes available in the buffer [out] length Total number of bytes that have been read
- Returns
- Error code
Definition at line 1084 of file tls_misc.c.
◆ tlsReadMpi()
Read a multiple precision integer from an opaque vector.
- Parameters
-
[out] a Resulting multiple precision integer [in] data Buffer where to read the opaque vector [in] size Total number of bytes available in the buffer [out] length Total number of bytes that have been read
- Returns
- Error code
Definition at line 1003 of file tls_misc.c.
◆ tlsRestoreSessionId()
| error_t tlsRestoreSessionId | ( | TlsContext * | context, |
| const TlsSessionState * | session | ||
| ) |
Restore a TLS session using session ID.
- Parameters
-
[in] context Pointer to the TLS context [in] session Pointer to the session state
- Returns
- Error code
Definition at line 558 of file tls_misc.c.
◆ tlsRestoreSessionTicket()
| error_t tlsRestoreSessionTicket | ( | TlsContext * | context, |
| const TlsSessionState * | session | ||
| ) |
Restore a TLS session using session ticket.
- Parameters
-
[in] context Pointer to the TLS context [in] session Pointer to the session state
- Returns
- Error code
Definition at line 607 of file tls_misc.c.
◆ tlsSaveSessionId()
| error_t tlsSaveSessionId | ( | const TlsContext * | context, |
| TlsSessionState * | session | ||
| ) |
Save session ID.
- Parameters
-
[in] context Pointer to the TLS context [out] session Pointer to the session state
- Returns
- Error code
Definition at line 432 of file tls_misc.c.
◆ tlsSaveSessionTicket()
| error_t tlsSaveSessionTicket | ( | const TlsContext * | context, |
| TlsSessionState * | session | ||
| ) |
Save session ticket.
- Parameters
-
[in] context Pointer to the TLS context [out] session Pointer to the session state
- Returns
- Error code
Definition at line 504 of file tls_misc.c.
◆ tlsSelectCipherSuite()
| error_t tlsSelectCipherSuite | ( | TlsContext * | context, |
| uint16_t | identifier | ||
| ) |
Set cipher suite.
- Parameters
-
[in] context Pointer to the TLS context [in] identifier Cipher suite identifier
- Returns
- Error code
Definition at line 335 of file tls_misc.c.
◆ tlsSelectVersion()
| error_t tlsSelectVersion | ( | TlsContext * | context, |
| uint16_t | version | ||
| ) |
Set the TLS version to be used.
- Parameters
-
[in] context Pointer to the TLS context [in] version TLS version
- Returns
- Error code
Definition at line 307 of file tls_misc.c.
◆ tlsWriteEcPoint()
| error_t tlsWriteEcPoint | ( | const EcPublicKey * | publicKey, |
| uint8_t * | data, | ||
| size_t * | length | ||
| ) |
Encode an EC point to an opaque vector.
- Parameters
-
[in] publicKey EC public key to be encoded [out] data Buffer where to store the opaque vector [out] length Total number of bytes that have been written
- Returns
- Error code
Definition at line 1045 of file tls_misc.c.
◆ tlsWriteMpi()
Encode a multiple precision integer to an opaque vector.
- Parameters
-
[in] a Pointer to a multiple precision integer [out] data Buffer where to store the opaque vector [out] length Total number of bytes that have been written
- Returns
- Error code
Definition at line 969 of file tls_misc.c.
