blob: 56174394c959c06f5f89f8629491cc591c843b11 [file] [log] [blame]
djm@openbsd.org3d6d09f2017-04-30 23:23:54 +00001/* $OpenBSD: buffer.h,v 1.26 2017/04/30 23:23:54 djm Exp $ */
Ben Lindstrom05764b92002-03-05 01:53:02 +00002
Damien Millerd4a8b7e1999-10-27 13:42:43 +10003/*
Damien Miller05e82c32014-05-15 14:33:43 +10004 * Copyright (c) 2012 Damien Miller <djm@mindrot.org>
Damien Miller5f056372000-04-16 12:31:48 +10005 *
Damien Miller05e82c32014-05-15 14:33:43 +10006 * 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.
9 *
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.
Damien Miller95def091999-11-25 00:26:21 +110017 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100018
Damien Miller05e82c32014-05-15 14:33:43 +100019/* Emulation wrappers for legacy OpenSSH buffer API atop sshbuf */
20
Damien Millerd4a8b7e1999-10-27 13:42:43 +100021#ifndef BUFFER_H
22#define BUFFER_H
23
Damien Miller05e82c32014-05-15 14:33:43 +100024#include "sshbuf.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100025
Damien Miller05e82c32014-05-15 14:33:43 +100026typedef struct sshbuf Buffer;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100027
Damien Miller05e82c32014-05-15 14:33:43 +100028#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)
32
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)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100036
Damien Miller5a6b4fe2001-12-21 14:56:54 +110037void buffer_append(Buffer *, const void *, u_int);
38void *buffer_append_space(Buffer *, u_int);
Damien Miller499a0d52006-04-23 12:06:03 +100039int buffer_check_alloc(Buffer *, u_int);
Damien Miller5a6b4fe2001-12-21 14:56:54 +110040void buffer_get(Buffer *, void *, u_int);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100041
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000042void buffer_consume(Buffer *, u_int);
43void buffer_consume_end(Buffer *, u_int);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100044
Damien Millerd4a8b7e1999-10-27 13:42:43 +100045
Darren Tucker50dbe832004-11-05 20:41:24 +110046int buffer_get_ret(Buffer *, void *, u_int);
47int buffer_consume_ret(Buffer *, u_int);
48int buffer_consume_end_ret(Buffer *, u_int);
49
Darren Tuckeref342ab2015-02-24 13:39:57 +110050#include <openssl/objects.h>
Damien Millerd7834352006-08-05 12:39:39 +100051#include <openssl/bn.h>
Damien Millerd7834352006-08-05 12:39:39 +100052void buffer_put_bignum2(Buffer *, const BIGNUM *);
Damien Millerd7834352006-08-05 12:39:39 +100053void buffer_get_bignum2(Buffer *, BIGNUM *);
Damien Miller05e82c32014-05-15 14:33:43 +100054void buffer_put_bignum2_from_string(Buffer *, const u_char *, u_int);
Damien Millerd7834352006-08-05 12:39:39 +100055
56u_short buffer_get_short(Buffer *);
57void buffer_put_short(Buffer *, u_short);
58
59u_int buffer_get_int(Buffer *);
60void buffer_put_int(Buffer *, u_int);
61
62u_int64_t buffer_get_int64(Buffer *);
63void buffer_put_int64(Buffer *, u_int64_t);
64
65int buffer_get_char(Buffer *);
66void buffer_put_char(Buffer *, int);
67
68void *buffer_get_string(Buffer *, u_int *);
Damien Miller633de332014-05-15 13:48:26 +100069const void *buffer_get_string_ptr(Buffer *, u_int *);
Damien Millerd7834352006-08-05 12:39:39 +100070void buffer_put_string(Buffer *, const void *, u_int);
Damien Millerda108ec2010-08-31 22:36:39 +100071char *buffer_get_cstring(Buffer *, u_int *);
Damien Millerd7834352006-08-05 12:39:39 +100072void buffer_put_cstring(Buffer *, const char *);
73
Damien Miller05e82c32014-05-15 14:33:43 +100074#define buffer_skip_string(b) (void)buffer_get_string_ptr(b, NULL);
Damien Millerd7834352006-08-05 12:39:39 +100075
Damien Millerd7834352006-08-05 12:39:39 +100076int buffer_put_bignum2_ret(Buffer *, const BIGNUM *);
77int buffer_get_bignum2_ret(Buffer *, BIGNUM *);
78int buffer_get_short_ret(u_short *, Buffer *);
79int buffer_get_int_ret(u_int *, Buffer *);
80int buffer_get_int64_ret(u_int64_t *, Buffer *);
81void *buffer_get_string_ret(Buffer *, u_int *);
Damien Millerda108ec2010-08-31 22:36:39 +100082char *buffer_get_cstring_ret(Buffer *, u_int *);
Damien Miller633de332014-05-15 13:48:26 +100083const void *buffer_get_string_ptr_ret(Buffer *, u_int *);
Damien Miller05e82c32014-05-15 14:33:43 +100084int buffer_get_char_ret(char *, Buffer *);
Damien Miller91b580e2014-01-12 19:21:22 +110085
Damien Miller6af914a2010-09-10 11:39:26 +100086#ifdef OPENSSL_HAS_ECC
Damien Millereb8b60e2010-08-31 22:41:14 +100087#include <openssl/ec.h>
Damien Millereb8b60e2010-08-31 22:41:14 +100088int buffer_put_ecpoint_ret(Buffer *, const EC_GROUP *, const EC_POINT *);
89void buffer_put_ecpoint(Buffer *, const EC_GROUP *, const EC_POINT *);
90int buffer_get_ecpoint_ret(Buffer *, const EC_GROUP *, EC_POINT *);
91void buffer_get_ecpoint(Buffer *, const EC_GROUP *, EC_POINT *);
Damien Miller6af914a2010-09-10 11:39:26 +100092#endif
Damien Millereb8b60e2010-08-31 22:41:14 +100093
Damien Miller05e82c32014-05-15 14:33:43 +100094#endif /* BUFFER_H */
95