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-2019 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 1.9.6
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
44 
46 
47 error_t tlsSelectVersion(TlsContext *context, uint16_t version);
49 
51  TlsEncryptionEngine *encryptionEngine, TlsConnectionEnd entity,
52  const uint8_t *secret);
53 
54 void tlsFreeEncryptionEngine(TlsEncryptionEngine *encryptionEngine);
55 
56 error_t tlsWriteMpi(const Mpi *a, uint8_t *data, size_t *length);
57 error_t tlsReadMpi(Mpi *a, const uint8_t *data, size_t size, size_t *length);
58 
60  const EcPoint *a, uint8_t *data, size_t *length);
61 
63  EcPoint *a, const uint8_t *data, size_t size, size_t *length);
64 
65 const char_t *tlsGetVersionName(uint16_t version);
66 const HashAlgo *tlsGetHashAlgo(uint8_t hashAlgoId);
67 const EcCurveInfo *tlsGetCurveInfo(TlsContext *context, uint16_t namedCurve);
68 TlsNamedGroup tlsGetNamedCurve(const uint8_t *oid, size_t length);
69 
70 size_t tlsComputeEncryptionOverhead(TlsEncryptionEngine *encryptionEngine,
71  size_t payloadLen);
72 
74 
75 //C++ guard
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 #endif
uint8_t length
Definition: dtls_misc.h:149
int bool_t
Definition: compiler_port.h:49
uint8_t a
Definition: ndp.h:410
Arbitrary precision integer.
Definition: mpi.h:69
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:705
TlsConnectionEnd
TLS connection end.
Definition: tls.h:859
uint16_t version
Definition: dtls_misc.h:172
void tlsFreeEncryptionEngine(TlsEncryptionEngine *encryptionEngine)
Release encryption engine.
Definition: tls_misc.c:592
char_t name[]
uint16_t errorCode
Definition: tftp_common.h:136
bool_t tlsCheckDnsHostname(const char_t *name, size_t length)
DNS hostname verification.
Definition: tls_misc.c:1218
EC domain parameters.
Definition: ec.h:63
error_t tlsSelectVersion(TlsContext *context, uint16_t version)
Set the TLS version to be used.
Definition: tls_misc.c:225
error_t tlsInitEncryptionEngine(TlsContext *context, TlsEncryptionEngine *encryptionEngine, TlsConnectionEnd entity, const uint8_t *secret)
Initialize encryption engine.
Definition: tls_misc.c:354
Elliptic curve parameters.
Definition: ec_curves.h:292
const HashAlgo * tlsGetHashAlgo(uint8_t hashAlgoId)
Get the hash algorithm that matches the specified identifier.
Definition: tls_misc.c:829
#define TlsContext
Definition: tls.h:36
error_t
Error codes.
Definition: error.h:42
error_t tlsSelectCipherSuite(TlsContext *context, uint16_t identifier)
Set cipher suite.
Definition: tls_misc.c:253
uint8_t identifier[]
const char_t * tlsGetVersionName(uint16_t version)
Convert TLS version to string representation.
Definition: tls_misc.c:788
uint8_t oid[1]
Definition: mib_common.h:186
Elliptic curve point.
Definition: ec.h:51
Encryption engine.
Definition: tls.h:1942
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:634
char char_t
Definition: compiler_port.h:43
size_t tlsComputeEncryptionOverhead(TlsEncryptionEngine *encryptionEngine, size_t payloadLen)
Compute overhead caused by encryption.
Definition: tls_misc.c:1166
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:667
TLS (Transport Layer Security)
void tlsProcessError(TlsContext *context, error_t errorCode)
Translate an error code to an alert message.
Definition: tls_misc.c:56
uint8_t random[32]
Definition: tls.h:1614
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:742
Common interface for hash algorithms.
Definition: crypto.h:1128
uint8_t payloadLen
Definition: ipv6.h:343
TlsNamedGroup
Named groups.
Definition: tls.h:1205
uint8_t data[]
Definition: dtls_misc.h:176
const EcCurveInfo * tlsGetCurveInfo(TlsContext *context, uint16_t namedCurve)
Get the EC domain parameters that match the specified named curve.
Definition: tls_misc.c:890
TlsNamedGroup tlsGetNamedCurve(const uint8_t *oid, size_t length)
Get the named curve that matches the specified OID.
Definition: tls_misc.c:1036
error_t tlsGenerateRandomValue(TlsContext *context, uint8_t *random)
Generate client or server random value.
Definition: tls_misc.c:164