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_CONSTATE_H
24 #define GNUTLS_LIB_CONSTATE_H
25 
26 int _gnutls_set_cipher_suite2(gnutls_session_t session,
27 			     const gnutls_cipher_suite_entry_st *cs);
28 
29 int _gnutls_epoch_set_keys(gnutls_session_t session, uint16_t epoch, hs_stage_t stage);
30 int _gnutls_connection_state_init(gnutls_session_t session);
31 int _gnutls_read_connection_state_init(gnutls_session_t session);
32 int _gnutls_write_connection_state_init(gnutls_session_t session);
33 
34 #define _gnutls_epoch_bump(session) \
35 	(session)->security_parameters.epoch_next++
36 
37 int _gnutls_epoch_dup(gnutls_session_t session, unsigned int epoch_rel);
38 
39 int _gnutls_epoch_get(gnutls_session_t session, unsigned int epoch_rel,
40 		      record_parameters_st ** params_out);
41 int _gnutls_epoch_setup_next(gnutls_session_t session, unsigned null_epoch, record_parameters_st **newp);
42 void _gnutls_epoch_gc(gnutls_session_t session);
43 void _gnutls_epoch_free(gnutls_session_t session,
44 			record_parameters_st * state);
45 
46 void _gnutls_set_resumed_parameters(gnutls_session_t session);
47 
48 int _tls13_connection_state_init(gnutls_session_t session, hs_stage_t stage);
49 int _tls13_read_connection_state_init(gnutls_session_t session, hs_stage_t stage);
50 int _tls13_write_connection_state_init(gnutls_session_t session, hs_stage_t stage);
51 
_gnutls_epoch_is_valid(gnutls_session_t session,int epoch)52 static inline int _gnutls_epoch_is_valid(gnutls_session_t session,
53 					 int epoch)
54 {
55 	record_parameters_st *params;
56 	int ret;
57 
58 	ret = _gnutls_epoch_get(session, epoch, &params);
59 	if (ret < 0)
60 		return 0;
61 
62 	return 1;
63 }
64 
65 
_gnutls_epoch_refcount_inc(gnutls_session_t session,int epoch)66 static inline int _gnutls_epoch_refcount_inc(gnutls_session_t session,
67 					     int epoch)
68 {
69 	record_parameters_st *params;
70 	int ret;
71 
72 	ret = _gnutls_epoch_get(session, epoch, &params);
73 	if (ret < 0)
74 		return ret;
75 
76 	params->usage_cnt++;
77 
78 	return params->epoch;
79 }
80 
_gnutls_epoch_refcount_dec(gnutls_session_t session,uint16_t epoch)81 static inline int _gnutls_epoch_refcount_dec(gnutls_session_t session,
82 					     uint16_t epoch)
83 {
84 	record_parameters_st *params;
85 	int ret;
86 
87 	ret = _gnutls_epoch_get(session, epoch, &params);
88 	if (ret < 0)
89 		return ret;
90 
91 	params->usage_cnt--;
92 	if (params->usage_cnt < 0)
93 		return GNUTLS_E_INTERNAL_ERROR;
94 
95 	return 0;
96 }
97 
98 #endif /* GNUTLS_LIB_CONSTATE_H */
99