tls_record_encryption.c
Go to the documentation of this file.
1 /**
2  * @file tls_record_encryption.c
3  * @brief TLS record encryption
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.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL TLS_TRACE_LEVEL
33 
34 //Dependencies
35 #include "tls.h"
36 #include "tls_record.h"
37 #include "tls_record_encryption.h"
38 #include "tls_misc.h"
39 #include "cipher_modes/cbc.h"
40 #include "aead/aead_algorithms.h"
41 #include "debug.h"
42 
43 //Check TLS library configuration
44 #if (TLS_SUPPORT == ENABLED)
45 
46 
47 /**
48  * @brief Encrypt an outgoing TLS record
49  * @param[in] context Pointer to the TLS context
50  * @param[in] encryptionEngine Pointer to the encryption engine
51  * @param[in,out] record TLS record to be encrypted
52  * @return Error code
53  **/
54 
56  TlsEncryptionEngine *encryptionEngine, void *record)
57 {
58  error_t error;
59 
60 #if (TLS_CCM_CIPHER_SUPPORT == ENABLED || TLS_CCM_8_CIPHER_SUPPORT == ENABLED || \
61  TLS_GCM_CIPHER_SUPPORT == ENABLED || TLS_CHACHA20_POLY1305_SUPPORT == ENABLED)
62  //AEAD cipher?
63  if(encryptionEngine->cipherMode == CIPHER_MODE_CCM ||
64  encryptionEngine->cipherMode == CIPHER_MODE_GCM ||
65  encryptionEngine->cipherMode == CIPHER_MODE_CHACHA20_POLY1305)
66  {
67  //Perform authenticated encryption
68  error = tlsEncryptAeadRecord(context, encryptionEngine, record);
69  }
70  else
71 #endif
72 #if (TLS_CBC_CIPHER_SUPPORT == ENABLED)
73  //CBC block cipher?
74  if(encryptionEngine->cipherMode == CIPHER_MODE_CBC)
75  {
76 #if (TLS_ENCRYPT_THEN_MAC_SUPPORT == ENABLED)
77  //Encrypt-then-MAC construction?
78  if(encryptionEngine->encryptThenMac)
79  {
80  //Encrypt the contents of the record
81  error = tlsEncryptCbcRecord(context, encryptionEngine, record);
82 
83  //Check status code
84  if(!error)
85  {
86  //Compute message authentication code
87  error = tlsAppendMessageAuthCode(context, encryptionEngine, record);
88  }
89  }
90  else
91 #endif
92  //MAC-then-encrypt construction?
93  {
94  //Compute message authentication code
95  error = tlsAppendMessageAuthCode(context, encryptionEngine, record);
96 
97  //Check status code
98  if(!error)
99  {
100  //Encrypt the contents of the record
101  error = tlsEncryptCbcRecord(context, encryptionEngine, record);
102  }
103  }
104  }
105  else
106 #endif
107 #if (TLS_STREAM_CIPHER_SUPPORT == ENABLED)
108  //Stream cipher?
109  if(encryptionEngine->cipherMode == CIPHER_MODE_STREAM)
110  {
111  //Compute message authentication code
112  error = tlsAppendMessageAuthCode(context, encryptionEngine, record);
113 
114  //Check status code
115  if(!error)
116  {
117  //Encrypt the contents of the record
118  error = tlsEncryptStreamRecord(context, encryptionEngine, record);
119  }
120  }
121  else
122 #endif
123 #if (TLS_NULL_CIPHER_SUPPORT == ENABLED)
124  //NULL cipher?
125  if(encryptionEngine->cipherMode == CIPHER_MODE_NULL)
126  {
127  //Compute message authentication code
128  error = tlsAppendMessageAuthCode(context, encryptionEngine, record);
129  }
130  else
131 #endif
132  //Invalid cipher mode?
133  {
134  //The specified cipher mode is not supported
136  }
137 
138  //Return status code
139  return error;
140 }
141 
142 
143 /**
144  * @brief Record encryption (AEAD cipher)
145  * @param[in] context Pointer to the TLS context
146  * @param[in] encryptionEngine Pointer to the encryption engine
147  * @param[in,out] record TLS record to be encrypted
148  * @return Error code
149  **/
150 
152  TlsEncryptionEngine *encryptionEngine, void *record)
153 {
154 #if (TLS_CCM_CIPHER_SUPPORT == ENABLED || TLS_CCM_8_CIPHER_SUPPORT == ENABLED || \
155  TLS_GCM_CIPHER_SUPPORT == ENABLED || TLS_CHACHA20_POLY1305_SUPPORT == ENABLED)
156  error_t error;
157  size_t length;
158  size_t aadLen;
159  size_t nonceLen;
160  uint8_t *data;
161  uint8_t *tag;
162  uint8_t aad[13];
163  uint8_t nonce[12];
164 
165  //Get the length of the TLS record
166  length = tlsGetRecordLength(context, record);
167  //Point to the payload
168  data = tlsGetRecordData(context, record);
169 
170  //Debug message
171  TRACE_DEBUG("Record to be encrypted (%" PRIuSIZE " bytes):\r\n", length);
172  TRACE_DEBUG_ARRAY(" ", record, length + sizeof(TlsRecord));
173 
174  //TLS 1.3 currently selected?
175  if(encryptionEngine->version == TLS_VERSION_1_3)
176  {
177  //The type field indicates the higher-level protocol used to process the
178  //enclosed fragment
179  data[length++] = tlsGetRecordType(context, record);
180 
181  //In TLS 1.3, the outer opaque_type field of a TLS record is always set
182  //to the value 23 (application data)
184 
185  //Fix the length field of the TLS record
186  tlsSetRecordLength(context, record, length +
187  encryptionEngine->authTagLen);
188  }
189 
190  //Additional data to be authenticated
191  tlsFormatAad(context, encryptionEngine, record, aad, &aadLen);
192 
193  //Check the length of the nonce explicit part
194  if(encryptionEngine->recordIvLen != 0)
195  {
196  //Make room for the explicit nonce at the beginning of the record
197  osMemmove(data + encryptionEngine->recordIvLen, data, length);
198 
199  //The explicit part of the nonce is chosen by the sender and is
200  //carried in each TLS record
201  error = context->prngAlgo->read(context->prngContext, data,
202  encryptionEngine->recordIvLen);
203  //Any error to report?
204  if(error)
205  return error;
206  }
207 
208  //Generate the nonce
209  tlsFormatNonce(context, encryptionEngine, record, data, nonce,
210  &nonceLen);
211 
212  //Point to the plaintext
213  data += encryptionEngine->recordIvLen;
214  //Point to the buffer where to store the authentication tag
215  tag = data + length;
216 
217 #if (TLS_CCM_CIPHER_SUPPORT == ENABLED || TLS_CCM_8_CIPHER_SUPPORT == ENABLED)
218  //CCM AEAD cipher?
219  if(encryptionEngine->cipherMode == CIPHER_MODE_CCM)
220  {
221  //Authenticated encryption using CCM
222  error = ccmEncrypt(encryptionEngine->cipherAlgo,
223  encryptionEngine->cipherContext, nonce, nonceLen, aad, aadLen,
224  data, data, length, tag, encryptionEngine->authTagLen);
225  }
226  else
227 #endif
228 #if (TLS_GCM_CIPHER_SUPPORT == ENABLED)
229  //GCM AEAD cipher?
230  if(encryptionEngine->cipherMode == CIPHER_MODE_GCM)
231  {
232  //Authenticated encryption using GCM
233  error = gcmEncrypt(encryptionEngine->gcmContext, nonce, nonceLen,
234  aad, aadLen, data, data, length, tag, encryptionEngine->authTagLen);
235  }
236  else
237 #endif
238 #if (TLS_CHACHA20_POLY1305_SUPPORT == ENABLED)
239  //ChaCha20Poly1305 AEAD cipher?
240  if(encryptionEngine->cipherMode == CIPHER_MODE_CHACHA20_POLY1305)
241  {
242  //Authenticated encryption using ChaCha20Poly1305
243  error = chacha20Poly1305Encrypt(encryptionEngine->encKey,
244  encryptionEngine->encKeyLen, nonce, nonceLen, aad, aadLen,
245  data, data, length, tag, encryptionEngine->authTagLen);
246  }
247  else
248 #endif
249  //Invalid cipher mode?
250  {
251  //The specified cipher mode is not supported
253  }
254 
255  //Failed to encrypt data?
256  if(error)
257  return error;
258 
259  //Compute the length of the resulting message
260  length += encryptionEngine->recordIvLen + encryptionEngine->authTagLen;
261  //Fix length field
262  tlsSetRecordLength(context, record, length);
263 
264  //Increment sequence number
265  tlsIncSequenceNumber(&encryptionEngine->seqNum);
266 
267  //Debug message
268  TRACE_DEBUG("Encrypted record (%" PRIuSIZE " bytes):\r\n", length);
269  TRACE_DEBUG_ARRAY(" ", record, length + sizeof(TlsRecord));
270 
271  //Successful processing
272  return NO_ERROR;
273 #else
274  //AEAD ciphers are not supported
276 #endif
277 }
278 
279 
280 /**
281  * @brief Record encryption (CBC block cipher)
282  * @param[in] context Pointer to the TLS context
283  * @param[in] encryptionEngine Pointer to the encryption engine
284  * @param[in,out] record TLS record to be encrypted
285  * @return Error code
286  **/
287 
289  TlsEncryptionEngine *encryptionEngine, void *record)
290 {
291 #if (TLS_CBC_CIPHER_SUPPORT == ENABLED)
292  error_t error;
293  size_t i;
294  size_t length;
295  size_t paddingLen;
296  uint8_t *data;
297  const CipherAlgo *cipherAlgo;
298 
299  //Point to the cipher algorithm
300  cipherAlgo = encryptionEngine->cipherAlgo;
301 
302  //Get the length of the TLS record
303  length = tlsGetRecordLength(context, record);
304  //Point to the payload
305  data = tlsGetRecordData(context, record);
306 
307  //Debug message
308  TRACE_DEBUG("Record to be encrypted (%" PRIuSIZE " bytes):\r\n", length);
309  TRACE_DEBUG_ARRAY(" ", record, length + sizeof(TlsRecord));
310 
311 #if (TLS_MAX_VERSION >= TLS_VERSION_1_1 && TLS_MIN_VERSION <= TLS_VERSION_1_2)
312  //TLS 1.1 and 1.2 use an explicit IV
313  if(encryptionEngine->version >= TLS_VERSION_1_1)
314  {
315  //Make room for the IV at the beginning of the data
316  osMemmove(data + encryptionEngine->recordIvLen, data, length);
317 
318  //The initialization vector should be chosen at random
319  error = context->prngAlgo->read(context->prngContext, data,
320  encryptionEngine->recordIvLen);
321  //Any error to report?
322  if(error)
323  return error;
324 
325  //Adjust the length of the message
326  length += encryptionEngine->recordIvLen;
327  }
328 #endif
329 
330  //Get the actual amount of bytes in the last block
331  paddingLen = (length + 1) % cipherAlgo->blockSize;
332 
333  //Padding is added to force the length of the plaintext to be an integral
334  //multiple of the cipher's block length
335  if(paddingLen > 0)
336  {
337  paddingLen = cipherAlgo->blockSize - paddingLen;
338  }
339 
340  //Write padding bytes
341  for(i = 0; i <= paddingLen; i++)
342  {
343  data[length + i] = (uint8_t) paddingLen;
344  }
345 
346  //Compute the length of the resulting message
347  length += paddingLen + 1;
348  //Fix length field
349  tlsSetRecordLength(context, record, length);
350 
351  //Debug message
352  TRACE_DEBUG("Record with padding (%" PRIuSIZE " bytes):\r\n", length);
353  TRACE_DEBUG_ARRAY(" ", record, length + sizeof(TlsRecord));
354 
355  //CBC encryption
356  error = cbcEncrypt(cipherAlgo, encryptionEngine->cipherContext,
357  encryptionEngine->iv, data, data, length);
358  //Any error to report?
359  if(error)
360  return error;
361 
362  //Debug message
363  TRACE_DEBUG("Encrypted record (%" PRIuSIZE " bytes):\r\n", length);
364  TRACE_DEBUG_ARRAY(" ", record, length + sizeof(TlsRecord));
365 
366  //Successful processing
367  return NO_ERROR;
368 #else
369  //CBC cipher mode is not supported
371 #endif
372 }
373 
374 
375 /**
376  * @brief Record encryption (stream cipher)
377  * @param[in] context Pointer to the TLS context
378  * @param[in] encryptionEngine Pointer to the encryption engine
379  * @param[in,out] record TLS record to be encrypted
380  * @return Error code
381  **/
382 
384  TlsEncryptionEngine *encryptionEngine, void *record)
385 {
386 #if (TLS_STREAM_CIPHER_SUPPORT == ENABLED)
387  size_t length;
388  uint8_t *data;
389 
390  //Get the length of the TLS record
391  length = tlsGetRecordLength(context, record);
392  //Point to the payload
393  data = tlsGetRecordData(context, record);
394 
395  //Debug message
396  TRACE_DEBUG("Record to be encrypted (%" PRIuSIZE " bytes):\r\n", length);
397  TRACE_DEBUG_ARRAY(" ", record, length + sizeof(TlsRecord));
398 
399  //Encrypt record contents
400  encryptionEngine->cipherAlgo->encryptStream(
401  encryptionEngine->cipherContext, data, data, length);
402 
403  //Debug message
404  TRACE_DEBUG("Encrypted record (%" PRIuSIZE " bytes):\r\n", length);
405  TRACE_DEBUG_ARRAY(" ", record, length + sizeof(TlsRecord));
406 
407  //Successful processing
408  return NO_ERROR;
409 #else
410  //Stream ciphers are not supported
412 #endif
413 }
414 
415 
416 /**
417  * @brief Append message authentication code
418  * @param[in] context Pointer to the TLS context
419  * @param[in] encryptionEngine Pointer to the encryption engine
420  * @param[in,out] record TLS record to be authenticated
421  * @return Error code
422  **/
423 
425  TlsEncryptionEngine *encryptionEngine, void *record)
426 {
427  error_t error;
428  size_t length;
429  uint8_t *data;
430 
431  //Get the length of the TLS record
432  length = tlsGetRecordLength(context, record);
433  //Point to the payload
434  data = tlsGetRecordData(context, record);
435 
436 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_2)
437  //TLS 1.0, TLS 1.1 or TLS 1.2 currently selected?
438  if(encryptionEngine->version >= TLS_VERSION_1_0 &&
439  encryptionEngine->version <= TLS_VERSION_1_2)
440  {
441  //TLS uses a HMAC construction
442  error = tlsComputeMac(context, encryptionEngine, record, data,
443  length, data + length);
444  }
445  else
446 #endif
447 #if (TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
448  //TLS 1.3 currently selected?
449  if(encryptionEngine->version == TLS_VERSION_1_3)
450  {
451  //The type field indicates the higher-level protocol used to process the
452  //enclosed fragment
453  data[length++] = tlsGetRecordType(context, record);
454 
455  //In TLS 1.3, the outer opaque_type field of a TLS record is always set
456  //to the value 23 (application data)
458 
459  //Fix the length field of the TLS record
460  tlsSetRecordLength(context, record, length +
461  encryptionEngine->hashAlgo->digestSize);
462 
463  //The record is protected using HMAC SHA-256 or SHA-384
464  error = tls13ComputeMac(context, encryptionEngine, record, data,
465  length, data + length);
466  }
467  else
468 #endif
469  //Invalid TLS version?
470  {
471  //Report an error
472  error = ERROR_INVALID_VERSION;
473  }
474 
475  //Any error to report?
476  if(error)
477  return error;
478 
479  //Debug message
480  TRACE_DEBUG("Write sequence number:\r\n");
481  TRACE_DEBUG_ARRAY(" ", &encryptionEngine->seqNum, sizeof(TlsSequenceNumber));
482  TRACE_DEBUG("Computed MAC:\r\n");
483  TRACE_DEBUG_ARRAY(" ", data + length, encryptionEngine->hashAlgo->digestSize);
484 
485  //Adjust the length of the message
486  length += encryptionEngine->hashAlgo->digestSize;
487  //Fix length field
488  tlsSetRecordLength(context, record, length);
489 
490  //Increment sequence number
491  tlsIncSequenceNumber(&encryptionEngine->seqNum);
492 
493  //Successful processing
494  return NO_ERROR;
495 }
496 
497 
498 /**
499  * @brief Compute message authentication code
500  * @param[in] context Pointer to the TLS context
501  * @param[in] encryptionEngine Pointer to the encryption/decryption engine
502  * @param[in] record Pointer to the TLS record
503  * @param[in] data Pointer to the record data
504  * @param[in] dataLen Length of the data
505  * @param[out] mac The computed MAC value
506  * @return Error code
507  **/
508 
509 __weak_func error_t tlsComputeMac(TlsContext *context,
510  TlsEncryptionEngine *encryptionEngine, const void *record,
511  const uint8_t *data, size_t dataLen, uint8_t *mac)
512 {
513  HmacContext *hmacContext;
514 
515  //Point to the HMAC context
516  hmacContext = encryptionEngine->hmacContext;
517 
518  //Initialize HMAC calculation
519  hmacInit(hmacContext, encryptionEngine->hashAlgo,
520  encryptionEngine->macKey, encryptionEngine->macKeyLen);
521 
522 #if (DTLS_SUPPORT == ENABLED)
523  //DTLS protocol?
524  if(context->transportProtocol == TLS_TRANSPORT_PROTOCOL_DATAGRAM)
525  {
526  const DtlsRecord *dtlsRecord;
527 
528  //Point to the DTLS record
529  dtlsRecord = (DtlsRecord *) record;
530 
531  //Compute the MAC over the 64-bit value formed by concatenating the
532  //epoch and the sequence number in the order they appear on the wire
533  hmacUpdate(hmacContext, (void *) &dtlsRecord->epoch, 2);
534  hmacUpdate(hmacContext, &dtlsRecord->seqNum, 6);
535 
536  //Compute MAC over the record contents
537  hmacUpdate(hmacContext, &dtlsRecord->type, 3);
538  hmacUpdate(hmacContext, (void *) &dtlsRecord->length, 2);
539  hmacUpdate(hmacContext, data, dataLen);
540  }
541  else
542 #endif
543  //TLS protocol?
544  {
545  const TlsRecord *tlsRecord;
546 
547  //Point to the TLS record
548  tlsRecord = (TlsRecord *) record;
549 
550  //Compute MAC over the implicit sequence number
551  hmacUpdate(hmacContext, &encryptionEngine->seqNum,
552  sizeof(TlsSequenceNumber));
553 
554  //Compute MAC over the record contents
555  hmacUpdate(hmacContext, tlsRecord, sizeof(TlsRecord));
556  hmacUpdate(hmacContext, data, dataLen);
557  }
558 
559  //Finalize HMAC computation
560  hmacFinal(hmacContext, mac);
561 
562  //Successful processing
563  return NO_ERROR;
564 }
565 
566 #endif
__weak_func error_t cbcEncrypt(const CipherAlgo *cipher, void *context, uint8_t *iv, const uint8_t *p, uint8_t *c, size_t length)
CBC encryption.
Definition: cbc.c:61
Cipher Block Chaining (CBC) mode.
__weak_func error_t ccmEncrypt(const CipherAlgo *cipher, void *context, const uint8_t *n, size_t nLen, const uint8_t *a, size_t aLen, const uint8_t *p, uint8_t *c, size_t length, uint8_t *t, size_t tLen)
Authenticated encryption using CCM.
Definition: ccm.c:67
error_t chacha20Poly1305Encrypt(const uint8_t *k, size_t kLen, const uint8_t *n, size_t nLen, const uint8_t *a, size_t aLen, const uint8_t *p, uint8_t *c, size_t length, uint8_t *t, size_t tLen)
Authenticated encryption using ChaCha20Poly1305.
#define PRIuSIZE
@ CIPHER_MODE_CHACHA20_POLY1305
Definition: crypto.h:951
@ CIPHER_MODE_CCM
Definition: crypto.h:949
@ CIPHER_MODE_CBC
Definition: crypto.h:945
@ CIPHER_MODE_STREAM
Definition: crypto.h:943
@ CIPHER_MODE_GCM
Definition: crypto.h:950
@ CIPHER_MODE_NULL
Definition: crypto.h:942
Debugging facilities.
#define TRACE_DEBUG_ARRAY(p, a, n)
Definition: debug.h:108
#define TRACE_DEBUG(...)
Definition: debug.h:107
DtlsRecord
Definition: dtls_misc.h:180
error_t
Error codes.
Definition: error.h:43
@ NO_ERROR
Success.
Definition: error.h:44
@ ERROR_UNSUPPORTED_CIPHER_MODE
Definition: error.h:128
@ ERROR_INVALID_VERSION
Definition: error.h:118
uint8_t data[]
Definition: ethernet.h:222
__weak_func error_t gcmEncrypt(GcmContext *context, const uint8_t *iv, size_t ivLen, const uint8_t *a, size_t aLen, const uint8_t *p, uint8_t *c, size_t length, uint8_t *t, size_t tLen)
Authenticated encryption using GCM.
Definition: gcm.c:214
__weak_func error_t hmacInit(HmacContext *context, const HashAlgo *hash, const void *key, size_t keyLen)
Initialize HMAC calculation.
Definition: hmac.c:140
__weak_func void hmacFinal(HmacContext *context, uint8_t *digest)
Finish the HMAC calculation.
Definition: hmac.c:218
__weak_func void hmacUpdate(HmacContext *context, const void *data, size_t length)
Update the HMAC context with a portion of the message being hashed.
Definition: hmac.c:201
#define osMemmove(dest, src, length)
Definition: os_port.h:147
uint32_t dataLen
Definition: sftp_common.h:229
Common interface for encryption algorithms.
Definition: crypto.h:1036
size_t blockSize
Definition: crypto.h:1040
HMAC algorithm context.
Definition: hmac.h:59
uint8_t length
Definition: tcp.h:368
error_t tls13ComputeMac(TlsContext *context, TlsEncryptionEngine *encryptionEngine, void *record, const uint8_t *data, size_t dataLen, uint8_t *mac)
Compute message authentication code.
Definition: tls13_misc.c:451
TLS (Transport Layer Security)
@ TLS_TRANSPORT_PROTOCOL_DATAGRAM
Definition: tls.h:942
@ TLS_TYPE_APPLICATION_DATA
Definition: tls.h:1012
#define TLS_VERSION_1_1
Definition: tls.h:95
#define TLS_VERSION_1_3
Definition: tls.h:97
#define TlsContext
Definition: tls.h:36
TlsSequenceNumber
Definition: tls.h:1489
#define TLS_VERSION_1_0
Definition: tls.h:94
#define TlsEncryptionEngine
Definition: tls.h:40
TlsRecord
Definition: tls.h:1725
#define TLS_VERSION_1_2
Definition: tls.h:96
TLS helper functions.
void tlsSetRecordType(TlsContext *context, void *record, uint8_t type)
Set TLS record type.
Definition: tls_record.c:758
uint8_t tlsGetRecordType(TlsContext *context, void *record)
Get TLS record type.
Definition: tls_record.c:784
void tlsIncSequenceNumber(TlsSequenceNumber *seqNum)
Increment sequence number.
Definition: tls_record.c:1030
uint8_t * tlsGetRecordData(TlsContext *context, void *record)
Get TLS record payload.
Definition: tls_record.c:872
void tlsSetRecordLength(TlsContext *context, void *record, size_t length)
Set TLS record length.
Definition: tls_record.c:815
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:963
size_t tlsGetRecordLength(TlsContext *context, void *record)
Get TLS record length.
Definition: tls_record.c:841
void tlsFormatAad(TlsContext *context, TlsEncryptionEngine *encryptionEngine, const void *record, uint8_t *aad, size_t *aadLen)
Format additional authenticated data (AAD)
Definition: tls_record.c:905
TLS record protocol.
__weak_func error_t tlsEncryptCbcRecord(TlsContext *context, TlsEncryptionEngine *encryptionEngine, void *record)
Record encryption (CBC block cipher)
error_t tlsEncryptRecord(TlsContext *context, TlsEncryptionEngine *encryptionEngine, void *record)
Encrypt an outgoing TLS record.
error_t tlsEncryptStreamRecord(TlsContext *context, TlsEncryptionEngine *encryptionEngine, void *record)
Record encryption (stream cipher)
__weak_func error_t tlsComputeMac(TlsContext *context, TlsEncryptionEngine *encryptionEngine, const void *record, const uint8_t *data, size_t dataLen, uint8_t *mac)
Compute message authentication code.
__weak_func error_t tlsEncryptAeadRecord(TlsContext *context, TlsEncryptionEngine *encryptionEngine, void *record)
Record encryption (AEAD cipher)
error_t tlsAppendMessageAuthCode(TlsContext *context, TlsEncryptionEngine *encryptionEngine, void *record)
Append message authentication code.
TLS record encryption.