tls_misc.h
Go to the documentation of this file.
1 /**
2  * @file tls_misc.h
3  * @brief TLS helper functions
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneSSL Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 #ifndef _TLS_MISC_H
32 #define _TLS_MISC_H
33 
34 //Dependencies
35 #include "tls.h"
36 
37 //C++ guard
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 //TLS related functions
43 void tlsChangeState(TlsContext *context, TlsState newState);
45 
48 
49 error_t tlsSelectVersion(TlsContext *context, uint16_t version);
51 
52 error_t tlsSaveSessionId(const TlsContext *context,
53  TlsSessionState *session);
54 
56  TlsSessionState *session);
57 
59  const TlsSessionState *session);
60 
62  const TlsSessionState *session);
63 
65  TlsEncryptionEngine *encryptionEngine, TlsConnectionEnd entity,
66  const uint8_t *secret);
67 
68 void tlsFreeEncryptionEngine(TlsEncryptionEngine *encryptionEngine);
69 
70 error_t tlsWriteMpi(const Mpi *a, uint8_t *data, size_t *length);
71 error_t tlsReadMpi(Mpi *a, const uint8_t *data, size_t size, size_t *length);
72 
74  const EcPoint *a, uint8_t *data, size_t *length);
75 
77  EcPoint *a, const uint8_t *data, size_t size, size_t *length);
78 
79 const char_t *tlsGetVersionName(uint16_t version);
80 const HashAlgo *tlsGetHashAlgo(TlsHashAlgo hashAlgoId);
81 const EcCurveInfo *tlsGetCurveInfo(TlsContext *context, uint16_t namedCurve);
82 TlsNamedGroup tlsGetNamedCurve(const uint8_t *oid, size_t length);
83 
84 size_t tlsComputeEncryptionOverhead(TlsEncryptionEngine *encryptionEngine,
85  size_t payloadLen);
86 
88 
89 //C++ guard
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif
void tlsChangeState(TlsContext *context, TlsState newState)
Update TLS state.
Definition: tls_misc.c:54
const HashAlgo * tlsGetHashAlgo(TlsHashAlgo hashAlgoId)
Get the hash algorithm that matches the specified identifier.
Definition: tls_misc.c:1173
error_t tlsRestoreSessionId(TlsContext *context, const TlsSessionState *session)
Restore a TLS session using session ID.
Definition: tls_misc.c:554
int bool_t
Definition: compiler_port.h:53
uint8_t a
Definition: ndp.h:411
Arbitrary precision integer.
Definition: mpi.h:80
error_t tlsWriteEcPoint(const EcDomainParameters *params, const EcPoint *a, uint8_t *data, size_t *length)
Encode an EC point to an opaque vector.
Definition: tls_misc.c:1029
TlsState
TLS FSM states.
Definition: tls.h:1454
TlsConnectionEnd
TLS connection end.
Definition: tls.h:967
uint8_t data[]
Definition: ethernet.h:222
void tlsFreeEncryptionEngine(TlsEncryptionEngine *encryptionEngine)
Release encryption engine.
Definition: tls_misc.c:917
TlsHashAlgo
Hash algorithms.
Definition: tls.h:1212
char_t name[]
error_t tlsRestoreSessionTicket(TlsContext *context, const TlsSessionState *session)
Restore a TLS session using session ticket.
Definition: tls_misc.c:603
uint8_t version
Definition: coap_common.h:177
uint16_t errorCode
Definition: tftp_common.h:138
bool_t tlsCheckDnsHostname(const char_t *name, size_t length)
DNS hostname verification.
Definition: tls_misc.c:1585
EC domain parameters.
Definition: ec.h:76
error_t tlsSelectVersion(TlsContext *context, uint16_t version)
Set the TLS version to be used.
Definition: tls_misc.c:305
uint8_t oid[]
Definition: lldp_tlv.h:300
error_t tlsInitEncryptionEngine(TlsContext *context, TlsEncryptionEngine *encryptionEngine, TlsConnectionEnd entity, const uint8_t *secret)
Initialize encryption engine.
Definition: tls_misc.c:670
Elliptic curve parameters.
Definition: ec_curves.h:302
#define TlsContext
Definition: tls.h:36
error_t
Error codes.
Definition: error.h:43
error_t tlsSelectCipherSuite(TlsContext *context, uint16_t identifier)
Set cipher suite.
Definition: tls_misc.c:333
error_t tlsSaveSessionId(const TlsContext *context, TlsSessionState *session)
Save session ID.
Definition: tls_misc.c:428
const char_t * tlsGetVersionName(uint16_t version)
Convert TLS version to string representation.
Definition: tls_misc.c:1112
EC point.
Definition: ec.h:64
uint8_t length
Definition: tcp.h:368
error_t tlsWriteMpi(const Mpi *a, uint8_t *data, size_t *length)
Encode a multiple precision integer to an opaque vector.
Definition: tls_misc.c:958
uint8_t secret[TLS_MASTER_SECRET_SIZE]
Master secret.
Definition: tls.h:1884
uint8_t random[32]
Definition: tls.h:1771
char char_t
Definition: compiler_port.h:48
size_t tlsComputeEncryptionOverhead(TlsEncryptionEngine *encryptionEngine, size_t payloadLen)
Compute overhead caused by encryption.
Definition: tls_misc.c:1531
TLS session state.
Definition: tls.h:2038
error_t tlsReadMpi(Mpi *a, const uint8_t *data, size_t size, size_t *length)
Read a multiple precision integer from an opaque vector.
Definition: tls_misc.c:991
TLS (Transport Layer Security)
uint8_t identifier[]
void tlsProcessError(TlsContext *context, error_t errorCode)
Translate an error code to an alert message.
Definition: tls_misc.c:74
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.
Definition: tls_misc.c:1066
Common interface for hash algorithms.
Definition: crypto.h:1046
uint16_t payloadLen
Definition: ipv6.h:281
TlsNamedGroup
Named groups.
Definition: tls.h:1369
const EcCurveInfo * tlsGetCurveInfo(TlsContext *context, uint16_t namedCurve)
Get the EC domain parameters that match the specified named curve.
Definition: tls_misc.c:1240
error_t tlsSaveSessionTicket(const TlsContext *context, TlsSessionState *session)
Save session ticket.
Definition: tls_misc.c:500
#define TlsEncryptionEngine
Definition: tls.h:40
error_t tlsGenerateSessionId(TlsContext *context, size_t length)
Generate a random session identifier.
Definition: tls_misc.c:268
TlsNamedGroup tlsGetNamedCurve(const uint8_t *oid, size_t length)
Get the named curve that matches the specified OID.
Definition: tls_misc.c:1394
error_t tlsGenerateRandomValue(TlsContext *context, uint8_t *random)
Generate client or server random value.
Definition: tls_misc.c:207