1 /*
2 * Copyright (C) 2000-2012 Free Software Foundation, Inc.
3 *
4 * Author: Nikos Mavrogiannopoulos
5 *
6 * This file is part of GnuTLS.
7 *
8 * The GnuTLS is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>
20 *
21 */
22
23 #ifndef GNUTLS_LIB_RECORD_H
24 #define GNUTLS_LIB_RECORD_H
25
26 #include <gnutls/gnutls.h>
27 #include <buffers.h>
28 #include <constate.h>
29
30 ssize_t _gnutls_send_tlen_int(gnutls_session_t session,
31 content_type_t type,
32 gnutls_handshake_description_t htype,
33 unsigned int epoch_rel, const void *data,
34 size_t sizeofdata, size_t min_pad,
35 unsigned int mflags);
36
37 inline static ssize_t
_gnutls_send_int(gnutls_session_t session,content_type_t type,gnutls_handshake_description_t htype,unsigned int epoch_rel,const void * _data,size_t data_size,unsigned int mflags)38 _gnutls_send_int(gnutls_session_t session, content_type_t type,
39 gnutls_handshake_description_t htype,
40 unsigned int epoch_rel, const void *_data,
41 size_t data_size, unsigned int mflags)
42 {
43 return _gnutls_send_tlen_int(session, type, htype, epoch_rel,
44 _data, data_size, 0, mflags);
45 }
46
47 ssize_t _gnutls_recv_int(gnutls_session_t session, content_type_t type,
48 uint8_t * data,
49 size_t sizeofdata, void *seq, unsigned int ms);
50
max_record_recv_size(gnutls_session_t session)51 inline static unsigned max_record_recv_size(gnutls_session_t session)
52 {
53 unsigned size;
54
55 if (session->internals.max_recv_size == 0) {
56 size = session->security_parameters.max_record_recv_size + RECORD_HEADER_SIZE(session);
57 if (session->internals.allow_large_records != 0)
58 size += EXTRA_COMP_SIZE;
59 } else {
60 size = session->internals.max_recv_size;
61 }
62
63 return size;
64 }
65
max_decrypted_size(gnutls_session_t session)66 inline static unsigned max_decrypted_size(gnutls_session_t session)
67 {
68 unsigned size = 0;
69
70 if (session->internals.allow_large_records != 0)
71 size += EXTRA_COMP_SIZE;
72
73 size += session->security_parameters.max_record_recv_size;
74
75 return size;
76 }
77
78 /* Returns the headers + any IV that the ciphersuite
79 * requires */
80 inline static
get_total_headers(gnutls_session_t session)81 unsigned int get_total_headers(gnutls_session_t session)
82 {
83 int ret;
84 record_parameters_st *params;
85 unsigned total = RECORD_HEADER_SIZE(session);
86
87 ret = _gnutls_epoch_get(session, EPOCH_WRITE_CURRENT, ¶ms);
88 if (ret < 0) {
89 return total;
90 }
91
92 return total + _gnutls_cipher_get_explicit_iv_size(params->cipher);
93 }
94
95 inline static
get_total_headers2(gnutls_session_t session,record_parameters_st * params)96 unsigned int get_total_headers2(gnutls_session_t session, record_parameters_st *params)
97 {
98 unsigned total = RECORD_HEADER_SIZE(session);
99
100 return total + _gnutls_cipher_get_explicit_iv_size(params->cipher);
101 }
102
session_invalidate(gnutls_session_t session)103 inline static void session_invalidate(gnutls_session_t session)
104 {
105 session->internals.invalid_connection = 1;
106 }
107
108 #endif /* GNUTLS_LIB_RECORD_H */
109