1/* $OpenBSD: buffer.h,v 1.21 2010/08/31 11:54:45 djm Exp $ */
2
3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
5 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
6 *                    All rights reserved
7 * Code for manipulating FIFO buffers.
8 *
9 * As far as I am concerned, the code I have written for this software
10 * can be used freely for any purpose.  Any derived versions of this
11 * software must be clearly marked as such, and if the derived work is
12 * incompatible with the protocol description in the RFC file, it must be
13 * called by a name other than "ssh" or "Secure Shell".
14 */
15
16#ifndef BUFFER_H
17#define BUFFER_H
18
19typedef struct {
20	u_char	*buf;		/* Buffer for data. */
21	u_int	 alloc;		/* Number of bytes allocated for data. */
22	u_int	 offset;	/* Offset of first byte containing data. */
23	u_int	 end;		/* Offset of last byte containing data. */
24}       Buffer;
25
26void	 buffer_init(Buffer *);
27void	 buffer_clear(Buffer *);
28void	 buffer_free(Buffer *);
29
30u_int	 buffer_len(const Buffer *);
31void	*buffer_ptr(const Buffer *);
32
33void	 buffer_append(Buffer *, const void *, u_int);
34void	*buffer_append_space(Buffer *, u_int);
35
36int	 buffer_check_alloc(Buffer *, u_int);
37
38void	 buffer_get(Buffer *, void *, u_int);
39
40void	 buffer_consume(Buffer *, u_int);
41void	 buffer_consume_end(Buffer *, u_int);
42
43void     buffer_dump(const Buffer *);
44
45int	 buffer_get_ret(Buffer *, void *, u_int);
46int	 buffer_consume_ret(Buffer *, u_int);
47int	 buffer_consume_end_ret(Buffer *, u_int);
48
49#ifdef __APPLE_CRYPTO__
50#include "ossl-bn.h"
51#else
52#include <openssl/bn.h>
53#endif
54
55void    buffer_put_bignum(Buffer *, const BIGNUM *);
56void    buffer_put_bignum2(Buffer *, const BIGNUM *);
57void	buffer_get_bignum(Buffer *, BIGNUM *);
58void	buffer_get_bignum2(Buffer *, BIGNUM *);
59
60u_short	buffer_get_short(Buffer *);
61void	buffer_put_short(Buffer *, u_short);
62
63u_int	buffer_get_int(Buffer *);
64void    buffer_put_int(Buffer *, u_int);
65
66u_int64_t buffer_get_int64(Buffer *);
67void	buffer_put_int64(Buffer *, u_int64_t);
68
69int     buffer_get_char(Buffer *);
70void    buffer_put_char(Buffer *, int);
71
72void   *buffer_get_string(Buffer *, u_int *);
73void   *buffer_get_string_ptr(Buffer *, u_int *);
74void    buffer_put_string(Buffer *, const void *, u_int);
75char   *buffer_get_cstring(Buffer *, u_int *);
76void	buffer_put_cstring(Buffer *, const char *);
77
78#define buffer_skip_string(b) \
79    do { u_int l = buffer_get_int(b); buffer_consume(b, l); } while (0)
80
81int	buffer_put_bignum_ret(Buffer *, const BIGNUM *);
82int	buffer_get_bignum_ret(Buffer *, BIGNUM *);
83int	buffer_put_bignum2_ret(Buffer *, const BIGNUM *);
84int	buffer_get_bignum2_ret(Buffer *, BIGNUM *);
85int	buffer_get_short_ret(u_short *, Buffer *);
86int	buffer_get_int_ret(u_int *, Buffer *);
87int	buffer_get_int64_ret(u_int64_t *, Buffer *);
88void	*buffer_get_string_ret(Buffer *, u_int *);
89char	*buffer_get_cstring_ret(Buffer *, u_int *);
90void	*buffer_get_string_ptr_ret(Buffer *, u_int *);
91int	buffer_get_char_ret(char *, Buffer *);
92
93#ifdef OPENSSL_HAS_ECC
94#include <openssl/ec.h>
95
96int	buffer_put_ecpoint_ret(Buffer *, const EC_GROUP *, const EC_POINT *);
97void	buffer_put_ecpoint(Buffer *, const EC_GROUP *, const EC_POINT *);
98int	buffer_get_ecpoint_ret(Buffer *, const EC_GROUP *, EC_POINT *);
99void	buffer_get_ecpoint(Buffer *, const EC_GROUP *, EC_POINT *);
100#endif
101
102#endif				/* BUFFER_H */
103