1 /* $OpenBSD: buffer.h,v 1.23 2014/01/12 08:13:13 djm Exp $ */
5 * Author: Tatu Ylonen <ylo@cs.hut.fi>
6 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8 * Code for manipulating FIFO buffers.
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".
21 u_char *buf; /* Buffer for data. */
22 u_int alloc; /* Number of bytes allocated for data. */
23 u_int offset; /* Offset of first byte containing data. */
24 u_int end; /* Offset of last byte containing data. */
27 void buffer_init(Buffer *);
28 void buffer_clear(Buffer *);
29 void buffer_free(Buffer *);
31 u_int buffer_len(const Buffer *);
32 void *buffer_ptr(const Buffer *);
34 void buffer_append(Buffer *, const void *, u_int);
35 void *buffer_append_space(Buffer *, u_int);
37 int buffer_check_alloc(Buffer *, u_int);
39 void buffer_get(Buffer *, void *, u_int);
41 void buffer_consume(Buffer *, u_int);
42 void buffer_consume_end(Buffer *, u_int);
44 void buffer_dump(const Buffer *);
46 int buffer_get_ret(Buffer *, void *, u_int);
47 int buffer_consume_ret(Buffer *, u_int);
48 int buffer_consume_end_ret(Buffer *, u_int);
50 u_int buffer_get_max_len(void);
52 #include <openssl/bn.h>
54 void buffer_put_bignum(Buffer *, const BIGNUM *);
55 void buffer_put_bignum2(Buffer *, const BIGNUM *);
56 void buffer_get_bignum(Buffer *, BIGNUM *);
57 void buffer_get_bignum2(Buffer *, BIGNUM *);
59 u_short buffer_get_short(Buffer *);
60 void buffer_put_short(Buffer *, u_short);
62 u_int buffer_get_int(Buffer *);
63 void buffer_put_int(Buffer *, u_int);
65 u_int64_t buffer_get_int64(Buffer *);
66 void buffer_put_int64(Buffer *, u_int64_t);
68 int buffer_get_char(Buffer *);
69 void buffer_put_char(Buffer *, int);
71 void *buffer_get_string(Buffer *, u_int *);
72 void *buffer_get_string_ptr(Buffer *, u_int *);
73 void buffer_put_string(Buffer *, const void *, u_int);
74 char *buffer_get_cstring(Buffer *, u_int *);
75 void buffer_put_cstring(Buffer *, const char *);
77 #define buffer_skip_string(b) \
78 do { u_int l = buffer_get_int(b); buffer_consume(b, l); } while (0)
80 int buffer_put_bignum_ret(Buffer *, const BIGNUM *);
81 int buffer_get_bignum_ret(Buffer *, BIGNUM *);
82 int buffer_put_bignum2_ret(Buffer *, const BIGNUM *);
83 int buffer_get_bignum2_ret(Buffer *, BIGNUM *);
84 int buffer_get_short_ret(u_short *, Buffer *);
85 int buffer_get_int_ret(u_int *, Buffer *);
86 int buffer_get_int64_ret(u_int64_t *, Buffer *);
87 void *buffer_get_string_ret(Buffer *, u_int *);
88 char *buffer_get_cstring_ret(Buffer *, u_int *);
89 void *buffer_get_string_ptr_ret(Buffer *, u_int *);
90 int buffer_get_char_ret(u_char *, Buffer *);
92 void *buffer_get_bignum2_as_string_ret(Buffer *, u_int *);
93 void *buffer_get_bignum2_as_string(Buffer *, u_int *);
94 void buffer_put_bignum2_from_string(Buffer *, const u_char *, u_int);
96 #ifdef OPENSSL_HAS_ECC
97 #include <openssl/ec.h>
99 int buffer_put_ecpoint_ret(Buffer *, const EC_GROUP *, const EC_POINT *);
100 void buffer_put_ecpoint(Buffer *, const EC_GROUP *, const EC_POINT *);
101 int buffer_get_ecpoint_ret(Buffer *, const EC_GROUP *, EC_POINT *);
102 void buffer_get_ecpoint(Buffer *, const EC_GROUP *, EC_POINT *);
105 #endif /* BUFFER_H */