Fix CVE-2017-6891 in minitasn1 code
[platform/upstream/gnutls.git] / lib / gnutls_handshake.h
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 <http://www.gnu.org/licenses/>
20  *
21  */
22
23 #ifndef HANDSHAKE_H
24 #define HANDSHAKE_H
25
26 #include <gnutls_errors.h>
27
28 int _gnutls_send_handshake(gnutls_session_t session, mbuffer_st * bufel,
29                            gnutls_handshake_description_t type);
30 int _gnutls_recv_hello_request(gnutls_session_t session, void *data,
31                                uint32_t data_size);
32 int _gnutls_recv_handshake(gnutls_session_t session,
33                            gnutls_handshake_description_t type,
34                            unsigned int optional, gnutls_buffer_st * buf);
35 int _gnutls_generate_session_id(uint8_t * session_id, uint8_t * len);
36 int _gnutls_set_server_random(gnutls_session_t session, uint8_t * rnd);
37 int _gnutls_set_client_random(gnutls_session_t session, uint8_t * rnd);
38
39 int _gnutls_find_pk_algos_in_ciphersuites(uint8_t * data, int datalen);
40 int _gnutls_server_select_suite(gnutls_session_t session, uint8_t * data,
41                                 unsigned int datalen);
42
43 int _gnutls_negotiate_version(gnutls_session_t session,
44                               gnutls_protocol_t adv_version);
45 int _gnutls_user_hello_func(gnutls_session_t session,
46                             gnutls_protocol_t adv_version);
47
48 void _gnutls_handshake_hash_buffers_clear(gnutls_session_t session);
49
50 #define STATE session->internals.handshake_state
51 #define FINAL_STATE session->internals.handshake_final_state
52 /* This returns true if we have got there
53  * before (and not finished due to an interrupt).
54  */
55 #define AGAIN(target) (STATE==target?1:0)
56 #define FAGAIN(target) (FINAL_STATE==target?1:0)
57 #define AGAIN2(state, target) (state==target?1:0)
58
59 inline static int handshake_remaining_time(gnutls_session_t session)
60 {
61         if (session->internals.handshake_endtime) {
62                 struct timespec now;
63                 gettime(&now);
64
65                 if (now.tv_sec < session->internals.handshake_endtime)
66                         return (session->internals.handshake_endtime -
67                                 now.tv_sec) * 1000;
68                 else
69                         return gnutls_assert_val(GNUTLS_E_TIMEDOUT);
70         }
71         return 0;
72 }
73
74 #endif