Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 1 | /* $OpenBSD: buffer.h,v 1.25 2014/04/30 05:29:56 djm Exp $ */ |
Ben Lindstrom | 05764b9 | 2002-03-05 01:53:02 +0000 | [diff] [blame] | 2 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 3 | /* |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 4 | * Copyright (c) 2012 Damien Miller <djm@mindrot.org> |
Damien Miller | 5f05637 | 2000-04-16 12:31:48 +1000 | [diff] [blame] | 5 | * |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 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. |
| 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 Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 17 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 18 | |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 19 | /* Emulation wrappers for legacy OpenSSH buffer API atop sshbuf */ |
| 20 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 21 | #ifndef BUFFER_H |
| 22 | #define BUFFER_H |
| 23 | |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 24 | #include "sshbuf.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 25 | |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 26 | typedef struct sshbuf Buffer; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 27 | |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 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) |
| 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 Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 36 | |
Damien Miller | 5a6b4fe | 2001-12-21 14:56:54 +1100 | [diff] [blame] | 37 | void buffer_append(Buffer *, const void *, u_int); |
| 38 | void *buffer_append_space(Buffer *, u_int); |
Damien Miller | 499a0d5 | 2006-04-23 12:06:03 +1000 | [diff] [blame] | 39 | int buffer_check_alloc(Buffer *, u_int); |
Damien Miller | 5a6b4fe | 2001-12-21 14:56:54 +1100 | [diff] [blame] | 40 | void buffer_get(Buffer *, void *, u_int); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 41 | |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 42 | void buffer_consume(Buffer *, u_int); |
| 43 | void buffer_consume_end(Buffer *, u_int); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 44 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 45 | |
Darren Tucker | 50dbe83 | 2004-11-05 20:41:24 +1100 | [diff] [blame] | 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); |
| 49 | |
Darren Tucker | ef342ab | 2015-02-24 13:39:57 +1100 | [diff] [blame] | 50 | #include <openssl/objects.h> |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 51 | #include <openssl/bn.h> |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 52 | void buffer_put_bignum(Buffer *, const BIGNUM *); |
| 53 | void buffer_put_bignum2(Buffer *, const BIGNUM *); |
| 54 | void buffer_get_bignum(Buffer *, BIGNUM *); |
| 55 | void buffer_get_bignum2(Buffer *, BIGNUM *); |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 56 | void buffer_put_bignum2_from_string(Buffer *, const u_char *, u_int); |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 57 | |
| 58 | u_short buffer_get_short(Buffer *); |
| 59 | void buffer_put_short(Buffer *, u_short); |
| 60 | |
| 61 | u_int buffer_get_int(Buffer *); |
| 62 | void buffer_put_int(Buffer *, u_int); |
| 63 | |
| 64 | u_int64_t buffer_get_int64(Buffer *); |
| 65 | void buffer_put_int64(Buffer *, u_int64_t); |
| 66 | |
| 67 | int buffer_get_char(Buffer *); |
| 68 | void buffer_put_char(Buffer *, int); |
| 69 | |
| 70 | void *buffer_get_string(Buffer *, u_int *); |
Damien Miller | 633de33 | 2014-05-15 13:48:26 +1000 | [diff] [blame] | 71 | const void *buffer_get_string_ptr(Buffer *, u_int *); |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 72 | void buffer_put_string(Buffer *, const void *, u_int); |
Damien Miller | da108ec | 2010-08-31 22:36:39 +1000 | [diff] [blame] | 73 | char *buffer_get_cstring(Buffer *, u_int *); |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 74 | void buffer_put_cstring(Buffer *, const char *); |
| 75 | |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 76 | #define buffer_skip_string(b) (void)buffer_get_string_ptr(b, NULL); |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 77 | |
| 78 | int buffer_put_bignum_ret(Buffer *, const BIGNUM *); |
| 79 | int buffer_get_bignum_ret(Buffer *, BIGNUM *); |
| 80 | int buffer_put_bignum2_ret(Buffer *, const BIGNUM *); |
| 81 | int buffer_get_bignum2_ret(Buffer *, BIGNUM *); |
| 82 | int buffer_get_short_ret(u_short *, Buffer *); |
| 83 | int buffer_get_int_ret(u_int *, Buffer *); |
| 84 | int buffer_get_int64_ret(u_int64_t *, Buffer *); |
| 85 | void *buffer_get_string_ret(Buffer *, u_int *); |
Damien Miller | da108ec | 2010-08-31 22:36:39 +1000 | [diff] [blame] | 86 | char *buffer_get_cstring_ret(Buffer *, u_int *); |
Damien Miller | 633de33 | 2014-05-15 13:48:26 +1000 | [diff] [blame] | 87 | const void *buffer_get_string_ptr_ret(Buffer *, u_int *); |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 88 | int buffer_get_char_ret(char *, Buffer *); |
Damien Miller | 91b580e | 2014-01-12 19:21:22 +1100 | [diff] [blame] | 89 | |
Damien Miller | 6af914a | 2010-09-10 11:39:26 +1000 | [diff] [blame] | 90 | #ifdef OPENSSL_HAS_ECC |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 91 | #include <openssl/ec.h> |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 92 | int buffer_put_ecpoint_ret(Buffer *, const EC_GROUP *, const EC_POINT *); |
| 93 | void buffer_put_ecpoint(Buffer *, const EC_GROUP *, const EC_POINT *); |
| 94 | int buffer_get_ecpoint_ret(Buffer *, const EC_GROUP *, EC_POINT *); |
| 95 | void buffer_get_ecpoint(Buffer *, const EC_GROUP *, EC_POINT *); |
Damien Miller | 6af914a | 2010-09-10 11:39:26 +1000 | [diff] [blame] | 96 | #endif |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 97 | |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 98 | #endif /* BUFFER_H */ |
| 99 | |