1 /* $OpenBSD: buffer.h,v 1.25 2014/04/30 05:29:56 djm Exp $ */
4 * Copyright (c) 2012 Damien Miller <djm@mindrot.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 /* Emulation wrappers for legacy OpenSSH buffer API atop sshbuf */
26 typedef struct sshbuf Buffer
;
28 #define buffer_init(b) sshbuf_init(b)
29 #define buffer_clear(b) sshbuf_reset(b)
30 #define buffer_free(b) sshbuf_free(b)
31 #define buffer_dump(b) sshbuf_dump(b, stderr)
33 /* XXX cast is safe: sshbuf never stores more than len 2^31 */
34 #define buffer_len(b) ((u_int) sshbuf_len(b))
35 #define buffer_ptr(b) sshbuf_mutable_ptr(b)
37 void buffer_append(Buffer
*, const void *, u_int
);
38 void *buffer_append_space(Buffer
*, u_int
);
39 int buffer_check_alloc(Buffer
*, u_int
);
40 void buffer_get(Buffer
*, void *, u_int
);
42 void buffer_consume(Buffer
*, u_int
);
43 void buffer_consume_end(Buffer
*, u_int
);
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 #include <openssl/bn.h>
51 void buffer_put_bignum(Buffer
*, const BIGNUM
*);
52 void buffer_put_bignum2(Buffer
*, const BIGNUM
*);
53 void buffer_get_bignum(Buffer
*, BIGNUM
*);
54 void buffer_get_bignum2(Buffer
*, BIGNUM
*);
55 void buffer_put_bignum2_from_string(Buffer
*, const u_char
*, u_int
);
57 u_short
buffer_get_short(Buffer
*);
58 void buffer_put_short(Buffer
*, u_short
);
60 u_int
buffer_get_int(Buffer
*);
61 void buffer_put_int(Buffer
*, u_int
);
63 u_int64_t
buffer_get_int64(Buffer
*);
64 void buffer_put_int64(Buffer
*, u_int64_t
);
66 int buffer_get_char(Buffer
*);
67 void buffer_put_char(Buffer
*, int);
69 void *buffer_get_string(Buffer
*, u_int
*);
70 const void *buffer_get_string_ptr(Buffer
*, u_int
*);
71 void buffer_put_string(Buffer
*, const void *, u_int
);
72 char *buffer_get_cstring(Buffer
*, u_int
*);
73 void buffer_put_cstring(Buffer
*, const char *);
75 #define buffer_skip_string(b) (void)buffer_get_string_ptr(b, NULL);
77 int buffer_put_bignum_ret(Buffer
*, const BIGNUM
*);
78 int buffer_get_bignum_ret(Buffer
*, BIGNUM
*);
79 int buffer_put_bignum2_ret(Buffer
*, const BIGNUM
*);
80 int buffer_get_bignum2_ret(Buffer
*, BIGNUM
*);
81 int buffer_get_short_ret(u_short
*, Buffer
*);
82 int buffer_get_int_ret(u_int
*, Buffer
*);
83 int buffer_get_int64_ret(u_int64_t
*, Buffer
*);
84 void *buffer_get_string_ret(Buffer
*, u_int
*);
85 char *buffer_get_cstring_ret(Buffer
*, u_int
*);
86 const void *buffer_get_string_ptr_ret(Buffer
*, u_int
*);
87 int buffer_get_char_ret(char *, Buffer
*);
89 #ifdef OPENSSL_HAS_ECC
90 #include <openssl/ec.h>
91 int buffer_put_ecpoint_ret(Buffer
*, const EC_GROUP
*, const EC_POINT
*);
92 void buffer_put_ecpoint(Buffer
*, const EC_GROUP
*, const EC_POINT
*);
93 int buffer_get_ecpoint_ret(Buffer
*, const EC_GROUP
*, EC_POINT
*);
94 void buffer_get_ecpoint(Buffer
*, const EC_GROUP
*, EC_POINT
*);