tls_record.h
Go to the documentation of this file.
1 /**
2  * @file tls_record.h
3  * @brief TLS record protocol
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneSSL Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _TLS_RECORD_H
30 #define _TLS_RECORD_H
31 
32 //Dependencies
33 #include "tls.h"
34 
35 //C++ guard
36 #ifdef __cplusplus
37  extern "C" {
38 #endif
39 
40 //TLS related functions
42  const uint8_t *data, size_t length, TlsContentType contentType);
43 
45  uint8_t **data, size_t *length, TlsContentType *contentType);
46 
47 error_t tlsWriteRecord(TlsContext *context, const uint8_t *data,
48  size_t length, TlsContentType contentType);
49 
50 error_t tlsReadRecord(TlsContext *context, uint8_t *data,
51  size_t size, size_t *length, TlsContentType *contentType);
52 
53 error_t tlsProcessRecord(TlsContext *context, TlsRecord *record);
54 
56  TlsEncryptionEngine *encryptionEngine, void *record);
57 
59  TlsEncryptionEngine *decryptionEngine, void *record);
60 
61 void tlsSetRecordType(TlsContext *context, void *record, uint8_t type);
62 uint8_t tlsGetRecordType(TlsContext *context, void *record);
63 void tlsSetRecordLength(TlsContext *context, void *record, size_t length);
64 size_t tlsGetRecordLength(TlsContext *context, void *record);
65 uint8_t *tlsGetRecordData(TlsContext *context, void *record);
66 
67 error_t tlsComputeMac(TlsContext *context, TlsEncryptionEngine *encryptionEngine,
68  void *record, const uint8_t *data, size_t dataLen, uint8_t *mac);
69 
70 void tlsFormatAad(TlsContext *context, TlsEncryptionEngine *encryptionEngine,
71  const void *record, uint8_t *aad, size_t *aadLen);
72 
73 void tlsFormatNonce(TlsContext *context, TlsEncryptionEngine *encryptionEngine,
74  const void *record, const uint8_t *recordIv, uint8_t *nonce, size_t *nonceLen);
75 
77 
78 //C++ guard
79 #ifdef __cplusplus
80  }
81 #endif
82 
83 #endif
TLS (Transport Layer Security)
error_t tlsDecryptRecord(TlsContext *context, TlsEncryptionEngine *decryptionEngine, void *record)
Decrypt an incoming TLS record.
Definition: tls_record.c:995
__start_packed struct @83 TlsRecord
TLS record.
error_t tlsEncryptRecord(TlsContext *context, TlsEncryptionEngine *encryptionEngine, void *record)
Encrypt an outgoing TLS record.
Definition: tls_record.c:729
error_t tlsReadProtocolData(TlsContext *context, uint8_t **data, size_t *length, TlsContentType *contentType)
Read protocol data.
Definition: tls_record.c:151
char_t type
void tlsFormatNonce(TlsContext *context, TlsEncryptionEngine *encryptionEngine, const void *record, const uint8_t *recordIv, uint8_t *nonce, size_t *nonceLen)
Format nonce.
Definition: tls_record.c:1580
void tlsSetRecordLength(TlsContext *context, void *record, size_t length)
Set TLS record length.
Definition: tls_record.c:1363
error_t tlsReadRecord(TlsContext *context, uint8_t *data, size_t size, size_t *length, TlsContentType *contentType)
Receive a TLS record.
Definition: tls_record.c:443
TlsContentType
Content type.
Definition: tls.h:910
error_t tlsComputeMac(TlsContext *context, TlsEncryptionEngine *encryptionEngine, void *record, const uint8_t *data, size_t dataLen, uint8_t *mac)
Compute message authentication code.
Definition: tls_record.c:1455
Encryption engine.
Definition: tls.h:1926
error_t tlsProcessRecord(TlsContext *context, TlsRecord *record)
Process incoming TLS record.
Definition: tls_record.c:614
size_t tlsGetRecordLength(TlsContext *context, void *record)
Get TLS record length.
Definition: tls_record.c:1389
error_t tlsWriteRecord(TlsContext *context, const uint8_t *data, size_t length, TlsContentType contentType)
Send a TLS record.
Definition: tls_record.c:338
error_t
Error codes.
Definition: error.h:40
DtlsSequenceNumber seqNum
Definition: dtls_misc.h:165
uint8_t data[]
Definition: dtls_misc.h:167
__start_packed struct @61 TlsSequenceNumber
Sequence number.
error_t tlsWriteProtocolData(TlsContext *context, const uint8_t *data, size_t length, TlsContentType contentType)
Write protocol data.
Definition: tls_record.c:58
uint8_t * tlsGetRecordData(TlsContext *context, void *record)
Get TLS record payload.
Definition: tls_record.c:1420
uint8_t length
Definition: dtls_misc.h:140
#define TlsContext
Definition: tls.h:34
uint8_t tlsGetRecordType(TlsContext *context, void *record)
Get TLS record type.
Definition: tls_record.c:1332
void tlsSetRecordType(TlsContext *context, void *record, uint8_t type)
Set TLS record type.
Definition: tls_record.c:1306
void tlsFormatAad(TlsContext *context, TlsEncryptionEngine *encryptionEngine, const void *record, uint8_t *aad, size_t *aadLen)
Format additional authenticated data (AAD)
Definition: tls_record.c:1516
void tlsIncSequenceNumber(TlsSequenceNumber *seqNum)
Increment sequence number.
Definition: tls_record.c:1647