blob: df1aebc02cc611b654c90c2c2a9eecf7283f172b [file] [log] [blame]
Damien Miller05e82c32014-05-15 14:33:43 +10001/* $OpenBSD: buffer.h,v 1.25 2014/04/30 05:29:56 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_bignum(Buffer *, const BIGNUM *);
53void buffer_put_bignum2(Buffer *, const BIGNUM *);
54void buffer_get_bignum(Buffer *, BIGNUM *);
55void buffer_get_bignum2(Buffer *, BIGNUM *);
Damien Miller05e82c32014-05-15 14:33:43 +100056void buffer_put_bignum2_from_string(Buffer *, const u_char *, u_int);
Damien Millerd7834352006-08-05 12:39:39 +100057
58u_short buffer_get_short(Buffer *);
59void buffer_put_short(Buffer *, u_short);
60
61u_int buffer_get_int(Buffer *);
62void buffer_put_int(Buffer *, u_int);
63
64u_int64_t buffer_get_int64(Buffer *);
65void buffer_put_int64(Buffer *, u_int64_t);
66
67int buffer_get_char(Buffer *);
68void buffer_put_char(Buffer *, int);
69
70void *buffer_get_string(Buffer *, u_int *);
Damien Miller633de332014-05-15 13:48:26 +100071const void *buffer_get_string_ptr(Buffer *, u_int *);
Damien Millerd7834352006-08-05 12:39:39 +100072void buffer_put_string(Buffer *, const void *, u_int);
Damien Millerda108ec2010-08-31 22:36:39 +100073char *buffer_get_cstring(Buffer *, u_int *);
Damien Millerd7834352006-08-05 12:39:39 +100074void buffer_put_cstring(Buffer *, const char *);
75
Damien Miller05e82c32014-05-15 14:33:43 +100076#define buffer_skip_string(b) (void)buffer_get_string_ptr(b, NULL);
Damien Millerd7834352006-08-05 12:39:39 +100077
78int buffer_put_bignum_ret(Buffer *, const BIGNUM *);
79int buffer_get_bignum_ret(Buffer *, BIGNUM *);
80int buffer_put_bignum2_ret(Buffer *, const BIGNUM *);
81int buffer_get_bignum2_ret(Buffer *, BIGNUM *);
82int buffer_get_short_ret(u_short *, Buffer *);
83int buffer_get_int_ret(u_int *, Buffer *);
84int buffer_get_int64_ret(u_int64_t *, Buffer *);
85void *buffer_get_string_ret(Buffer *, u_int *);
Damien Millerda108ec2010-08-31 22:36:39 +100086char *buffer_get_cstring_ret(Buffer *, u_int *);
Damien Miller633de332014-05-15 13:48:26 +100087const void *buffer_get_string_ptr_ret(Buffer *, u_int *);
Damien Miller05e82c32014-05-15 14:33:43 +100088int buffer_get_char_ret(char *, Buffer *);
Damien Miller91b580e2014-01-12 19:21:22 +110089
Damien Miller6af914a2010-09-10 11:39:26 +100090#ifdef OPENSSL_HAS_ECC
Damien Millereb8b60e2010-08-31 22:41:14 +100091#include <openssl/ec.h>
Damien Millereb8b60e2010-08-31 22:41:14 +100092int buffer_put_ecpoint_ret(Buffer *, const EC_GROUP *, const EC_POINT *);
93void buffer_put_ecpoint(Buffer *, const EC_GROUP *, const EC_POINT *);
94int buffer_get_ecpoint_ret(Buffer *, const EC_GROUP *, EC_POINT *);
95void buffer_get_ecpoint(Buffer *, const EC_GROUP *, EC_POINT *);
Damien Miller6af914a2010-09-10 11:39:26 +100096#endif
Damien Millereb8b60e2010-08-31 22:41:14 +100097
Damien Miller05e82c32014-05-15 14:33:43 +100098#endif /* BUFFER_H */
99