blob: 9d853edf2da21729d4536b0b7bcbeee3244a18de [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
Damien Millerd7834352006-08-05 12:39:39 +100050#include <openssl/bn.h>
Damien Millerd7834352006-08-05 12:39:39 +100051void buffer_put_bignum(Buffer *, const BIGNUM *);
52void buffer_put_bignum2(Buffer *, const BIGNUM *);
53void buffer_get_bignum(Buffer *, BIGNUM *);
54void buffer_get_bignum2(Buffer *, BIGNUM *);
Damien Miller05e82c32014-05-15 14:33:43 +100055void buffer_put_bignum2_from_string(Buffer *, const u_char *, u_int);
Damien Millerd7834352006-08-05 12:39:39 +100056
57u_short buffer_get_short(Buffer *);
58void buffer_put_short(Buffer *, u_short);
59
60u_int buffer_get_int(Buffer *);
61void buffer_put_int(Buffer *, u_int);
62
63u_int64_t buffer_get_int64(Buffer *);
64void buffer_put_int64(Buffer *, u_int64_t);
65
66int buffer_get_char(Buffer *);
67void buffer_put_char(Buffer *, int);
68
69void *buffer_get_string(Buffer *, u_int *);
Damien Miller633de332014-05-15 13:48:26 +100070const void *buffer_get_string_ptr(Buffer *, u_int *);
Damien Millerd7834352006-08-05 12:39:39 +100071void buffer_put_string(Buffer *, const void *, u_int);
Damien Millerda108ec2010-08-31 22:36:39 +100072char *buffer_get_cstring(Buffer *, u_int *);
Damien Millerd7834352006-08-05 12:39:39 +100073void buffer_put_cstring(Buffer *, const char *);
74
Damien Miller05e82c32014-05-15 14:33:43 +100075#define buffer_skip_string(b) (void)buffer_get_string_ptr(b, NULL);
Damien Millerd7834352006-08-05 12:39:39 +100076
77int buffer_put_bignum_ret(Buffer *, const BIGNUM *);
78int buffer_get_bignum_ret(Buffer *, BIGNUM *);
79int buffer_put_bignum2_ret(Buffer *, const BIGNUM *);
80int buffer_get_bignum2_ret(Buffer *, BIGNUM *);
81int buffer_get_short_ret(u_short *, Buffer *);
82int buffer_get_int_ret(u_int *, Buffer *);
83int buffer_get_int64_ret(u_int64_t *, Buffer *);
84void *buffer_get_string_ret(Buffer *, u_int *);
Damien Millerda108ec2010-08-31 22:36:39 +100085char *buffer_get_cstring_ret(Buffer *, u_int *);
Damien Miller633de332014-05-15 13:48:26 +100086const void *buffer_get_string_ptr_ret(Buffer *, u_int *);
Damien Miller05e82c32014-05-15 14:33:43 +100087int buffer_get_char_ret(char *, Buffer *);
Damien Miller91b580e2014-01-12 19:21:22 +110088
Damien Miller6af914a2010-09-10 11:39:26 +100089#ifdef OPENSSL_HAS_ECC
Damien Millereb8b60e2010-08-31 22:41:14 +100090#include <openssl/ec.h>
Damien Millereb8b60e2010-08-31 22:41:14 +100091int buffer_put_ecpoint_ret(Buffer *, const EC_GROUP *, const EC_POINT *);
92void buffer_put_ecpoint(Buffer *, const EC_GROUP *, const EC_POINT *);
93int buffer_get_ecpoint_ret(Buffer *, const EC_GROUP *, EC_POINT *);
94void buffer_get_ecpoint(Buffer *, const EC_GROUP *, EC_POINT *);
Damien Miller6af914a2010-09-10 11:39:26 +100095#endif
Damien Millereb8b60e2010-08-31 22:41:14 +100096
Damien Miller05e82c32014-05-15 14:33:43 +100097#endif /* BUFFER_H */
98