Blame lib/gnutls_int.h

Packit Service 4684c1
/*
Packit Service 4684c1
 * Copyright (C) 2000-2016 Free Software Foundation, Inc.
Packit Service 4684c1
 * Copyright (C) 2015-2018 Red Hat, Inc.
Packit Service 4684c1
 *
Packit Service 4684c1
 * Author: Nikos Mavrogiannopoulos
Packit Service 4684c1
 *
Packit Service 4684c1
 * This file is part of GnuTLS.
Packit Service 4684c1
 *
Packit Service 4684c1
 * The GnuTLS is free software; you can redistribute it and/or
Packit Service 4684c1
 * modify it under the terms of the GNU Lesser General Public License
Packit Service 4684c1
 * as published by the Free Software Foundation; either version 2.1 of
Packit Service 4684c1
 * the License, or (at your option) any later version.
Packit Service 4684c1
 *
Packit Service 4684c1
 * This library is distributed in the hope that it will be useful, but
Packit Service 4684c1
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 4684c1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 4684c1
 * Lesser General Public License for more details.
Packit Service 4684c1
 *
Packit Service 4684c1
 * You should have received a copy of the GNU Lesser General Public License
Packit Service 4684c1
 * along with this program.  If not, see <https://www.gnu.org/licenses/>
Packit Service 4684c1
 *
Packit Service 4684c1
 */
Packit Service 4684c1
Packit Service 4684c1
#ifndef GNUTLS_LIB_GNUTLS_INT_H
Packit Service 4684c1
#define GNUTLS_LIB_GNUTLS_INT_H
Packit Service 4684c1
Packit Service 4684c1
#ifdef HAVE_CONFIG_H
Packit Service 4684c1
#include <config.h>
Packit Service 4684c1
#endif
Packit Service 4684c1
Packit Service 4684c1
#include <stddef.h>
Packit Service 4684c1
#include <string.h>
Packit Service 4684c1
#include <stdlib.h>
Packit Service 4684c1
#include <stdio.h>
Packit Service 4684c1
#include <ctype.h>
Packit Service 4684c1
#include <limits.h>
Packit Service 4684c1
#include <stdint.h>
Packit Service 4684c1
#include <stdbool.h>
Packit Service 4684c1
#include <assert.h>
Packit Service 4684c1
Packit Service 4684c1
#ifdef NO_SSIZE_T
Packit Service 4684c1
#define HAVE_SSIZE_T
Packit Service 4684c1
typedef int ssize_t;
Packit Service 4684c1
#endif
Packit Service 4684c1
Packit Service 4684c1
#include <sys/types.h>
Packit Service 4684c1
#include <unistd.h>
Packit Service 4684c1
#include <sys/stat.h>
Packit Service 4684c1
#if HAVE_SYS_SOCKET_H
Packit Service 4684c1
#include <sys/socket.h>
Packit Service 4684c1
#elif HAVE_WS2TCPIP_H
Packit Service 4684c1
#include <ws2tcpip.h>
Packit Service 4684c1
#endif
Packit Service 4684c1
#include <time.h>
Packit Service 4684c1
Packit Service 4684c1
#include <nettle/memxor.h>
Packit Service 4684c1
Packit Service 4684c1
#include "attribute.h"
Packit Service 4684c1
Packit Service 4684c1
#define ENABLE_ALIGN16
Packit Service 4684c1
Packit Service 4684c1
#ifdef __clang_major
Packit Service 4684c1
# define _GNUTLS_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
Packit Service 4684c1
#else
Packit Service 4684c1
# define _GNUTLS_CLANG_VERSION 0
Packit Service 4684c1
#endif
Packit Service 4684c1
Packit Service 4684c1
/* clang also defines __GNUC__. It promotes a GCC version of 4.2.1. */
Packit Service 4684c1
#ifdef __GNUC__
Packit Service 4684c1
# define _GNUTLS_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
Packit Service 4684c1
#endif
Packit Service 4684c1
Packit Service 4684c1
#if _GNUTLS_GCC_VERSION >= 30100
Packit Service 4684c1
# define likely(x)      __builtin_expect((x), 1)
Packit Service 4684c1
# define unlikely(x)    __builtin_expect((x), 0)
Packit Service 4684c1
#else
Packit Service 4684c1
# define likely
Packit Service 4684c1
# define unlikely
Packit Service 4684c1
#endif
Packit Service 4684c1
Packit Service 4684c1
#include <gnutls/gnutls.h>
Packit Service 4684c1
#include <gnutls/dtls.h>
Packit Service 4684c1
#include <gnutls/abstract.h>
Packit Service 4684c1
#include <gnutls/socket.h>
Packit Service 4684c1
#include <system.h>
Packit Service 4684c1
Packit Service 4684c1
/* in case we compile with system headers taking priority, we
Packit Service 4684c1
 * make sure that some new attributes are still available.
Packit Service 4684c1
 */
Packit Service 4684c1
#ifndef __GNUTLS_CONST__
Packit Service 4684c1
# define __GNUTLS_CONST__
Packit Service 4684c1
#endif
Packit Service 4684c1
Packit Service 4684c1
/* The size of a handshake message should not
Packit Service 4684c1
 * be larger than this value.
Packit Service 4684c1
 */
Packit Service 4684c1
#define MAX_HANDSHAKE_PACKET_SIZE 128*1024
Packit Service 4684c1
Packit Service 4684c1
#define GNUTLS_DEF_SESSION_ID_SIZE 32
Packit Service 4684c1
Packit Service 4684c1
/* The maximum digest size of hash algorithms.
Packit Service 4684c1
 */
Packit Service 4684c1
#define MAX_FILENAME 512
Packit Service 4684c1
#define MAX_HASH_SIZE 64
Packit Service 4684c1
Packit Service 4684c1
#define MAX_MAC_KEY_SIZE 64
Packit Service 4684c1
Packit Service 4684c1
#define MAX_CIPHER_BLOCK_SIZE 64 /* CHACHA20 */
Packit Service 4684c1
#define MAX_CIPHER_KEY_SIZE 32
Packit Service 4684c1
Packit Service 4684c1
#define MAX_CIPHER_IV_SIZE 16
Packit Service 4684c1
Packit Service 4684c1
#define MAX_USERNAME_SIZE 128
Packit Service 4684c1
#define MAX_SERVER_NAME_SIZE 256
Packit Service 4684c1
Packit Service 4684c1
#define AEAD_EXPLICIT_DATA_SIZE 8
Packit Service 4684c1
#define AEAD_IMPLICIT_DATA_SIZE 4
Packit Service 4684c1
Packit Service 4684c1
#define GNUTLS_MASTER_SIZE 48
Packit Service 4684c1
#define GNUTLS_RANDOM_SIZE 32
Packit Service 4684c1
Packit Service 4684c1
/* Under TLS1.3 a hello retry request is sent as server hello */
Packit Service 4684c1
#define REAL_HSK_TYPE(t) ((t)==GNUTLS_HANDSHAKE_HELLO_RETRY_REQUEST?GNUTLS_HANDSHAKE_SERVER_HELLO:t)
Packit Service 4684c1
Packit Service 4684c1
/* DTLS */
Packit Service 4684c1
#define DTLS_RETRANS_TIMEOUT 1000
Packit Service 4684c1
Packit Service 4684c1
/* TLS Extensions */
Packit Service 4684c1
/* we can receive up to MAX_EXT_TYPES extensions.
Packit Service 4684c1
 */
Packit Service 4684c1
#define MAX_EXT_TYPES 64
Packit Service 4684c1
Packit Service 4684c1
/* TLS-internal extension (will be parsed after a ciphersuite is selected).
Packit Service 4684c1
 * This amends the gnutls_ext_parse_type_t. Not exported yet to allow more refining
Packit Service 4684c1
 * prior to finalizing an API. */
Packit Service 4684c1
#define _GNUTLS_EXT_TLS_POST_CS 177
Packit Service 4684c1
Packit Service 4684c1
/* expire time for resuming sessions */
Packit Service 4684c1
#define DEFAULT_EXPIRE_TIME 21600
Packit Service 4684c1
#define STEK_ROTATION_PERIOD_PRODUCT 3
Packit Service 4684c1
#define DEFAULT_HANDSHAKE_TIMEOUT_MS 40*1000
Packit Service 4684c1
Packit Service 4684c1
/* The EC group to be used when the extension
Packit Service 4684c1
 * supported groups/curves is not present */
Packit Service 4684c1
#define DEFAULT_EC_GROUP GNUTLS_GROUP_SECP256R1
Packit Service 4684c1
Packit Service 4684c1
typedef enum transport_t {
Packit Service 4684c1
	GNUTLS_STREAM,
Packit Service 4684c1
	GNUTLS_DGRAM
Packit Service 4684c1
} transport_t;
Packit Service 4684c1
Packit Service 4684c1
/* The TLS 1.3 stage of handshake */
Packit Service 4684c1
typedef enum hs_stage_t {
Packit Service 4684c1
	STAGE_HS,
Packit Service 4684c1
	STAGE_APP,
Packit Service 4684c1
	STAGE_UPD_OURS,
Packit Service 4684c1
	STAGE_UPD_PEERS,
Packit Service 4684c1
	STAGE_EARLY
Packit Service 4684c1
} hs_stage_t;
Packit Service 4684c1
Packit Service 4684c1
typedef enum record_send_state_t {
Packit Service 4684c1
	RECORD_SEND_NORMAL = 0,
Packit Service 4684c1
	RECORD_SEND_CORKED, /* corked and transition to NORMAL afterwards */
Packit Service 4684c1
	RECORD_SEND_CORKED_TO_KU, /* corked but must transition to RECORD_SEND_KEY_UPDATE_1 */
Packit Service 4684c1
	RECORD_SEND_KEY_UPDATE_1,
Packit Service 4684c1
	RECORD_SEND_KEY_UPDATE_2,
Packit Service 4684c1
	RECORD_SEND_KEY_UPDATE_3
Packit Service 4684c1
} record_send_state_t;
Packit Service 4684c1
Packit Service 4684c1
/* The mode check occurs a lot throughout GnuTLS and can be replaced by
Packit Service 4684c1
 * the following shorter macro. Also easier to update one macro
Packit Service 4684c1
 * in the future when the internal structure changes than all the conditionals
Packit Service 4684c1
 * itself.
Packit Service 4684c1
 */
Packit Service 4684c1
#define IS_SERVER(session) (session->security_parameters.entity == GNUTLS_SERVER)
Packit Service 4684c1
Packit Service 4684c1
/* To check whether we have a DTLS session */
Packit Service 4684c1
#define IS_DTLS(session) (session->internals.transport == GNUTLS_DGRAM)
Packit Service 4684c1
Packit Service 4684c1
/* the maximum size of encrypted packets */
Packit Service 4684c1
#define DEFAULT_MAX_RECORD_SIZE 16384
Packit Service 4684c1
#define DEFAULT_MAX_EARLY_DATA_SIZE 16384
Packit Service 4684c1
#define TLS_RECORD_HEADER_SIZE 5
Packit Service 4684c1
#define DTLS_RECORD_HEADER_SIZE (TLS_RECORD_HEADER_SIZE+8)
Packit Service 4684c1
#define RECORD_HEADER_SIZE(session) (IS_DTLS(session) ? DTLS_RECORD_HEADER_SIZE : TLS_RECORD_HEADER_SIZE)
Packit Service 4684c1
#define MAX_RECORD_HEADER_SIZE DTLS_RECORD_HEADER_SIZE
Packit Service 4684c1
Packit Service 4684c1
#define MIN_RECORD_SIZE 512
Packit Service 4684c1
#define MIN_RECORD_SIZE_SMALL 64
Packit Service 4684c1
Packit Service 4684c1
/* The following macro is used to calculate the overhead when sending.
Packit Service 4684c1
 * when receiving we use a different way as there are implementations that
Packit Service 4684c1
 * store more data than allowed.
Packit Service 4684c1
 */
Packit Service 4684c1
#define MAX_RECORD_SEND_OVERHEAD(session) (MAX_CIPHER_BLOCK_SIZE/*iv*/+MAX_PAD_SIZE+MAX_HASH_SIZE/*MAC*/)
Packit Service 4684c1
#define MAX_RECORD_SEND_SIZE(session) (IS_DTLS(session)? \
Packit Service 4684c1
	(MIN((size_t)gnutls_dtls_get_mtu(session), (size_t)session->security_parameters.max_record_send_size+MAX_RECORD_SEND_OVERHEAD(session))): \
Packit Service 4684c1
	((size_t)session->security_parameters.max_record_send_size+MAX_RECORD_SEND_OVERHEAD(session)))
Packit Service 4684c1
#define MAX_PAD_SIZE 255
Packit Service 4684c1
#define EXTRA_COMP_SIZE 2048
Packit Service 4684c1
Packit Service 4684c1
#define TLS_HANDSHAKE_HEADER_SIZE 4
Packit Service 4684c1
#define DTLS_HANDSHAKE_HEADER_SIZE (TLS_HANDSHAKE_HEADER_SIZE+8)
Packit Service 4684c1
#define HANDSHAKE_HEADER_SIZE(session) (IS_DTLS(session) ? DTLS_HANDSHAKE_HEADER_SIZE : TLS_HANDSHAKE_HEADER_SIZE)
Packit Service 4684c1
#define MAX_HANDSHAKE_HEADER_SIZE DTLS_HANDSHAKE_HEADER_SIZE
Packit Service 4684c1
Packit Service 4684c1
/* Maximum seed size for provable parameters */
Packit Service 4684c1
#define MAX_PVP_SEED_SIZE 256
Packit Service 4684c1
Packit Service 4684c1
/* This is the maximum handshake message size we send without
Packit Service 4684c1
   fragmentation. This currently ignores record layer overhead. */
Packit Service 4684c1
#define DTLS_DEFAULT_MTU 1200
Packit Service 4684c1
Packit Service 4684c1
/* the maximum size of the DTLS cookie */
Packit Service 4684c1
#define DTLS_MAX_COOKIE_SIZE 32
Packit Service 4684c1
Packit Service 4684c1
/* The maximum number of HELLO_VERIFY_REQUEST messages the client
Packit Service 4684c1
   processes before aborting. */
Packit Service 4684c1
#define MAX_HANDSHAKE_HELLO_VERIFY_REQUESTS 5
Packit Service 4684c1
Packit Service 4684c1
#define MAX_PK_PARAM_SIZE 2048
Packit Service 4684c1
Packit Service 4684c1
/* defaults for verification functions
Packit Service 4684c1
 */
Packit Service 4684c1
#define DEFAULT_MAX_VERIFY_DEPTH 16
Packit Service 4684c1
#define DEFAULT_MAX_VERIFY_BITS (MAX_PK_PARAM_SIZE*8)
Packit Service 4684c1
#define MAX_VERIFY_DEPTH 4096
Packit Service 4684c1
Packit Service 4684c1
#include <mem.h>
Packit Service 4684c1
Packit Service 4684c1
#define MEMSUB(x,y) ((ssize_t)((ptrdiff_t)x-(ptrdiff_t)y))
Packit Service 4684c1
Packit Service 4684c1
#define DECR_LEN(len, x) DECR_LENGTH_RET(len, x, GNUTLS_E_UNEXPECTED_PACKET_LENGTH)
Packit Service 4684c1
#define DECR_LEN_FINAL(len, x) do { \
Packit Service 4684c1
	if (len != x) \
Packit Service 4684c1
		return gnutls_assert_val(GNUTLS_E_UNEXPECTED_PACKET_LENGTH); \
Packit Service 4684c1
	else \
Packit Service 4684c1
		len = 0; \
Packit Service 4684c1
	} while (0)
Packit Service 4684c1
#define DECR_LENGTH_RET(len, x, RET) DECR_LENGTH_COM(len, x, return RET)
Packit Service 4684c1
#define DECR_LENGTH_COM(len, x, COM) do { if (len
Packit Service 4684c1
Packit Service 4684c1
#define GNUTLS_POINTER_TO_INT(_) ((int) GNUTLS_POINTER_TO_INT_CAST (_))
Packit Service 4684c1
#define GNUTLS_INT_TO_POINTER(_) ((void*) GNUTLS_POINTER_TO_INT_CAST (_))
Packit Service 4684c1
Packit Service 4684c1
#define GNUTLS_KX_INVALID (-1)
Packit Service 4684c1
Packit Service 4684c1
#include <mpi.h>
Packit Service 4684c1
Packit Service 4684c1
typedef enum handshake_state_t { STATE0 = 0, STATE1, STATE2,
Packit Service 4684c1
	STATE3, STATE4, STATE5, STATE6, STATE7, STATE8,
Packit Service 4684c1
	STATE9, STATE10, STATE11, STATE12, STATE13, STATE14,
Packit Service 4684c1
	STATE15, STATE16, STATE17, STATE18, STATE19,
Packit Service 4684c1
	STATE20 = 20, STATE21, STATE22,
Packit Service 4684c1
	STATE30 = 30, STATE31, STATE40 = 40, STATE41, STATE50 = 50,
Packit Service 4684c1
	STATE90=90, STATE91, STATE92, STATE93, STATE94, STATE99=99,
Packit Service 4684c1
	STATE100=100, STATE101, STATE102, STATE103, STATE104,
Packit Service 4684c1
	STATE105, STATE106, STATE107, STATE108, STATE109, STATE110,
Packit Service 4684c1
	STATE111, STATE112, STATE113, STATE114, STATE115,
Packit Service 4684c1
	STATE150 /* key update */
Packit Service 4684c1
} handshake_state_t;
Packit Service 4684c1
Packit Service 4684c1
typedef enum bye_state_t {
Packit Service 4684c1
	BYE_STATE0 = 0, BYE_STATE1, BYE_STATE2
Packit Service 4684c1
} bye_state_t;
Packit Service 4684c1
Packit Service 4684c1
typedef enum send_ticket_state_t {
Packit Service 4684c1
	TICKET_STATE0 = 0, TICKET_STATE1
Packit Service 4684c1
} send_ticket_state_t;
Packit Service 4684c1
Packit Service 4684c1
typedef enum reauth_state_t {
Packit Service 4684c1
	REAUTH_STATE0 = 0, REAUTH_STATE1, REAUTH_STATE2, REAUTH_STATE3,
Packit Service 4684c1
	REAUTH_STATE4, REAUTH_STATE5
Packit Service 4684c1
} reauth_state_t;
Packit Service 4684c1
Packit Service 4684c1
#define TICKET_STATE session->internals.ticket_state
Packit Service 4684c1
#define BYE_STATE session->internals.bye_state
Packit Service 4684c1
#define REAUTH_STATE session->internals.reauth_state
Packit Service 4684c1
Packit Service 4684c1
typedef enum heartbeat_state_t {
Packit Service 4684c1
	SHB_SEND1 = 0,
Packit Service 4684c1
	SHB_SEND2,
Packit Service 4684c1
	SHB_RECV
Packit Service 4684c1
} heartbeat_state_t;
Packit Service 4684c1
Packit Service 4684c1
typedef enum recv_state_t {
Packit Service 4684c1
	RECV_STATE_0 = 0,
Packit Service 4684c1
	RECV_STATE_DTLS_RETRANSMIT,
Packit Service 4684c1
	/* client-side false start state */
Packit Service 4684c1
	RECV_STATE_FALSE_START_HANDLING, /* we are calling gnutls_handshake() within record_recv() */
Packit Service 4684c1
	RECV_STATE_FALSE_START, /* gnutls_record_recv() should complete the handshake */
Packit Service 4684c1
	/* async handshake msg state */
Packit Service 4684c1
	RECV_STATE_ASYNC_HANDSHAKE, /* an incomplete async handshake message was seen */
Packit Service 4684c1
	/* server-side early start under TLS1.3; enabled when no client cert is received */
Packit Service 4684c1
	RECV_STATE_EARLY_START_HANDLING, /* we are calling gnutls_handshake() within record_recv() */
Packit Service 4684c1
	RECV_STATE_EARLY_START, /* gnutls_record_recv() should complete the handshake */
Packit Service 4684c1
	RECV_STATE_REHANDSHAKE, /* gnutls_record_recv() should complete any incoming re-handshake requests */
Packit Service 4684c1
	RECV_STATE_REAUTH /* gnutls_record_recv() should complete any incoming reauthentication requests */
Packit Service 4684c1
} recv_state_t;
Packit Service 4684c1
Packit Service 4684c1
#include "str.h"
Packit Service 4684c1
Packit Service 4684c1
/* This is the maximum number of algorithms (ciphers or macs etc).
Packit Service 4684c1
 * keep it synced with GNUTLS_MAX_ALGORITHM_NUM in gnutls.h
Packit Service 4684c1
 */
Packit Service 4684c1
#define MAX_ALGOS GNUTLS_MAX_ALGORITHM_NUM
Packit Service 4684c1
Packit Service 4684c1
/* IDs are allocated in a way that all values fit in 64-bit integer as (1<
Packit Service 4684c1
typedef enum extensions_t {
Packit Service 4684c1
	GNUTLS_EXTENSION_INVALID = 0xffff,
Packit Service 4684c1
	GNUTLS_EXTENSION_STATUS_REQUEST = 0,
Packit Service 4684c1
	GNUTLS_EXTENSION_CERT_TYPE,
Packit Service 4684c1
	GNUTLS_EXTENSION_CLIENT_CERT_TYPE,
Packit Service 4684c1
	GNUTLS_EXTENSION_SERVER_CERT_TYPE,
Packit Service 4684c1
	GNUTLS_EXTENSION_SUPPORTED_GROUPS,
Packit Service 4684c1
	GNUTLS_EXTENSION_SUPPORTED_EC_POINT_FORMATS,
Packit Service 4684c1
	GNUTLS_EXTENSION_SRP,
Packit Service 4684c1
	GNUTLS_EXTENSION_SIGNATURE_ALGORITHMS,
Packit Service 4684c1
	GNUTLS_EXTENSION_SRTP,
Packit Service 4684c1
	GNUTLS_EXTENSION_HEARTBEAT,
Packit Service 4684c1
	GNUTLS_EXTENSION_ALPN,
Packit Service 4684c1
	GNUTLS_EXTENSION_ETM,
Packit Service 4684c1
	GNUTLS_EXTENSION_EXT_MASTER_SECRET,
Packit Service 4684c1
	GNUTLS_EXTENSION_SESSION_TICKET,
Packit Service 4684c1
	GNUTLS_EXTENSION_KEY_SHARE,
Packit Service 4684c1
	GNUTLS_EXTENSION_SUPPORTED_VERSIONS,
Packit Service 4684c1
	GNUTLS_EXTENSION_POST_HANDSHAKE,
Packit Service 4684c1
	GNUTLS_EXTENSION_SAFE_RENEGOTIATION,
Packit Service 4684c1
	GNUTLS_EXTENSION_SERVER_NAME,
Packit Service 4684c1
	GNUTLS_EXTENSION_COOKIE,
Packit Service 4684c1
	GNUTLS_EXTENSION_EARLY_DATA,
Packit Service 4684c1
	GNUTLS_EXTENSION_PSK_KE_MODES,
Packit Service 4684c1
	GNUTLS_EXTENSION_RECORD_SIZE_LIMIT,
Packit Service 4684c1
	GNUTLS_EXTENSION_MAX_RECORD_SIZE,
Packit Service 4684c1
	/*
Packit Service 4684c1
	 * pre_shared_key and dumbfw must always be the last extensions,
Packit Service 4684c1
	 * in that order */
Packit Service 4684c1
	GNUTLS_EXTENSION_DUMBFW,
Packit Service 4684c1
	GNUTLS_EXTENSION_PRE_SHARED_KEY,
Packit Service 4684c1
	GNUTLS_EXTENSION_MAX /* not real extension - used for iterators */
Packit Service 4684c1
} extensions_t;
Packit Service 4684c1
Packit Service 4684c1
#define GNUTLS_EXTENSION_MAX_VALUE 63
Packit Service 4684c1
#define ext_track_t uint64_t
Packit Service 4684c1
Packit Service 4684c1
#include <verify.h>
Packit Service 4684c1
Packit Service 4684c1
verify(GNUTLS_EXTENSION_MAX < GNUTLS_EXTENSION_MAX_VALUE);
Packit Service 4684c1
verify(GNUTLS_EXTENSION_MAX < MAX_EXT_TYPES);
Packit Service 4684c1
Packit Service 4684c1
/* we must provide at least 16 extensions for users to register;
Packit Service 4684c1
 * increase GNUTLS_EXTENSION_MAX_VALUE, MAX_EXT_TYPES and used_exts
Packit Service 4684c1
 * type if this fails
Packit Service 4684c1
 */
Packit Service 4684c1
verify(GNUTLS_EXTENSION_MAX_VALUE - GNUTLS_EXTENSION_MAX >= 16);
Packit Service 4684c1
Packit Service 4684c1
/* The 'verify' symbol from <verify.h> is used extensively in the
Packit Service 4684c1
 * code; undef it to avoid clash
Packit Service 4684c1
 */
Packit Service 4684c1
#undef verify
Packit Service 4684c1
Packit Service 4684c1
typedef enum { CIPHER_STREAM, CIPHER_BLOCK, CIPHER_AEAD } cipher_type_t;
Packit Service 4684c1
Packit Service 4684c1
#define RESUME_TRUE 1
Packit Service 4684c1
#define RESUME_FALSE 0
Packit Service 4684c1
Packit Service 4684c1
/* Record Protocol */
Packit Service 4684c1
typedef enum content_type_t {
Packit Service 4684c1
	GNUTLS_CHANGE_CIPHER_SPEC = 20, GNUTLS_ALERT,
Packit Service 4684c1
	GNUTLS_HANDSHAKE, GNUTLS_APPLICATION_DATA,
Packit Service 4684c1
	GNUTLS_HEARTBEAT
Packit Service 4684c1
} content_type_t;
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
#define GNUTLS_PK_ANY (gnutls_pk_algorithm_t)-1
Packit Service 4684c1
#define GNUTLS_PK_NONE (gnutls_pk_algorithm_t)-2
Packit Service 4684c1
Packit Service 4684c1
#define GNUTLS_PK_IS_RSA(pk) ((pk) == GNUTLS_PK_RSA || (pk) == GNUTLS_PK_RSA_PSS)
Packit Service 4684c1
Packit Service 4684c1
/* Message buffers (mbuffers) structures */
Packit Service 4684c1
Packit Service 4684c1
/* this is actually the maximum number of distinct handshake
Packit Service 4684c1
 * messages that can arrive in a single flight
Packit Service 4684c1
 */
Packit Service 4684c1
#define MAX_HANDSHAKE_MSGS 6
Packit Service 4684c1
typedef struct {
Packit Service 4684c1
	/* Handshake layer type and sequence of message */
Packit Service 4684c1
	gnutls_handshake_description_t htype;
Packit Service 4684c1
Packit Service 4684c1
	/* The "real" type received; that is, it does not distinguish
Packit Service 4684c1
	 * HRR from server hello, while htype does */
Packit Service 4684c1
	gnutls_handshake_description_t rtype;
Packit Service 4684c1
	uint32_t length;
Packit Service 4684c1
Packit Service 4684c1
	/* valid in DTLS */
Packit Service 4684c1
	uint16_t sequence;
Packit Service 4684c1
Packit Service 4684c1
	/* indicate whether that message is complete.
Packit Service 4684c1
	 * complete means start_offset == 0 and end_offset == length
Packit Service 4684c1
	 */
Packit Service 4684c1
	uint32_t start_offset;
Packit Service 4684c1
	uint32_t end_offset;
Packit Service 4684c1
Packit Service 4684c1
	uint8_t header[MAX_HANDSHAKE_HEADER_SIZE];
Packit Service 4684c1
	int header_size;
Packit Service 4684c1
Packit Service 4684c1
	gnutls_buffer_st data;
Packit Service 4684c1
} handshake_buffer_st;
Packit Service 4684c1
Packit Service 4684c1
typedef struct mbuffer_st {
Packit Service 4684c1
	/* when used in mbuffer_head_st */
Packit Service 4684c1
	struct mbuffer_st *next;
Packit Service 4684c1
	struct mbuffer_st *prev;
Packit Service 4684c1
Packit Service 4684c1
	/* msg->size - mark = number of bytes left to process in this
Packit Service 4684c1
	   message. Mark should only be non-zero when this buffer is the
Packit Service 4684c1
	   head of the queue. */
Packit Service 4684c1
	size_t mark;
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
	/* the data */
Packit Service 4684c1
	gnutls_datum_t msg;
Packit Service 4684c1
	size_t maximum_size;
Packit Service 4684c1
Packit Service 4684c1
	/* used during fill in, to separate header from data
Packit Service 4684c1
	 * body. */
Packit Service 4684c1
	unsigned int uhead_mark;
Packit Service 4684c1
Packit Service 4684c1
	/* Filled in by record layer on recv:
Packit Service 4684c1
	 * type, record_sequence
Packit Service 4684c1
	 */
Packit Service 4684c1
Packit Service 4684c1
	/* record layer content type */
Packit Service 4684c1
	content_type_t type;
Packit Service 4684c1
Packit Service 4684c1
	/* record layer sequence */
Packit Service 4684c1
	uint64_t record_sequence;
Packit Service 4684c1
Packit Service 4684c1
	/* Filled in by handshake layer on send:
Packit Service 4684c1
	 * type, epoch, htype, handshake_sequence
Packit Service 4684c1
	 */
Packit Service 4684c1
Packit Service 4684c1
	/* Record layer epoch of message */
Packit Service 4684c1
	uint16_t epoch;
Packit Service 4684c1
Packit Service 4684c1
	/* Handshake layer type and sequence of message */
Packit Service 4684c1
	gnutls_handshake_description_t htype;
Packit Service 4684c1
	uint16_t handshake_sequence;
Packit Service 4684c1
} mbuffer_st;
Packit Service 4684c1
Packit Service 4684c1
typedef struct mbuffer_head_st {
Packit Service 4684c1
	mbuffer_st *head;
Packit Service 4684c1
	mbuffer_st *tail;
Packit Service 4684c1
Packit Service 4684c1
	unsigned int length;
Packit Service 4684c1
	size_t byte_length;
Packit Service 4684c1
} mbuffer_head_st;
Packit Service 4684c1
Packit Service 4684c1
/* Store & Retrieve functions defines:
Packit Service 4684c1
 */
Packit Service 4684c1
Packit Service 4684c1
typedef struct auth_cred_st {
Packit Service 4684c1
	gnutls_credentials_type_t algorithm;
Packit Service 4684c1
Packit Service 4684c1
	/* the type of credentials depends on algorithm
Packit Service 4684c1
	 */
Packit Service 4684c1
	void *credentials;
Packit Service 4684c1
	struct auth_cred_st *next;
Packit Service 4684c1
} auth_cred_st;
Packit Service 4684c1
Packit Service 4684c1
/* session ticket definitions */
Packit Service 4684c1
#define TICKET_MASTER_KEY_SIZE (TICKET_KEY_NAME_SIZE+TICKET_CIPHER_KEY_SIZE+TICKET_MAC_SECRET_SIZE)
Packit Service 4684c1
#define TICKET_KEY_NAME_SIZE 16
Packit Service 4684c1
#define TICKET_CIPHER_KEY_SIZE 32
Packit Service 4684c1
#define TICKET_MAC_SECRET_SIZE 16
Packit Service 4684c1
Packit Service 4684c1
/* These are restricted by TICKET_CIPHER_KEY_SIZE and TICKET_MAC_SECRET_SIZE */
Packit Service 4684c1
#define TICKET_CIPHER GNUTLS_CIPHER_AES_256_CBC
Packit Service 4684c1
#define TICKET_IV_SIZE 16
Packit Service 4684c1
#define TICKET_BLOCK_SIZE 16
Packit Service 4684c1
Packit Service 4684c1
#define TICKET_MAC_ALGO GNUTLS_MAC_SHA1
Packit Service 4684c1
#define TICKET_MAC_SIZE 20 /* HMAC-SHA1 */
Packit Service 4684c1
Packit Service 4684c1
struct ticket_st {
Packit Service 4684c1
	uint8_t key_name[TICKET_KEY_NAME_SIZE];
Packit Service 4684c1
	uint8_t IV[TICKET_IV_SIZE];
Packit Service 4684c1
	uint8_t *encrypted_state;
Packit Service 4684c1
	uint16_t encrypted_state_len;
Packit Service 4684c1
	uint8_t mac[TICKET_MAC_SIZE];
Packit Service 4684c1
};
Packit Service 4684c1
Packit Service 4684c1
struct binder_data_st {
Packit Service 4684c1
	const struct mac_entry_st *prf; /* non-null if this struct is set */
Packit Service 4684c1
	gnutls_datum_t psk;
Packit Service 4684c1
Packit Service 4684c1
	/* 0-based index of the selected PSK.
Packit Service 4684c1
	 * This only applies if the HSK_PSK_SELECTED flag is set in internals.hsk_flags,
Packit Service 4684c1
	 * which signals a PSK has indeed been selected. */
Packit Service 4684c1
	uint8_t idx;
Packit Service 4684c1
	uint8_t resumption; /* whether it is a resumption binder */
Packit Service 4684c1
};
Packit Service 4684c1
Packit Service 4684c1
typedef void (* gnutls_stek_rotation_callback_t) (const gnutls_datum_t *prev_key,
Packit Service 4684c1
						const gnutls_datum_t *new_key,
Packit Service 4684c1
						uint64_t t);
Packit Service 4684c1
Packit Service 4684c1
struct gnutls_key_st {
Packit Service 4684c1
	struct { /* These are kept outside the TLS1.3 union as they are
Packit Service 4684c1
	          * negotiated via extension, even before protocol is negotiated */
Packit Service 4684c1
		gnutls_pk_params_st ecdh_params;
Packit Service 4684c1
		gnutls_pk_params_st ecdhx_params;
Packit Service 4684c1
		gnutls_pk_params_st dh_params;
Packit Service 4684c1
	} kshare;
Packit Service 4684c1
Packit Service 4684c1
	/* The union contents depend on the negotiated protocol.
Packit Service 4684c1
	 * It should not contain any values which are allocated
Packit Service 4684c1
	 * prior to protocol negotiation, as it would be impossible
Packit Service 4684c1
	 * to deinitialize.
Packit Service 4684c1
	 */
Packit Service 4684c1
	union {
Packit Service 4684c1
		struct {
Packit Service 4684c1
			/* the current (depending on state) secret, can be
Packit Service 4684c1
			 * early_secret, client_early_traffic_secret, ... */
Packit Service 4684c1
			uint8_t temp_secret[MAX_HASH_SIZE];
Packit Service 4684c1
			unsigned temp_secret_size; /* depends on negotiated PRF size */
Packit Service 4684c1
			uint8_t e_ckey[MAX_HASH_SIZE]; /* client_early_traffic_secret */
Packit Service 4684c1
			uint8_t hs_ckey[MAX_HASH_SIZE]; /* client_hs_traffic_secret */
Packit Service 4684c1
			uint8_t hs_skey[MAX_HASH_SIZE]; /* server_hs_traffic_secret */
Packit Service 4684c1
			uint8_t ap_ckey[MAX_HASH_SIZE]; /* client_ap_traffic_secret */
Packit Service 4684c1
			uint8_t ap_skey[MAX_HASH_SIZE]; /* server_ap_traffic_secret */
Packit Service 4684c1
			uint8_t ap_expkey[MAX_HASH_SIZE]; /* {early_,}exporter_master_secret */
Packit Service 4684c1
			uint8_t ap_rms[MAX_HASH_SIZE]; /* resumption_master_secret */
Packit Service 4684c1
		} tls13; /* tls1.3 */
Packit Service 4684c1
Packit Service 4684c1
		/* Folow the SSL3.0 and TLS1.2 key exchanges */
Packit Service 4684c1
		struct {
Packit Service 4684c1
			/* For ECDH KX */
Packit Service 4684c1
			struct {
Packit Service 4684c1
				gnutls_pk_params_st params; /* private part */
Packit Service 4684c1
				/* public part */
Packit Service 4684c1
				bigint_t x;
Packit Service 4684c1
				bigint_t y;
Packit Service 4684c1
				gnutls_datum_t raw; /* public key used in ECDHX (point) */
Packit Service 4684c1
			} ecdh;
Packit Service 4684c1
Packit Service 4684c1
			/* For DH KX */
Packit Service 4684c1
			struct {
Packit Service 4684c1
				gnutls_pk_params_st params;
Packit Service 4684c1
				bigint_t client_Y;
Packit Service 4684c1
			} dh;
Packit Service 4684c1
Packit Service 4684c1
			/* for SRP KX */
Packit Service 4684c1
			struct {
Packit Service 4684c1
				bigint_t srp_key;
Packit Service 4684c1
				bigint_t srp_g;
Packit Service 4684c1
				bigint_t srp_p;
Packit Service 4684c1
				bigint_t A;
Packit Service 4684c1
				bigint_t B;
Packit Service 4684c1
				bigint_t u;
Packit Service 4684c1
				bigint_t b;
Packit Service 4684c1
				bigint_t a;
Packit Service 4684c1
				bigint_t x;
Packit Service 4684c1
			} srp;
Packit Service 4684c1
		} tls12; /* from ssl3.0 to tls12 */
Packit Service 4684c1
	} proto;
Packit Service 4684c1
Packit Service 4684c1
	/* binders / pre-shared keys in use; temporary storage.
Packit Service 4684c1
	 * On client side it will hold data for the resumption and external
Packit Service 4684c1
	 * PSKs After server hello is received the selected binder is set on 0 position
Packit Service 4684c1
	 * and HSK_PSK_SELECTED is set.
Packit Service 4684c1
	 *
Packit Service 4684c1
	 * On server side the first value is populated with
Packit Service 4684c1
	 * the selected PSK data if HSK_PSK_SELECTED flag is set. */
Packit Service 4684c1
	struct binder_data_st binders[2];
Packit Service 4684c1
Packit Service 4684c1
	/* TLS pre-master key; applies to 1.2 and 1.3 */
Packit Service 4684c1
	gnutls_datum_t key;
Packit Service 4684c1
Packit Service 4684c1
	uint8_t
Packit Service 4684c1
		/* The key to encrypt and decrypt session tickets */
Packit Service 4684c1
		session_ticket_key[TICKET_MASTER_KEY_SIZE],
Packit Service 4684c1
		/* Static buffer for the previous key, whenever we need it */
Packit Service 4684c1
		previous_ticket_key[TICKET_MASTER_KEY_SIZE],
Packit Service 4684c1
		/* Initial key supplied by the caller */
Packit Service 4684c1
		initial_stek[TICKET_MASTER_KEY_SIZE];
Packit Service 4684c1
Packit Service 4684c1
	/* this is used to hold the peers authentication data
Packit Service 4684c1
	 */
Packit Service 4684c1
	/* auth_info_t structures SHOULD NOT contain malloced
Packit Service 4684c1
	 * elements. Check gnutls_session_pack.c, and gnutls_auth.c.
Packit Service 4684c1
	 * Remember that this should be calloced!
Packit Service 4684c1
	 */
Packit Service 4684c1
	void *auth_info;
Packit Service 4684c1
	gnutls_credentials_type_t auth_info_type;
Packit Service 4684c1
	int auth_info_size;	/* needed in order to store to db for restoring
Packit Service 4684c1
				 */
Packit Service 4684c1
	auth_cred_st *cred;	/* used to specify keys/certificates etc */
Packit Service 4684c1
Packit Service 4684c1
	struct {
Packit Service 4684c1
		uint64_t last_result;
Packit Service 4684c1
		uint8_t was_rotated;
Packit Service 4684c1
		gnutls_stek_rotation_callback_t cb;
Packit Service 4684c1
	} totp;
Packit Service 4684c1
};
Packit Service 4684c1
Packit Service 4684c1
typedef struct gnutls_key_st gnutls_key_st;
Packit Service 4684c1
Packit Service 4684c1
struct pin_info_st {
Packit Service 4684c1
	gnutls_pin_callback_t cb;
Packit Service 4684c1
	void *data;
Packit Service 4684c1
};
Packit Service 4684c1
Packit Service 4684c1
struct record_state_st;
Packit Service 4684c1
typedef struct record_state_st record_state_st;
Packit Service 4684c1
Packit Service 4684c1
struct record_parameters_st;
Packit Service 4684c1
typedef struct record_parameters_st record_parameters_st;
Packit Service 4684c1
Packit Service 4684c1
#define GNUTLS_CIPHER_FLAG_ONLY_AEAD	(1 << 0) /* When set, this cipher is only available through the new AEAD API */
Packit Service 4684c1
#define GNUTLS_CIPHER_FLAG_XOR_NONCE	(1 << 1) /* In this TLS AEAD cipher xor the implicit_iv with the nonce */
Packit Service 4684c1
#define GNUTLS_CIPHER_FLAG_NO_REKEY	(1 << 2) /* whether this tls1.3 cipher doesn't need to rekey after 2^24 messages */
Packit Service 4684c1
Packit Service 4684c1
/* cipher and mac parameters */
Packit Service 4684c1
typedef struct cipher_entry_st {
Packit Service 4684c1
	const char *name;
Packit Service 4684c1
	gnutls_cipher_algorithm_t id;
Packit Service 4684c1
	uint16_t blocksize;
Packit Service 4684c1
	uint16_t keysize;
Packit Service 4684c1
	cipher_type_t type;
Packit Service 4684c1
	uint16_t implicit_iv;	/* the size of implicit IV - the IV generated but not sent */
Packit Service 4684c1
	uint16_t explicit_iv;	/* the size of explicit IV - the IV stored in record */
Packit Service 4684c1
	uint16_t cipher_iv;	/* the size of IV needed by the cipher */
Packit Service 4684c1
	uint16_t tagsize;
Packit Service 4684c1
	unsigned flags;
Packit Service 4684c1
} cipher_entry_st;
Packit Service 4684c1
Packit Service 4684c1
typedef struct gnutls_cipher_suite_entry_st {
Packit Service 4684c1
	const char *name;
Packit Service 4684c1
	const uint8_t id[2];
Packit Service 4684c1
	gnutls_cipher_algorithm_t block_algorithm;
Packit Service 4684c1
	gnutls_kx_algorithm_t kx_algorithm;
Packit Service 4684c1
	gnutls_mac_algorithm_t mac_algorithm;
Packit Service 4684c1
	gnutls_protocol_t min_version;	/* this cipher suite is supported
Packit Service 4684c1
					 * from 'version' and above;
Packit Service 4684c1
					 */
Packit Service 4684c1
	gnutls_protocol_t max_version;	/* this cipher suite is not supported
Packit Service 4684c1
					 * after 'version' and above;
Packit Service 4684c1
					 */
Packit Service 4684c1
	gnutls_protocol_t min_dtls_version;	/* DTLS min version */
Packit Service 4684c1
	gnutls_protocol_t max_dtls_version;	/* DTLS max version */
Packit Service 4684c1
	gnutls_mac_algorithm_t prf;
Packit Service 4684c1
} gnutls_cipher_suite_entry_st;
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
typedef struct gnutls_group_entry_st {
Packit Service 4684c1
	const char *name;
Packit Service 4684c1
	gnutls_group_t id;
Packit Service 4684c1
	const gnutls_datum_t *prime;
Packit Service 4684c1
	const gnutls_datum_t *q;
Packit Service 4684c1
	const gnutls_datum_t *generator;
Packit Service 4684c1
	const unsigned *q_bits;
Packit Service 4684c1
	gnutls_ecc_curve_t curve;
Packit Service 4684c1
	gnutls_pk_algorithm_t pk;
Packit Service 4684c1
	unsigned tls_id;		/* The RFC4492 namedCurve ID or TLS 1.3 group ID */
Packit Service 4684c1
} gnutls_group_entry_st;
Packit Service 4684c1
Packit Service 4684c1
#define GNUTLS_MAC_FLAG_PREIMAGE_INSECURE	1  /* if this algorithm should not be trusted for pre-image attacks */
Packit Service 4684c1
#define GNUTLS_MAC_FLAG_CONTINUOUS_MAC		(1 << 1) /* if this MAC should be used in a 'continuous' way in TLS */
Packit Service 4684c1
/* This structure is used both for MACs and digests
Packit Service 4684c1
 */
Packit Service 4684c1
typedef struct mac_entry_st {
Packit Service 4684c1
	const char *name;
Packit Service 4684c1
	const char *oid;	/* OID of the hash - if it is a hash */
Packit Service 4684c1
	const char *mac_oid;    /* OID of the MAC algorithm - if it is a MAC */
Packit Service 4684c1
	gnutls_mac_algorithm_t id;
Packit Service 4684c1
	unsigned output_size;
Packit Service 4684c1
	unsigned key_size;
Packit Service 4684c1
	unsigned nonce_size;
Packit Service 4684c1
	unsigned placeholder;	/* if set, then not a real MAC */
Packit Service 4684c1
	unsigned block_size;	/* internal block size for HMAC */
Packit Service 4684c1
	unsigned flags;
Packit Service 4684c1
} mac_entry_st;
Packit Service 4684c1
Packit Service 4684c1
typedef struct {
Packit Service 4684c1
	const char *name;
Packit Service 4684c1
	gnutls_protocol_t id;	/* gnutls internal version number */
Packit Service 4684c1
	unsigned age;		/* internal ordering by protocol age */
Packit Service 4684c1
	uint8_t major;		/* defined by the protocol */
Packit Service 4684c1
	uint8_t minor;		/* defined by the protocol */
Packit Service 4684c1
	transport_t transport;	/* Type of transport, stream or datagram */
Packit Service 4684c1
	bool supported;	/* 0 not supported, > 0 is supported */
Packit Service 4684c1
	bool explicit_iv;
Packit Service 4684c1
	bool extensions;	/* whether it supports extensions */
Packit Service 4684c1
	bool selectable_sighash;	/* whether signatures can be selected */
Packit Service 4684c1
	bool selectable_prf;	/* whether the PRF is ciphersuite-defined */
Packit Service 4684c1
Packit Service 4684c1
	/* if SSL3 is disabled this flag indicates that this protocol is a placeholder,
Packit Service 4684c1
	 * otherwise it prevents this protocol from being set as record version */
Packit Service 4684c1
	bool obsolete;
Packit Service 4684c1
	bool tls13_sem;		/* The TLS 1.3 handshake semantics */
Packit Service 4684c1
	bool false_start;	/* That version can be used with false start */
Packit Service 4684c1
	bool only_extension;	/* negotiated only with an extension */
Packit Service 4684c1
	bool post_handshake_auth;	/* Supports the TLS 1.3 post handshake auth */
Packit Service 4684c1
	bool key_shares;	/* TLS 1.3 key share key exchange */
Packit Service 4684c1
	bool multi_ocsp;	/* TLS 1.3 multiple OCSP responses */
Packit Service 4684c1
	/*
Packit Service 4684c1
	 * TLS versions modify the semantics of signature algorithms. This number
Packit Service 4684c1
	 * is there to distinguish signature algorithms semantics between versions
Packit Service 4684c1
	 * (maps to sign_algorithm_st->tls_sem)
Packit Service 4684c1
	 */
Packit Service 4684c1
	uint8_t tls_sig_sem;
Packit Service 4684c1
} version_entry_st;
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
/* STATE (cont) */
Packit Service 4684c1
Packit Service 4684c1
#include <hash_int.h>
Packit Service 4684c1
#include <cipher_int.h>
Packit Service 4684c1
Packit Service 4684c1
typedef struct {
Packit Service 4684c1
	uint8_t id[2]; /* used to be (in TLS 1.2) hash algorithm , PK algorithm */
Packit Service 4684c1
	uint8_t tls_sem; /* should match the protocol version's tls_sig_sem. */
Packit Service 4684c1
} sign_algorithm_st;
Packit Service 4684c1
Packit Service 4684c1
/* This structure holds parameters got from TLS extension
Packit Service 4684c1
 * mechanism. (some extensions may hold parameters in auth_info_t
Packit Service 4684c1
 * structures also - see SRP).
Packit Service 4684c1
 */
Packit Service 4684c1
Packit Service 4684c1
#define MAX_VERIFY_DATA_SIZE 36	/* in SSL 3.0, 12 in TLS 1.0 */
Packit Service 4684c1
Packit Service 4684c1
/* auth_info_t structures now MAY contain malloced
Packit Service 4684c1
 * elements.
Packit Service 4684c1
 */
Packit Service 4684c1
Packit Service 4684c1
/* This structure and auth_info_t, are stored in the resume database,
Packit Service 4684c1
 * and are restored, in case of resume.
Packit Service 4684c1
 * Holds all the required parameters to resume the current
Packit Service 4684c1
 * session.
Packit Service 4684c1
 */
Packit Service 4684c1
Packit Service 4684c1
/* Note that the security parameters structure is set up after the
Packit Service 4684c1
 * handshake has finished. The only value you may depend on while
Packit Service 4684c1
 * the handshake is in progress is the cipher suite value.
Packit Service 4684c1
 */
Packit Service 4684c1
typedef struct {
Packit Service 4684c1
	unsigned int entity;	/* GNUTLS_SERVER or GNUTLS_CLIENT */
Packit Service 4684c1
Packit Service 4684c1
	/* The epoch used to read and write */
Packit Service 4684c1
	uint16_t epoch_read;
Packit Service 4684c1
	uint16_t epoch_write;
Packit Service 4684c1
Packit Service 4684c1
	/* The epoch that the next handshake will initialize. */
Packit Service 4684c1
	uint16_t epoch_next;
Packit Service 4684c1
Packit Service 4684c1
	/* The epoch at index 0 of record_parameters. */
Packit Service 4684c1
	uint16_t epoch_min;
Packit Service 4684c1
Packit Service 4684c1
	/* this is the ciphersuite we are going to use
Packit Service 4684c1
	 * moved here from internals in order to be restored
Packit Service 4684c1
	 * on resume;
Packit Service 4684c1
	 */
Packit Service 4684c1
	const struct gnutls_cipher_suite_entry_st *cs;
Packit Service 4684c1
Packit Service 4684c1
	/* This is kept outside the ciphersuite entry as on certain
Packit Service 4684c1
	 * TLS versions we need a separate PRF MAC, i.e., MD5_SHA1. */
Packit Service 4684c1
	const mac_entry_st *prf;
Packit Service 4684c1
Packit Service 4684c1
	uint8_t master_secret[GNUTLS_MASTER_SIZE];
Packit Service 4684c1
	uint8_t client_random[GNUTLS_RANDOM_SIZE];
Packit Service 4684c1
	uint8_t server_random[GNUTLS_RANDOM_SIZE];
Packit Service 4684c1
	uint8_t session_id[GNUTLS_MAX_SESSION_ID_SIZE];
Packit Service 4684c1
	uint8_t session_id_size;
Packit Service 4684c1
	time_t timestamp;
Packit Service 4684c1
Packit Service 4684c1
	/* whether client has agreed in post handshake auth - only set on server side */
Packit Service 4684c1
	uint8_t post_handshake_auth;
Packit Service 4684c1
Packit Service 4684c1
	/* The maximum amount of plaintext sent in a record,
Packit Service 4684c1
	 * negotiated with the peer.
Packit Service 4684c1
	 */
Packit Service 4684c1
	uint16_t max_record_send_size;
Packit Service 4684c1
	uint16_t max_record_recv_size;
Packit Service 4684c1
Packit Service 4684c1
	/* The maximum amount of plaintext sent in a record, set by
Packit Service 4684c1
	 * the programmer.
Packit Service 4684c1
	 */
Packit Service 4684c1
	uint16_t max_user_record_send_size;
Packit Service 4684c1
	uint16_t max_user_record_recv_size;
Packit Service 4684c1
Packit Service 4684c1
	/* The maximum amount of early data */
Packit Service 4684c1
	uint32_t max_early_data_size;
Packit Service 4684c1
Packit Service 4684c1
	/* holds the negotiated certificate types */
Packit Service 4684c1
	gnutls_certificate_type_t client_ctype;
Packit Service 4684c1
	gnutls_certificate_type_t server_ctype;
Packit Service 4684c1
Packit Service 4684c1
	/* The selected (after server hello EC or DH group */
Packit Service 4684c1
	const gnutls_group_entry_st *grp;
Packit Service 4684c1
Packit Service 4684c1
	/* Holds the signature algorithm that will be used in this session,
Packit Service 4684c1
	 * selected by the server at the time of Ciphersuite/certificate
Packit Service 4684c1
	 * selection - see select_sign_algorithm() */
Packit Service 4684c1
	gnutls_sign_algorithm_t server_sign_algo;
Packit Service 4684c1
Packit Service 4684c1
	/* Holds the signature algorithm used in this session - If any */
Packit Service 4684c1
	gnutls_sign_algorithm_t client_sign_algo;
Packit Service 4684c1
Packit Service 4684c1
	/* Whether the master secret negotiation will be according to
Packit Service 4684c1
	 * draft-ietf-tls-session-hash-01
Packit Service 4684c1
	 */
Packit Service 4684c1
	uint8_t ext_master_secret;
Packit Service 4684c1
	/* encrypt-then-mac -> rfc7366 */
Packit Service 4684c1
	uint8_t etm;
Packit Service 4684c1
Packit Service 4684c1
	uint8_t client_auth_type; /* gnutls_credentials_type_t */
Packit Service 4684c1
	uint8_t server_auth_type;
Packit Service 4684c1
Packit Service 4684c1
	/* Note: if you add anything in Security_Parameters struct, then
Packit Service 4684c1
	 * also modify CPY_COMMON in constate.c, and session_pack.c,
Packit Service 4684c1
	 * in order to save it in the session storage.
Packit Service 4684c1
	 */
Packit Service 4684c1
Packit Service 4684c1
	/* Used by extensions that enable supplemental data: Which ones
Packit Service 4684c1
	 * do that? Do they belong in security parameters?
Packit Service 4684c1
	 */
Packit Service 4684c1
	int do_recv_supplemental, do_send_supplemental;
Packit Service 4684c1
	const version_entry_st *pversion;
Packit Service 4684c1
} security_parameters_st;
Packit Service 4684c1
Packit Service 4684c1
typedef struct api_aead_cipher_hd_st {
Packit Service 4684c1
	cipher_hd_st ctx_enc;
Packit Service 4684c1
} api_aead_cipher_hd_st;
Packit Service 4684c1
Packit Service 4684c1
struct record_state_st {
Packit Service 4684c1
	/* mac keys can be as long as the hash size */
Packit Service 4684c1
	uint8_t mac_key[MAX_HASH_SIZE];
Packit Service 4684c1
	unsigned mac_key_size;
Packit Service 4684c1
Packit Service 4684c1
	uint8_t iv[MAX_CIPHER_IV_SIZE];
Packit Service 4684c1
	unsigned iv_size;
Packit Service 4684c1
Packit Service 4684c1
	uint8_t key[MAX_CIPHER_KEY_SIZE];
Packit Service 4684c1
	unsigned key_size;
Packit Service 4684c1
Packit Service 4684c1
	union {
Packit Service 4684c1
		auth_cipher_hd_st tls12;
Packit Service 4684c1
		api_aead_cipher_hd_st aead;
Packit Service 4684c1
	} ctx;
Packit Service 4684c1
	unsigned aead_tag_size;
Packit Service 4684c1
	unsigned is_aead;
Packit Service 4684c1
	uint64_t sequence_number;
Packit Service 4684c1
};
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
/* These are used to resolve relative epochs. These values are just
Packit Service 4684c1
   outside the 16 bit range to prevent off-by-one errors. An absolute
Packit Service 4684c1
   epoch may be referred to by its numeric id in the range
Packit Service 4684c1
   0x0000-0xffff. */
Packit Service 4684c1
#define EPOCH_READ_CURRENT  70000
Packit Service 4684c1
#define EPOCH_WRITE_CURRENT 70001
Packit Service 4684c1
#define EPOCH_NEXT	  70002
Packit Service 4684c1
Packit Service 4684c1
struct record_parameters_st {
Packit Service 4684c1
	uint16_t epoch;
Packit Service 4684c1
	int initialized;
Packit Service 4684c1
Packit Service 4684c1
	const cipher_entry_st *cipher;
Packit Service 4684c1
	bool etm;
Packit Service 4684c1
	const mac_entry_st *mac;
Packit Service 4684c1
Packit Service 4684c1
	/* for DTLS sliding window */
Packit Service 4684c1
	uint64_t dtls_sw_next; /* The end point (next expected packet) of the sliding window without epoch */
Packit Service 4684c1
	uint64_t dtls_sw_bits;
Packit Service 4684c1
	unsigned dtls_sw_have_recv; /* whether at least a packet has been received */
Packit Service 4684c1
Packit Service 4684c1
	record_state_st read;
Packit Service 4684c1
	record_state_st write;
Packit Service 4684c1
Packit Service 4684c1
	/* Whether this state is in use, i.e., if there is
Packit Service 4684c1
	   a pending handshake message waiting to be encrypted
Packit Service 4684c1
	   under this epoch's parameters.
Packit Service 4684c1
	 */
Packit Service 4684c1
	int usage_cnt;
Packit Service 4684c1
};
Packit Service 4684c1
Packit Service 4684c1
typedef struct {
Packit Service 4684c1
	unsigned int priorities[MAX_ALGOS];
Packit Service 4684c1
	unsigned int num_priorities;
Packit Service 4684c1
} priority_st;
Packit Service 4684c1
Packit Service 4684c1
typedef enum {
Packit Service 4684c1
	SR_DISABLED,
Packit Service 4684c1
	SR_UNSAFE,
Packit Service 4684c1
	SR_PARTIAL,
Packit Service 4684c1
	SR_SAFE
Packit Service 4684c1
} safe_renegotiation_t;
Packit Service 4684c1
Packit Service 4684c1
#define MAX_CIPHERSUITE_SIZE 256
Packit Service 4684c1
Packit Service 4684c1
typedef struct ciphersuite_list_st {
Packit Service 4684c1
	const gnutls_cipher_suite_entry_st *entry[MAX_CIPHERSUITE_SIZE];
Packit Service 4684c1
	unsigned int size;
Packit Service 4684c1
} ciphersuite_list_st;
Packit Service 4684c1
Packit Service 4684c1
typedef struct group_list_st {
Packit Service 4684c1
	const gnutls_group_entry_st *entry[MAX_ALGOS];
Packit Service 4684c1
	unsigned int size;
Packit Service 4684c1
	bool have_ffdhe;
Packit Service 4684c1
} group_list_st;
Packit Service 4684c1
Packit Service 4684c1
typedef struct sign_algo_list_st {
Packit Service 4684c1
	const struct gnutls_sign_entry_st *entry[MAX_ALGOS];
Packit Service 4684c1
	unsigned int size;
Packit Service 4684c1
} sign_algo_list_st;
Packit Service 4684c1
Packit Service 4684c1
#include "atomic.h"
Packit Service 4684c1
Packit Service 4684c1
/* For the external api */
Packit Service 4684c1
struct gnutls_priority_st {
Packit Service 4684c1
	priority_st protocol;
Packit Service 4684c1
	priority_st client_ctype;
Packit Service 4684c1
	priority_st server_ctype;
Packit Service 4684c1
Packit Service 4684c1
	/* The following are not necessary to be stored in
Packit Service 4684c1
	 * the structure; however they are required by the
Packit Service 4684c1
	 * external APIs: gnutls_priority_*_list() */
Packit Service 4684c1
	priority_st _cipher;
Packit Service 4684c1
	priority_st _mac;
Packit Service 4684c1
	priority_st _kx;
Packit Service 4684c1
	priority_st _sign_algo;
Packit Service 4684c1
	priority_st _supported_ecc;
Packit Service 4684c1
Packit Service 4684c1
	/* the supported groups */
Packit Service 4684c1
	group_list_st groups;
Packit Service 4684c1
Packit Service 4684c1
	/* the supported signature algorithms */
Packit Service 4684c1
	sign_algo_list_st sigalg;
Packit Service 4684c1
Packit Service 4684c1
	/* the supported ciphersuites */
Packit Service 4684c1
	ciphersuite_list_st cs;
Packit Service 4684c1
Packit Service 4684c1
	/* to disable record padding */
Packit Service 4684c1
	bool no_extensions;
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
	safe_renegotiation_t sr;
Packit Service 4684c1
	bool min_record_version;
Packit Service 4684c1
	bool server_precedence;
Packit Service 4684c1
	bool allow_server_key_usage_violation; /* for test suite purposes only */
Packit Service 4684c1
	bool no_tickets;
Packit Service 4684c1
	bool have_cbc;
Packit Service 4684c1
	bool have_psk;
Packit Service 4684c1
	bool force_etm;
Packit Service 4684c1
	unsigned int additional_verify_flags;
Packit Service 4684c1
Packit Service 4684c1
	/* TLS_FALLBACK_SCSV */
Packit Service 4684c1
	bool fallback;
Packit Service 4684c1
Packit Service 4684c1
	/* The session's expected security level.
Packit Service 4684c1
	 * Will be used to determine the minimum DH bits,
Packit Service 4684c1
	 * (or the acceptable certificate security level).
Packit Service 4684c1
	 */
Packit Service 4684c1
	gnutls_sec_param_t level;
Packit Service 4684c1
Packit Service 4684c1
	/* these should be accessed from
Packit Service 4684c1
	 * session->internals.VAR names */
Packit Service 4684c1
	bool _allow_large_records;
Packit Service 4684c1
	bool _allow_small_records;
Packit Service 4684c1
	bool _no_etm;
Packit Service 4684c1
	bool _no_ext_master_secret;
Packit Service 4684c1
	bool _allow_key_usage_violation;
Packit Service 4684c1
	bool _allow_wrong_pms;
Packit Service 4684c1
	bool _dumbfw;
Packit Service 4684c1
	unsigned int _dh_prime_bits;	/* old (deprecated) variable */
Packit Service 4684c1
Packit Service 4684c1
	DEF_ATOMIC_INT(usage_cnt);
Packit Service 4684c1
};
Packit Service 4684c1
Packit Service 4684c1
/* Allow around 50KB of length-hiding padding
Packit Service 4684c1
 * when using legacy padding,
Packit Service 4684c1
 * or around 3.2MB when using new padding. */
Packit Service 4684c1
#define DEFAULT_MAX_EMPTY_RECORDS 200
Packit Service 4684c1
Packit Service 4684c1
#define ENABLE_COMPAT(x) \
Packit Service 4684c1
	      (x)->allow_large_records = 1; \
Packit Service 4684c1
	      (x)->allow_small_records = 1; \
Packit Service 4684c1
	      (x)->no_etm = 1; \
Packit Service 4684c1
	      (x)->no_ext_master_secret = 1; \
Packit Service 4684c1
	      (x)->allow_key_usage_violation = 1; \
Packit Service 4684c1
	      (x)->allow_wrong_pms = 1; \
Packit Service 4684c1
	      (x)->dumbfw = 1
Packit Service 4684c1
Packit Service 4684c1
#define ENABLE_PRIO_COMPAT(x) \
Packit Service 4684c1
	      (x)->_allow_large_records = 1; \
Packit Service 4684c1
	      (x)->_allow_small_records = 1; \
Packit Service 4684c1
	      (x)->_no_etm = 1; \
Packit Service 4684c1
	      (x)->_no_ext_master_secret = 1; \
Packit Service 4684c1
	      (x)->_allow_key_usage_violation = 1; \
Packit Service 4684c1
	      (x)->_allow_wrong_pms = 1; \
Packit Service 4684c1
	      (x)->_dumbfw = 1
Packit Service 4684c1
Packit Service 4684c1
/* DH and RSA parameters types.
Packit Service 4684c1
 */
Packit Service 4684c1
typedef struct gnutls_dh_params_int {
Packit Service 4684c1
	/* [0] is the prime, [1] is the generator, [2] is Q if available.
Packit Service 4684c1
	 */
Packit Service 4684c1
	bigint_t params[3];
Packit Service 4684c1
	int q_bits;		/* length of q in bits. If zero then length is unknown.
Packit Service 4684c1
				 */
Packit Service 4684c1
} dh_params_st;
Packit Service 4684c1
Packit Service 4684c1
/* TLS 1.3 session ticket
Packit Service 4684c1
 */
Packit Service 4684c1
typedef struct {
Packit Service 4684c1
	struct timespec arrival_time;
Packit Service 4684c1
	struct timespec creation_time;
Packit Service 4684c1
	uint32_t lifetime;
Packit Service 4684c1
	uint32_t age_add;
Packit Service 4684c1
	uint8_t nonce[255];
Packit Service 4684c1
	size_t nonce_size;
Packit Service 4684c1
	const mac_entry_st *prf;
Packit Service 4684c1
	uint8_t resumption_master_secret[MAX_HASH_SIZE];
Packit Service 4684c1
	gnutls_datum_t ticket;
Packit Service 4684c1
} tls13_ticket_st;
Packit Service 4684c1
Packit Service 4684c1
/* DTLS session state
Packit Service 4684c1
 */
Packit Service 4684c1
typedef struct {
Packit Service 4684c1
	/* HelloVerifyRequest DOS prevention cookie */
Packit Service 4684c1
	gnutls_datum_t dcookie;
Packit Service 4684c1
Packit Service 4684c1
	/* For DTLS handshake fragmentation and reassembly. */
Packit Service 4684c1
	uint16_t hsk_write_seq;
Packit Service 4684c1
	/* the sequence number of the expected packet */
Packit Service 4684c1
	unsigned int hsk_read_seq;
Packit Service 4684c1
	uint16_t mtu;
Packit Service 4684c1
Packit Service 4684c1
	/* a flight transmission is in process */
Packit Service 4684c1
	bool flight_init;
Packit Service 4684c1
	/* whether this is the last flight in the protocol  */
Packit Service 4684c1
	bool last_flight;
Packit Service 4684c1
Packit Service 4684c1
	/* the retransmission timeout in milliseconds */
Packit Service 4684c1
	unsigned int retrans_timeout_ms;
Packit Service 4684c1
Packit Service 4684c1
	unsigned int hsk_hello_verify_requests;
Packit Service 4684c1
Packit Service 4684c1
	/* The actual retrans_timeout for the next message (e.g. doubled or so)
Packit Service 4684c1
	 */
Packit Service 4684c1
	unsigned int actual_retrans_timeout_ms;
Packit Service 4684c1
Packit Service 4684c1
	/* timers to handle async handshake after gnutls_handshake()
Packit Service 4684c1
	 * has terminated. Required to handle retransmissions.
Packit Service 4684c1
	 */
Packit Service 4684c1
	time_t async_term;
Packit Service 4684c1
Packit Service 4684c1
	/* last retransmission triggered by record layer */
Packit Service 4684c1
	struct timespec last_retransmit;
Packit Service 4684c1
	unsigned int packets_dropped;
Packit Service 4684c1
} dtls_st;
Packit Service 4684c1
Packit Service 4684c1
typedef struct tfo_st {
Packit Service 4684c1
	int fd;
Packit Service 4684c1
	int flags;
Packit Service 4684c1
	bool connect_only; /* a previous sendmsg() failed, attempting connect() */
Packit Service 4684c1
	struct sockaddr_storage connect_addr;
Packit Service 4684c1
	socklen_t connect_addrlen;
Packit Service 4684c1
} tfo_st;
Packit Service 4684c1
Packit Service 4684c1
typedef struct {
Packit Service 4684c1
	/* holds all the parsed data received by the record layer */
Packit Service 4684c1
	mbuffer_head_st record_buffer;
Packit Service 4684c1
Packit Service 4684c1
	int handshake_hash_buffer_prev_len;	/* keeps the length of handshake_hash_buffer, excluding
Packit Service 4684c1
						 * the last received message */
Packit Service 4684c1
	unsigned handshake_hash_buffer_client_hello_len; /* if non-zero it is the length of data until the client hello message */
Packit Service 4684c1
	unsigned handshake_hash_buffer_client_kx_len;/* if non-zero it is the length of data until the
Packit Service 4684c1
						 * the client key exchange message */
Packit Service 4684c1
	unsigned handshake_hash_buffer_server_finished_len;/* if non-zero it is the length of data until the
Packit Service 4684c1
						 * the server finished message */
Packit Service 4684c1
	unsigned handshake_hash_buffer_client_finished_len;/* if non-zero it is the length of data until the
Packit Service 4684c1
						 * the client finished message */
Packit Service 4684c1
	gnutls_buffer_st handshake_hash_buffer;	/* used to keep the last received handshake
Packit Service 4684c1
						 * message */
Packit Service 4684c1
Packit Service 4684c1
	bool resumable;	/* TRUE or FALSE - if we can resume that session */
Packit Service 4684c1
Packit Service 4684c1
	send_ticket_state_t ticket_state; /* used by gnutls_session_ticket_send() */
Packit Service 4684c1
	bye_state_t bye_state; /* used by gnutls_bye() */
Packit Service 4684c1
	reauth_state_t reauth_state; /* used by gnutls_reauth() */
Packit Service 4684c1
Packit Service 4684c1
	handshake_state_t handshake_final_state;
Packit Service 4684c1
	handshake_state_t handshake_state;	/* holds
Packit Service 4684c1
						 * a number which indicates where
Packit Service 4684c1
						 * the handshake procedure has been
Packit Service 4684c1
						 * interrupted. If it is 0 then
Packit Service 4684c1
						 * no interruption has happened.
Packit Service 4684c1
						 */
Packit Service 4684c1
Packit Service 4684c1
	bool invalid_connection;	/* true or FALSE - if this session is valid */
Packit Service 4684c1
Packit Service 4684c1
	bool may_not_read;	/* if it's 0 then we can read/write, otherwise it's forbidden to read/write
Packit Service 4684c1
				 */
Packit Service 4684c1
	bool may_not_write;
Packit Service 4684c1
	bool read_eof;		/* non-zero if we have received a closure alert. */
Packit Service 4684c1
Packit Service 4684c1
	int last_alert;		/* last alert received */
Packit Service 4684c1
Packit Service 4684c1
	/* The last handshake messages sent or received.
Packit Service 4684c1
	 */
Packit Service 4684c1
	int last_handshake_in;
Packit Service 4684c1
	int last_handshake_out;
Packit Service 4684c1
Packit Service 4684c1
	/* priorities */
Packit Service 4684c1
	struct gnutls_priority_st *priorities;
Packit Service 4684c1
Packit Service 4684c1
	/* variables directly set when setting the priorities above, or
Packit Service 4684c1
	 * when overriding them */
Packit Service 4684c1
	bool allow_large_records;
Packit Service 4684c1
	bool allow_small_records;
Packit Service 4684c1
	bool no_etm;
Packit Service 4684c1
	bool no_ext_master_secret;
Packit Service 4684c1
	bool allow_key_usage_violation;
Packit Service 4684c1
	bool allow_wrong_pms;
Packit Service 4684c1
	bool dumbfw;
Packit Service 4684c1
Packit Service 4684c1
	/* old (deprecated) variable. This is used for both srp_prime_bits
Packit Service 4684c1
	 * and dh_prime_bits as they don't overlap */
Packit Service 4684c1
	/* For SRP: minimum bits to allow for SRP
Packit Service 4684c1
	 * use gnutls_srp_set_prime_bits() to adjust it.
Packit Service 4684c1
	 */
Packit Service 4684c1
	uint16_t dh_prime_bits; /* srp_prime_bits */
Packit Service 4684c1
Packit Service 4684c1
	/* resumed session */
Packit Service 4684c1
	bool resumed;	/* RESUME_TRUE or FALSE - if we are resuming a session */
Packit Service 4684c1
Packit Service 4684c1
	/* server side: non-zero if resumption was requested by client
Packit Service 4684c1
	 * client side: non-zero if we set resumption parameters */
Packit Service 4684c1
	bool resumption_requested;
Packit Service 4684c1
	security_parameters_st resumed_security_parameters;
Packit Service 4684c1
	gnutls_datum_t resumption_data; /* copy of input to gnutls_session_set_data() */
Packit Service 4684c1
Packit Service 4684c1
	/* These buffers are used in the handshake
Packit Service 4684c1
	 * protocol only. freed using _gnutls_handshake_io_buffer_clear();
Packit Service 4684c1
	 */
Packit Service 4684c1
	mbuffer_head_st handshake_send_buffer;
Packit Service 4684c1
	mbuffer_head_st handshake_header_recv_buffer;
Packit Service 4684c1
	handshake_buffer_st handshake_recv_buffer[MAX_HANDSHAKE_MSGS];
Packit Service 4684c1
	int handshake_recv_buffer_size;
Packit Service 4684c1
Packit Service 4684c1
	/* this buffer holds a record packet -mostly used for
Packit Service 4684c1
	 * non blocking IO.
Packit Service 4684c1
	 */
Packit Service 4684c1
	mbuffer_head_st record_recv_buffer;	/* buffer holding the unparsed record that is currently
Packit Service 4684c1
						 * being received */
Packit Service 4684c1
	mbuffer_head_st record_send_buffer;	/* holds cached data
Packit Service 4684c1
						 * for the gnutls_io_write_buffered()
Packit Service 4684c1
						 * function.
Packit Service 4684c1
						 */
Packit Service 4684c1
	size_t record_send_buffer_user_size;	/* holds the
Packit Service 4684c1
						 * size of the user specified data to
Packit Service 4684c1
						 * send.
Packit Service 4684c1
						 */
Packit Service 4684c1
Packit Service 4684c1
	mbuffer_head_st early_data_recv_buffer;
Packit Service 4684c1
	gnutls_buffer_st early_data_presend_buffer;
Packit Service 4684c1
Packit Service 4684c1
	record_send_state_t rsend_state;
Packit Service 4684c1
	/* buffer used temporarily during key update */
Packit Service 4684c1
	gnutls_buffer_st record_key_update_buffer;
Packit Service 4684c1
	gnutls_buffer_st record_presend_buffer;	/* holds cached data
Packit Service 4684c1
						 * for the gnutls_record_send()
Packit Service 4684c1
						 * function.
Packit Service 4684c1
						 */
Packit Service 4684c1
Packit Service 4684c1
	/* buffer used temporarily during TLS1.3 reauthentication */
Packit Service 4684c1
	gnutls_buffer_st reauth_buffer;
Packit Service 4684c1
Packit Service 4684c1
	time_t expire_time;	/* after expire_time seconds this session will expire */
Packit Service 4684c1
	const struct mod_auth_st_int *auth_struct;	/* used in handshake packets and KX algorithms */
Packit Service 4684c1
Packit Service 4684c1
	/* this is the highest version available
Packit Service 4684c1
	 * to the peer. (advertized version).
Packit Service 4684c1
	 * This is obtained by the Handshake Client Hello
Packit Service 4684c1
	 * message. (some implementations read the Record version)
Packit Service 4684c1
	 */
Packit Service 4684c1
	uint8_t adv_version_major;
Packit Service 4684c1
	uint8_t adv_version_minor;
Packit Service 4684c1
Packit Service 4684c1
	/* if this is non zero a certificate request message
Packit Service 4684c1
	 * will be sent to the client. - only if the ciphersuite
Packit Service 4684c1
	 * supports it. In server side it contains GNUTLS_CERT_REQUIRE
Packit Service 4684c1
	 * or similar.
Packit Service 4684c1
	 */
Packit Service 4684c1
	gnutls_certificate_request_t send_cert_req;
Packit Service 4684c1
Packit Service 4684c1
	size_t max_handshake_data_buffer_size;
Packit Service 4684c1
Packit Service 4684c1
	/* PUSH & PULL functions.
Packit Service 4684c1
	 */
Packit Service 4684c1
	gnutls_pull_timeout_func pull_timeout_func;
Packit Service 4684c1
	gnutls_pull_func pull_func;
Packit Service 4684c1
	gnutls_push_func push_func;
Packit Service 4684c1
	gnutls_vec_push_func vec_push_func;
Packit Service 4684c1
	gnutls_errno_func errno_func;
Packit Service 4684c1
	/* Holds the first argument of PUSH and PULL
Packit Service 4684c1
	 * functions;
Packit Service 4684c1
	 */
Packit Service 4684c1
	gnutls_transport_ptr_t transport_recv_ptr;
Packit Service 4684c1
	gnutls_transport_ptr_t transport_send_ptr;
Packit Service 4684c1
Packit Service 4684c1
	/* STORE & RETRIEVE functions. Only used if other
Packit Service 4684c1
	 * backend than gdbm is used.
Packit Service 4684c1
	 */
Packit Service 4684c1
	gnutls_db_store_func db_store_func;
Packit Service 4684c1
	gnutls_db_retr_func db_retrieve_func;
Packit Service 4684c1
	gnutls_db_remove_func db_remove_func;
Packit Service 4684c1
	void *db_ptr;
Packit Service 4684c1
Packit Service 4684c1
	/* post client hello callback (server side only)
Packit Service 4684c1
	 */
Packit Service 4684c1
	gnutls_handshake_post_client_hello_func user_hello_func;
Packit Service 4684c1
	/* handshake hook function */
Packit Service 4684c1
	gnutls_handshake_hook_func h_hook;
Packit Service 4684c1
	unsigned int h_type;	/* the hooked type */
Packit Service 4684c1
	int16_t h_post;		/* whether post-generation/receive */
Packit Service 4684c1
Packit Service 4684c1
	gnutls_keylog_func keylog_func;
Packit Service 4684c1
Packit Service 4684c1
	/* holds the selected certificate and key.
Packit Service 4684c1
	 * use _gnutls_selected_certs_deinit() and _gnutls_selected_certs_set()
Packit Service 4684c1
	 * to change them.
Packit Service 4684c1
	 */
Packit Service 4684c1
	gnutls_pcert_st *selected_cert_list;
Packit Service 4684c1
	uint16_t selected_cert_list_length;
Packit Service 4684c1
	struct gnutls_privkey_st *selected_key;
Packit Service 4684c1
Packit Service 4684c1
	/* new callbacks such as gnutls_certificate_retrieve_function3
Packit Service 4684c1
	 * set the selected_ocsp datum values. The older OCSP callback-based
Packit Service 4684c1
	 * functions, set the ocsp_func. The former takes precedence when
Packit Service 4684c1
	 * set.
Packit Service 4684c1
	 */
Packit Service 4684c1
	gnutls_ocsp_data_st *selected_ocsp;
Packit Service 4684c1
	uint16_t selected_ocsp_length;
Packit Service 4684c1
	gnutls_status_request_ocsp_func selected_ocsp_func;
Packit Service 4684c1
	void *selected_ocsp_func_ptr;
Packit Service 4684c1
	bool selected_need_free;
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
	/* This holds the default version that our first
Packit Service 4684c1
	 * record packet will have. */
Packit Service 4684c1
	uint8_t default_record_version[2];
Packit Service 4684c1
	uint8_t default_hello_version[2];
Packit Service 4684c1
Packit Service 4684c1
	void *user_ptr;
Packit Service 4684c1
Packit Service 4684c1
	/* Holds 0 if the last called function was interrupted while
Packit Service 4684c1
	 * receiving, and non zero otherwise.
Packit Service 4684c1
	 */
Packit Service 4684c1
	bool direction;
Packit Service 4684c1
Packit Service 4684c1
	/* If non zero the server will not advertise the CA's he
Packit Service 4684c1
	 * trusts (do not send an RDN sequence).
Packit Service 4684c1
	 */
Packit Service 4684c1
	bool ignore_rdn_sequence;
Packit Service 4684c1
Packit Service 4684c1
	/* This is used to set an arbitrary version in the RSA
Packit Service 4684c1
	 * PMS secret. Can be used by clients to test whether the
Packit Service 4684c1
	 * server checks that version. (** only used in gnutls-cli-debug)
Packit Service 4684c1
	 */
Packit Service 4684c1
	uint8_t rsa_pms_version[2];
Packit Service 4684c1
Packit Service 4684c1
	/* To avoid using global variables, and especially on Windows where
Packit Service 4684c1
	 * the application may use a different errno variable than GnuTLS,
Packit Service 4684c1
	 * it is possible to use gnutls_transport_set_errno to set a
Packit Service 4684c1
	 * session-specific errno variable in the user-replaceable push/pull
Packit Service 4684c1
	 * functions.  This value is used by the send/recv functions.  (The
Packit Service 4684c1
	 * strange name of this variable is because 'errno' is typically
Packit Service 4684c1
	 * #define'd.)
Packit Service 4684c1
	 */
Packit Service 4684c1
	int errnum;
Packit Service 4684c1
Packit Service 4684c1
	/* A handshake process has been completed */
Packit Service 4684c1
	bool initial_negotiation_completed;
Packit Service 4684c1
	void *post_negotiation_lock; /* protects access to the variable above
Packit Service 4684c1
				      * in the cases where negotiation is incomplete
Packit Service 4684c1
				      * after gnutls_handshake() - early/false start */
Packit Service 4684c1
Packit Service 4684c1
	/* The type of transport protocol; stream or datagram */
Packit Service 4684c1
	transport_t transport;
Packit Service 4684c1
Packit Service 4684c1
	/* DTLS session state */
Packit Service 4684c1
	dtls_st dtls;
Packit Service 4684c1
	/* Protect from infinite loops due to GNUTLS_E_LARGE_PACKET non-handling
Packit Service 4684c1
	 * or due to multiple alerts being received. */
Packit Service 4684c1
	unsigned handshake_suspicious_loops;
Packit Service 4684c1
	/* should be non-zero when a handshake is in progress */
Packit Service 4684c1
	bool handshake_in_progress;
Packit Service 4684c1
Packit Service 4684c1
	/* if set it means that the master key was set using
Packit Service 4684c1
	 * gnutls_session_set_master() rather than being negotiated. */
Packit Service 4684c1
	bool premaster_set;
Packit Service 4684c1
Packit Service 4684c1
	unsigned int cb_tls_unique_len;
Packit Service 4684c1
	unsigned char cb_tls_unique[MAX_VERIFY_DATA_SIZE];
Packit Service 4684c1
Packit Service 4684c1
	/* starting time of current handshake */
Packit Service 4684c1
	struct timespec handshake_start_time;
Packit Service 4684c1
Packit Service 4684c1
	/* expected end time of current handshake (start+timeout);
Packit Service 4684c1
	 * this is only filled if a handshake_time_ms is set. */
Packit Service 4684c1
	struct timespec handshake_abs_timeout;
Packit Service 4684c1
Packit Service 4684c1
	/* An estimation of round-trip time under TLS1.3; populated in client side only */
Packit Service 4684c1
	unsigned ertt;
Packit Service 4684c1
Packit Service 4684c1
	unsigned int handshake_timeout_ms;	/* timeout in milliseconds */
Packit Service 4684c1
	unsigned int record_timeout_ms;	/* timeout in milliseconds */
Packit Service 4684c1
Packit Service 4684c1
	/* saved context of post handshake certificate request. In
Packit Service 4684c1
	 * client side is what we received in server's certificate request;
Packit Service 4684c1
	 * in server side is what we sent to client. */
Packit Service 4684c1
	gnutls_datum_t post_handshake_cr_context;
Packit Service 4684c1
	/* it is a copy of the handshake hash buffer if post handshake is used */
Packit Service 4684c1
	gnutls_buffer_st post_handshake_hash_buffer;
Packit Service 4684c1
Packit Service 4684c1
/* When either of PSK or DHE-PSK is received */
Packit Service 4684c1
#define HSK_PSK_KE_MODES_RECEIVED (HSK_PSK_KE_MODE_PSK|HSK_PSK_KE_MODE_DHE_PSK|HSK_PSK_KE_MODE_INVALID)
Packit Service 4684c1
Packit Service 4684c1
#define HSK_CRT_VRFY_EXPECTED 1
Packit Service 4684c1
#define HSK_CRT_ASKED (1<<2)
Packit Service 4684c1
#define HSK_HRR_SENT (1<<3)
Packit Service 4684c1
#define HSK_HRR_RECEIVED (1<<4)
Packit Service 4684c1
#define HSK_CRT_REQ_SENT (1<<5)
Packit Service 4684c1
#define HSK_KEY_UPDATE_ASKED (1<<7) /* flag is not used during handshake */
Packit Service 4684c1
#define HSK_FALSE_START_USED (1<<8) /* TLS1.2 only */
Packit Service 4684c1
#define HSK_HAVE_FFDHE (1<<9) /* whether the peer has advertized at least an FFDHE group */
Packit Service 4684c1
#define HSK_USED_FFDHE (1<<10) /* whether ffdhe was actually negotiated and used */
Packit Service 4684c1
#define HSK_PSK_KE_MODES_SENT (1<<11)
Packit Service 4684c1
#define HSK_PSK_KE_MODE_PSK (1<<12) /* client: whether PSK without DH is allowed,
Packit Service 4684c1
				     * server: whether PSK without DH is selected. */
Packit Service 4684c1
#define HSK_PSK_KE_MODE_INVALID (1<<13) /* server: no compatible PSK modes were seen */
Packit Service 4684c1
#define HSK_PSK_KE_MODE_DHE_PSK (1<<14) /* server: whether PSK with DH is selected
Packit Service 4684c1
					 * client: whether PSK with DH is allowed
Packit Service 4684c1
					 */
Packit Service 4684c1
#define HSK_PSK_SELECTED (1<<15) /* server: whether PSK was selected, either for resumption or not;
Packit Service 4684c1
				  *	    on resumption session->internals.resumed will be set as well.
Packit Service 4684c1
				  * client: the same */
Packit Service 4684c1
#define HSK_KEY_SHARE_SENT (1<<16) /* server: key share was sent to client */
Packit Service 4684c1
#define HSK_KEY_SHARE_RECEIVED (1<<17) /* client: key share was received
Packit Service 4684c1
					* server: key share was received and accepted */
Packit Service 4684c1
#define HSK_TLS13_TICKET_SENT (1<<18) /* client: sent a ticket under TLS1.3;
Packit Service 4684c1
					 * server: a ticket was sent to client.
Packit Service 4684c1
					 */
Packit Service 4684c1
#define HSK_TLS12_TICKET_SENT (1<<19) /* client: sent a ticket under TLS1.2;
Packit Service 4684c1
				       * server: a ticket was sent to client.
Packit Service 4684c1
				       */
Packit Service 4684c1
#define HSK_TICKET_RECEIVED (1<<20) /* client: a session ticket was received */
Packit Service 4684c1
#define HSK_EARLY_START_USED (1<<21)
Packit Service 4684c1
#define HSK_EARLY_DATA_IN_FLIGHT (1<<22) /* client: sent early_data extension in ClientHello
Packit Service 4684c1
					  * server: early_data extension was seen in ClientHello
Packit Service 4684c1
					  */
Packit Service 4684c1
#define HSK_EARLY_DATA_ACCEPTED (1<<23) /* client: early_data extension was seen in EncryptedExtensions
Packit Service 4684c1
					 * server: intend to process early data
Packit Service 4684c1
					 */
Packit Service 4684c1
#define HSK_RECORD_SIZE_LIMIT_NEGOTIATED (1<<24)
Packit Service 4684c1
#define HSK_RECORD_SIZE_LIMIT_SENT (1<<25) /* record_size_limit extension was sent */
Packit Service 4684c1
#define HSK_RECORD_SIZE_LIMIT_RECEIVED (1<<26) /* server: record_size_limit extension was seen but not accepted yet */
Packit Service 4684c1
#define HSK_OCSP_REQUESTED (1<<27) /* server: client requested OCSP stapling */
Packit Service 4684c1
#define HSK_CLIENT_OCSP_REQUESTED (1<<28) /* client: server requested OCSP stapling */
Packit Service 4684c1
Packit Service 4684c1
	/* The hsk_flags are for use within the ongoing handshake;
Packit Service 4684c1
	 * they are reset to zero prior to handshake start by gnutls_handshake. */
Packit Service 4684c1
	unsigned hsk_flags;
Packit Service 4684c1
	struct timespec last_key_update;
Packit Service 4684c1
	unsigned key_update_count;
Packit Service 4684c1
	/* Read-only pointer to the full ClientHello message */
Packit Service 4684c1
	gnutls_buffer_st full_client_hello;
Packit Service 4684c1
	/* The offset at which extensions start in the ClientHello buffer */
Packit Service 4684c1
	int extensions_offset;
Packit Service 4684c1
Packit Service 4684c1
	gnutls_buffer_st hb_local_data;
Packit Service 4684c1
	gnutls_buffer_st hb_remote_data;
Packit Service 4684c1
	struct timespec hb_ping_start;	/* timestamp: when first HeartBeat ping was sent */
Packit Service 4684c1
	struct timespec hb_ping_sent;	/* timestamp: when last HeartBeat ping was sent */
Packit Service 4684c1
	unsigned int hb_actual_retrans_timeout_ms;	/* current timeout, in milliseconds */
Packit Service 4684c1
	unsigned int hb_retrans_timeout_ms;	/* the default timeout, in milliseconds */
Packit Service 4684c1
	unsigned int hb_total_timeout_ms;	/* the total timeout, in milliseconds */
Packit Service 4684c1
Packit Service 4684c1
	bool ocsp_check_ok;	/* will be zero if the OCSP response TLS extension
Packit Service 4684c1
					 * check failed (OCSP was old/unrelated or so). */
Packit Service 4684c1
Packit Service 4684c1
	heartbeat_state_t hb_state;	/* for ping */
Packit Service 4684c1
Packit Service 4684c1
	recv_state_t recv_state;	/* state of the receive function */
Packit Service 4684c1
Packit Service 4684c1
	/* if set, server and client random were set by the application */
Packit Service 4684c1
	bool sc_random_set;
Packit Service 4684c1
Packit Service 4684c1
#define INT_FLAG_NO_TLS13 (1LL<<60)
Packit Service 4684c1
	uint64_t flags; /* the flags in gnutls_init() and GNUTLS_INT_FLAGS */
Packit Service 4684c1
Packit Service 4684c1
	/* a verify callback to override the verify callback from the credentials
Packit Service 4684c1
	 * structure */
Packit Service 4684c1
	gnutls_certificate_verify_function *verify_callback;
Packit Service 4684c1
	gnutls_typed_vdata_st *vc_data;
Packit Service 4684c1
	gnutls_typed_vdata_st vc_sdata;
Packit Service 4684c1
	unsigned vc_elements;
Packit Service 4684c1
	unsigned vc_status;
Packit Service 4684c1
	unsigned int additional_verify_flags; /* may be set by priorities or the vc functions */
Packit Service 4684c1
Packit Service 4684c1
	/* we append the verify flags because these can be set,
Packit Service 4684c1
	 * either by this function or by gnutls_session_set_verify_cert().
Packit Service 4684c1
	 * However, we ensure that a single profile is set. */
Packit Service 4684c1
#define ADD_PROFILE_VFLAGS(session, vflags) do { \
Packit Service 4684c1
	if ((session->internals.additional_verify_flags & GNUTLS_VFLAGS_PROFILE_MASK) && \
Packit Service 4684c1
	    (vflags & GNUTLS_VFLAGS_PROFILE_MASK)) \
Packit Service 4684c1
		session->internals.additional_verify_flags &= ~GNUTLS_VFLAGS_PROFILE_MASK; \
Packit Service 4684c1
	session->internals.additional_verify_flags |= vflags; \
Packit Service 4684c1
	} while(0)
Packit Service 4684c1
Packit Service 4684c1
	/* the SHA256 hash of the peer's certificate */
Packit Service 4684c1
	uint8_t cert_hash[32];
Packit Service 4684c1
	bool cert_hash_set;
Packit Service 4684c1
Packit Service 4684c1
	/* The saved username from PSK or SRP auth */
Packit Service 4684c1
	char saved_username[MAX_USERNAME_SIZE+1];
Packit Service 4684c1
	int saved_username_size;
Packit Service 4684c1
Packit Service 4684c1
	/* Needed for TCP Fast Open (TFO), set by gnutls_transport_set_fastopen() */
Packit Service 4684c1
	tfo_st tfo;
Packit Service 4684c1
Packit Service 4684c1
	struct gnutls_supplemental_entry_st *rsup;
Packit Service 4684c1
	unsigned rsup_size;
Packit Service 4684c1
Packit Service 4684c1
	struct hello_ext_entry_st *rexts;
Packit Service 4684c1
	unsigned rexts_size;
Packit Service 4684c1
Packit Service 4684c1
	struct { /* ext_data[id] contains data for extension_t id */
Packit Service 4684c1
		gnutls_ext_priv_data_t priv;
Packit Service 4684c1
		gnutls_ext_priv_data_t resumed_priv;
Packit Service 4684c1
		uint8_t set;
Packit Service 4684c1
		uint8_t resumed_set;
Packit Service 4684c1
	} ext_data[MAX_EXT_TYPES];
Packit Service 4684c1
Packit Service 4684c1
	/* In case of a client holds the extensions we sent to the peer;
Packit Service 4684c1
	 * otherwise the extensions we received from the client. This is
Packit Service 4684c1
	 * an OR of (1<
Packit Service 4684c1
	 */
Packit Service 4684c1
	ext_track_t used_exts;
Packit Service 4684c1
Packit Service 4684c1
	gnutls_ext_flags_t ext_msg; /* accessed through _gnutls_ext_get/set_msg() */
Packit Service 4684c1
Packit Service 4684c1
	/* this is not the negotiated max_record_recv_size, but the actual maximum
Packit Service 4684c1
	 * receive size */
Packit Service 4684c1
	unsigned max_recv_size;
Packit Service 4684c1
Packit Service 4684c1
	/* candidate groups to be selected for security params groups, they are
Packit Service 4684c1
	 * prioritized in isolation under TLS1.2 */
Packit Service 4684c1
	const gnutls_group_entry_st *cand_ec_group;
Packit Service 4684c1
	const gnutls_group_entry_st *cand_dh_group;
Packit Service 4684c1
	/* used under TLS1.3+ */
Packit Service 4684c1
	const gnutls_group_entry_st *cand_group;
Packit Service 4684c1
Packit Service 4684c1
	/* the ciphersuite received in HRR */
Packit Service 4684c1
	uint8_t hrr_cs[2];
Packit Service 4684c1
Packit Service 4684c1
	/* this is only used under TLS1.2 or earlier */
Packit Service 4684c1
	int session_ticket_renew;
Packit Service 4684c1
Packit Service 4684c1
	tls13_ticket_st tls13_ticket;
Packit Service 4684c1
Packit Service 4684c1
	/* the amount of early data received so far */
Packit Service 4684c1
	uint32_t early_data_received;
Packit Service 4684c1
Packit Service 4684c1
	/* anti-replay measure for 0-RTT mode */
Packit Service 4684c1
	gnutls_anti_replay_t anti_replay;
Packit Service 4684c1
Packit Service 4684c1
	/* Protects _gnutls_epoch_gc() from _gnutls_epoch_get(); these may be
Packit Service 4684c1
	 * called in parallel when false start is used and false start is used. */
Packit Service 4684c1
	void *epoch_lock;
Packit Service 4684c1
Packit Service 4684c1
	/* If you add anything here, check _gnutls_handshake_internal_state_clear().
Packit Service 4684c1
	 */
Packit Service 4684c1
} internals_st;
Packit Service 4684c1
Packit Service 4684c1
/* Maximum number of epochs we keep around. */
Packit Service 4684c1
#define MAX_EPOCH_INDEX 4
Packit Service 4684c1
Packit Service 4684c1
#define reset_cand_groups(session) \
Packit Service 4684c1
	session->internals.cand_ec_group = session->internals.cand_dh_group = \
Packit Service 4684c1
		session->internals.cand_group = NULL
Packit Service 4684c1
Packit Service 4684c1
struct gnutls_session_int {
Packit Service 4684c1
	security_parameters_st security_parameters;
Packit Service 4684c1
	record_parameters_st *record_parameters[MAX_EPOCH_INDEX];
Packit Service 4684c1
	internals_st internals;
Packit Service 4684c1
	gnutls_key_st key;
Packit Service 4684c1
};
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
/* functions
Packit Service 4684c1
 */
Packit Service 4684c1
void _gnutls_free_auth_info(gnutls_session_t session);
Packit Service 4684c1
Packit Service 4684c1
/* These two macros return the advertised TLS version of
Packit Service 4684c1
 * the peer.
Packit Service 4684c1
 */
Packit Service 4684c1
#define _gnutls_get_adv_version_major(session) \
Packit Service 4684c1
	session->internals.adv_version_major
Packit Service 4684c1
Packit Service 4684c1
#define _gnutls_get_adv_version_minor(session) \
Packit Service 4684c1
	session->internals.adv_version_minor
Packit Service 4684c1
Packit Service 4684c1
#define set_adv_version(session, major, minor) \
Packit Service 4684c1
	session->internals.adv_version_major = major; \
Packit Service 4684c1
	session->internals.adv_version_minor = minor
Packit Service 4684c1
Packit Service 4684c1
int _gnutls_is_secure_mem_null(const void *);
Packit Service 4684c1
Packit Service 4684c1
inline static const version_entry_st *get_version(gnutls_session_t session)
Packit Service 4684c1
{
Packit Service 4684c1
	return session->security_parameters.pversion;
Packit Service 4684c1
}
Packit Service 4684c1
Packit Service 4684c1
inline static unsigned get_num_version(gnutls_session_t session)
Packit Service 4684c1
{
Packit Service 4684c1
	if (likely(session->security_parameters.pversion != NULL))
Packit Service 4684c1
		return session->security_parameters.pversion->id;
Packit Service 4684c1
	else
Packit Service 4684c1
		return GNUTLS_VERSION_UNKNOWN;
Packit Service 4684c1
}
Packit Service 4684c1
Packit Service 4684c1
void _gnutls_priority_update_fips(void);
Packit Service 4684c1
void _gnutls_priority_update_non_aesni(void);
Packit Service 4684c1
extern unsigned _gnutls_disable_tls13;
Packit Service 4684c1
Packit Service 4684c1
#define timespec_sub_ms _gnutls_timespec_sub_ms
Packit Service 4684c1
unsigned int
Packit Service 4684c1
/* returns a-b in ms */
Packit Service 4684c1
 timespec_sub_ms(struct timespec *a, struct timespec *b);
Packit Service 4684c1
Packit Service 4684c1
inline static int _gnutls_timespec_cmp(struct timespec *a, struct timespec *b) {
Packit Service 4684c1
	if (a->tv_sec < b->tv_sec)
Packit Service 4684c1
		return -1;
Packit Service 4684c1
	if (a->tv_sec > b->tv_sec)
Packit Service 4684c1
		return 1;
Packit Service 4684c1
	if (a->tv_nsec < b->tv_nsec)
Packit Service 4684c1
		return -1;
Packit Service 4684c1
	if (a->tv_nsec > b->tv_nsec)
Packit Service 4684c1
		return 1;
Packit Service 4684c1
	return 0;
Packit Service 4684c1
}
Packit Service 4684c1
Packit Service 4684c1
#include <algorithms.h>
Packit Service 4684c1
inline static int _gnutls_set_current_version(gnutls_session_t s, unsigned v)
Packit Service 4684c1
{
Packit Service 4684c1
	s->security_parameters.pversion = version_to_entry(v);
Packit Service 4684c1
	if (s->security_parameters.pversion == NULL) {
Packit Service 4684c1
		return GNUTLS_E_UNSUPPORTED_VERSION_PACKET;
Packit Service 4684c1
	}
Packit Service 4684c1
	return 0;
Packit Service 4684c1
}
Packit Service 4684c1
Packit Service 4684c1
/* Returns the maximum amount of the plaintext to be sent, considering
Packit Service 4684c1
 * both user-specified/negotiated maximum values.
Packit Service 4684c1
 */
Packit Service 4684c1
inline static size_t max_record_send_size(gnutls_session_t session,
Packit Service 4684c1
					  record_parameters_st *
Packit Service 4684c1
					  record_params)
Packit Service 4684c1
{
Packit Service 4684c1
	size_t max;
Packit Service 4684c1
Packit Service 4684c1
	max = MIN(session->security_parameters.max_record_send_size,
Packit Service 4684c1
		  session->security_parameters.max_user_record_send_size);
Packit Service 4684c1
Packit Service 4684c1
	if (IS_DTLS(session))
Packit Service 4684c1
		max = MIN(gnutls_dtls_get_data_mtu(session), max);
Packit Service 4684c1
Packit Service 4684c1
	return max;
Packit Service 4684c1
}
Packit Service 4684c1
Packit Service 4684c1
/* Returns the during the handshake negotiated certificate type(s).
Packit Service 4684c1
 * See state.c for the full function documentation.
Packit Service 4684c1
 *
Packit Service 4684c1
 * This function is made static inline for optimization reasons.
Packit Service 4684c1
 */
Packit Service 4684c1
inline static gnutls_certificate_type_t
Packit Service 4684c1
get_certificate_type(gnutls_session_t session,
Packit Service 4684c1
		     gnutls_ctype_target_t target)
Packit Service 4684c1
{
Packit Service 4684c1
	switch (target) {
Packit Service 4684c1
		case GNUTLS_CTYPE_CLIENT:
Packit Service 4684c1
			return session->security_parameters.client_ctype;
Packit Service 4684c1
			break;
Packit Service 4684c1
		case GNUTLS_CTYPE_SERVER:
Packit Service 4684c1
			return session->security_parameters.server_ctype;
Packit Service 4684c1
			break;
Packit Service 4684c1
		case GNUTLS_CTYPE_OURS:
Packit Service 4684c1
			if (IS_SERVER(session)) {
Packit Service 4684c1
				return session->security_parameters.server_ctype;
Packit Service 4684c1
			} else {
Packit Service 4684c1
				return session->security_parameters.client_ctype;
Packit Service 4684c1
			}
Packit Service 4684c1
			break;
Packit Service 4684c1
		case GNUTLS_CTYPE_PEERS:
Packit Service 4684c1
			if (IS_SERVER(session)) {
Packit Service 4684c1
				return session->security_parameters.client_ctype;
Packit Service 4684c1
			} else {
Packit Service 4684c1
				return session->security_parameters.server_ctype;
Packit Service 4684c1
			}
Packit Service 4684c1
			break;
Packit Service 4684c1
		default:	// Illegal parameter passed
Packit Service 4684c1
			return GNUTLS_CRT_UNKNOWN;
Packit Service 4684c1
	}
Packit Service 4684c1
}
Packit Service 4684c1
Packit Service 4684c1
/* Macros to aide constant time/mem checks */
Packit Service 4684c1
#define CONSTCHECK_NOT_EQUAL(a, b) ((-((uint32_t)(a) ^ (uint32_t)(b))) >> 31)
Packit Service 4684c1
#define CONSTCHECK_EQUAL(a, b) (1U - CONSTCHECK_NOT_EQUAL(a, b))
Packit Service 4684c1
Packit Service 4684c1
extern unsigned int _gnutls_global_version;
Packit Service 4684c1
Packit Service 4684c1
#endif /* GNUTLS_LIB_GNUTLS_INT_H */