1*de0e0e4dSAntonio Huete Jimenez /* $OpenBSD: tls13_record.h,v 1.5 2021/10/23 13:12:14 jsing Exp $ */
2cca6fc52SDaniel Fojt /*
3cca6fc52SDaniel Fojt  * Copyright (c) 2019 Joel Sing <jsing@openbsd.org>
4cca6fc52SDaniel Fojt  *
5cca6fc52SDaniel Fojt  * Permission to use, copy, modify, and distribute this software for any
6cca6fc52SDaniel Fojt  * purpose with or without fee is hereby granted, provided that the above
7cca6fc52SDaniel Fojt  * copyright notice and this permission notice appear in all copies.
8cca6fc52SDaniel Fojt  *
9cca6fc52SDaniel Fojt  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10cca6fc52SDaniel Fojt  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11cca6fc52SDaniel Fojt  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12cca6fc52SDaniel Fojt  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13cca6fc52SDaniel Fojt  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14cca6fc52SDaniel Fojt  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15cca6fc52SDaniel Fojt  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16cca6fc52SDaniel Fojt  */
17cca6fc52SDaniel Fojt 
18cca6fc52SDaniel Fojt #ifndef HEADER_TLS13_RECORD_H
19cca6fc52SDaniel Fojt #define HEADER_TLS13_RECORD_H
20cca6fc52SDaniel Fojt 
21cca6fc52SDaniel Fojt #include "bytestring.h"
22cca6fc52SDaniel Fojt 
23cca6fc52SDaniel Fojt __BEGIN_HIDDEN_DECLS
24cca6fc52SDaniel Fojt 
25cca6fc52SDaniel Fojt /*
26cca6fc52SDaniel Fojt  * TLSv1.3 Record Protocol - RFC 8446 section 5.
27cca6fc52SDaniel Fojt  *
28cca6fc52SDaniel Fojt  * The maximum plaintext is 2^14, however for inner plaintext an additional
29cca6fc52SDaniel Fojt  * byte is allowed for the content type. A maximum AEAD overhead of 255-bytes
30cca6fc52SDaniel Fojt  * is permitted, along with a 5-byte header, giving a maximum size of
31cca6fc52SDaniel Fojt  * 5 + 2^14 + 1 + 255 = 16,645-bytes.
32cca6fc52SDaniel Fojt  */
33cca6fc52SDaniel Fojt #define TLS13_RECORD_HEADER_LEN			5
34cca6fc52SDaniel Fojt #define TLS13_RECORD_MAX_AEAD_OVERHEAD		255
35cca6fc52SDaniel Fojt #define TLS13_RECORD_MAX_PLAINTEXT_LEN		16384
36cca6fc52SDaniel Fojt #define TLS13_RECORD_MAX_INNER_PLAINTEXT_LEN \
37cca6fc52SDaniel Fojt 	(TLS13_RECORD_MAX_PLAINTEXT_LEN + 1)
38cca6fc52SDaniel Fojt #define TLS13_RECORD_MAX_CIPHERTEXT_LEN \
39cca6fc52SDaniel Fojt 	(TLS13_RECORD_MAX_INNER_PLAINTEXT_LEN + TLS13_RECORD_MAX_AEAD_OVERHEAD)
40cca6fc52SDaniel Fojt #define TLS13_RECORD_MAX_LEN \
41cca6fc52SDaniel Fojt 	(TLS13_RECORD_HEADER_LEN + TLS13_RECORD_MAX_CIPHERTEXT_LEN)
42cca6fc52SDaniel Fojt 
43cca6fc52SDaniel Fojt /*
44cca6fc52SDaniel Fojt  * TLSv1.3 Per-Record Nonces and Sequence Numbers - RFC 8446 section 5.3.
45cca6fc52SDaniel Fojt  */
46cca6fc52SDaniel Fojt #define TLS13_RECORD_SEQ_NUM_LEN 8
47cca6fc52SDaniel Fojt 
48cca6fc52SDaniel Fojt struct tls13_record;
49cca6fc52SDaniel Fojt 
50cca6fc52SDaniel Fojt struct tls13_record *tls13_record_new(void);
51cca6fc52SDaniel Fojt void tls13_record_free(struct tls13_record *_rec);
52cca6fc52SDaniel Fojt uint16_t tls13_record_version(struct tls13_record *_rec);
53cca6fc52SDaniel Fojt uint8_t tls13_record_content_type(struct tls13_record *_rec);
54cca6fc52SDaniel Fojt int tls13_record_header(struct tls13_record *_rec, CBS *_cbs);
55cca6fc52SDaniel Fojt int tls13_record_content(struct tls13_record *_rec, CBS *_cbs);
56cca6fc52SDaniel Fojt void tls13_record_data(struct tls13_record *_rec, CBS *_cbs);
57cca6fc52SDaniel Fojt int tls13_record_set_data(struct tls13_record *_rec, uint8_t *_data,
58cca6fc52SDaniel Fojt     size_t _data_len);
59*de0e0e4dSAntonio Huete Jimenez ssize_t tls13_record_recv(struct tls13_record *_rec, tls_read_cb _wire_read,
60cca6fc52SDaniel Fojt     void *_wire_arg);
61*de0e0e4dSAntonio Huete Jimenez ssize_t tls13_record_send(struct tls13_record *_rec, tls_write_cb _wire_write,
62cca6fc52SDaniel Fojt     void *_wire_arg);
63cca6fc52SDaniel Fojt 
64cca6fc52SDaniel Fojt __END_HIDDEN_DECLS
65cca6fc52SDaniel Fojt 
66cca6fc52SDaniel Fojt #endif
67