1/* $OpenBSD: packet.h,v 1.59 2013/07/12 00:19:59 djm Exp $ */
2/* $FreeBSD$ */
3
4/*
5 * Author: Tatu Ylonen <ylo@cs.hut.fi>
6 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
7 *                    All rights reserved
8 * Interface for the packet protocol functions.
9 *
10 * As far as I am concerned, the code I have written for this software
11 * can be used freely for any purpose.  Any derived versions of this
12 * software must be clearly marked as such, and if the derived work is
13 * incompatible with the protocol description in the RFC file, it must be
14 * called by a name other than "ssh" or "Secure Shell".
15 */
16
17#ifndef PACKET_H
18#define PACKET_H
19
20#include <termios.h>
21
22#include <openssl/bn.h>
23#ifdef OPENSSL_HAS_ECC
24#include <openssl/ec.h>
25#endif
26
27void     packet_set_connection(int, int);
28void     packet_set_timeout(int, int);
29void     packet_set_nonblocking(void);
30int      packet_get_connection_in(void);
31int      packet_get_connection_out(void);
32void     packet_close(void);
33void	 packet_set_encryption_key(const u_char *, u_int, int);
34u_int	 packet_get_encryption_key(u_char *);
35void     packet_set_protocol_flags(u_int);
36u_int	 packet_get_protocol_flags(void);
37void     packet_start_compression(int);
38void     packet_set_interactive(int, int, int);
39int      packet_is_interactive(void);
40void     packet_set_server(void);
41void     packet_set_authenticated(void);
42#ifdef	NONE_CIPHER_ENABLED
43int      packet_get_authentication_state(void);
44#endif
45
46void     packet_start(u_char);
47void     packet_put_char(int ch);
48void     packet_put_int(u_int value);
49void     packet_put_int64(u_int64_t value);
50void     packet_put_bignum(BIGNUM * value);
51void     packet_put_bignum2(BIGNUM * value);
52#ifdef OPENSSL_HAS_ECC
53void     packet_put_ecpoint(const EC_GROUP *, const EC_POINT *);
54#endif
55void     packet_put_string(const void *buf, u_int len);
56void     packet_put_cstring(const char *str);
57void     packet_put_raw(const void *buf, u_int len);
58void     packet_send(void);
59
60int      packet_read(void);
61void     packet_read_expect(int type);
62void     packet_process_incoming(const char *buf, u_int len);
63int      packet_read_seqnr(u_int32_t *seqnr_p);
64int      packet_read_poll_seqnr(u_int32_t *seqnr_p);
65
66u_int	 packet_get_char(void);
67u_int	 packet_get_int(void);
68u_int64_t packet_get_int64(void);
69void     packet_get_bignum(BIGNUM * value);
70void     packet_get_bignum2(BIGNUM * value);
71#ifdef OPENSSL_HAS_ECC
72void	 packet_get_ecpoint(const EC_GROUP *, EC_POINT *);
73#endif
74void	*packet_get_raw(u_int *length_ptr);
75void	*packet_get_string(u_int *length_ptr);
76char	*packet_get_cstring(u_int *length_ptr);
77void	*packet_get_string_ptr(u_int *length_ptr);
78void     packet_disconnect(const char *fmt,...) __attribute__((noreturn)) __attribute__((format(printf, 1, 2)));
79void     packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2)));
80
81void	 set_newkeys(int mode);
82int	 packet_get_keyiv_len(int);
83void	 packet_get_keyiv(int, u_char *, u_int);
84int	 packet_get_keycontext(int, u_char *);
85void	 packet_set_keycontext(int, u_char *);
86void	 packet_get_state(int, u_int32_t *, u_int64_t *, u_int32_t *, u_int64_t *);
87void	 packet_set_state(int, u_int32_t, u_int64_t, u_int32_t, u_int64_t);
88int	 packet_get_ssh1_cipher(void);
89void	 packet_set_iv(int, u_char *);
90void	*packet_get_newkeys(int);
91
92void     packet_write_poll(void);
93void     packet_write_wait(void);
94int      packet_have_data_to_write(void);
95int      packet_not_very_much_data_to_write(void);
96
97int	 packet_connection_is_on_socket(void);
98int	 packet_remaining(void);
99void	 packet_send_ignore(int);
100void	 packet_add_padding(u_char);
101
102void	 tty_make_modes(int, struct termios *);
103void	 tty_parse_modes(int, int *);
104
105void	 packet_set_alive_timeouts(int);
106int	 packet_inc_alive_timeouts(void);
107int	 packet_set_maxsize(u_int);
108u_int	 packet_get_maxsize(void);
109
110/* don't allow remaining bytes after the end of the message */
111#define packet_check_eom() \
112do { \
113	int _len = packet_remaining(); \
114	if (_len > 0) { \
115		logit("Packet integrity error (%d bytes remaining) at %s:%d", \
116		    _len ,__FILE__, __LINE__); \
117		packet_disconnect("Packet integrity error."); \
118	} \
119} while (0)
120
121int	 packet_need_rekeying(void);
122#ifdef	NONE_CIPHER_ENABLED
123void	 packet_request_rekeying(void);
124#endif
125void	 packet_set_rekey_limits(u_int32_t, time_t);
126time_t	 packet_get_rekey_timeout(void);
127
128void	 packet_backup_state(void);
129void	 packet_restore_state(void);
130
131void	*packet_get_input(void);
132void	*packet_get_output(void);
133
134#endif				/* PACKET_H */
135