buffer.h revision 262566
1/* $OpenBSD: buffer.h,v 1.23 2014/01/12 08:13:13 djm Exp $ */ 2/* $FreeBSD: stable/10/crypto/openssh/buffer.h 262566 2014-02-27 17:29:02Z des $ */ 3 4/* 5 * Author: Tatu Ylonen <ylo@cs.hut.fi> 6 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 7 * All rights reserved 8 * Code for manipulating FIFO buffers. 9 * 10 * As far as I am concerned, the code I have written for this software 11 * can be used freely for any purpose. Any derived versions of this 12 * software must be clearly marked as such, and if the derived work is 13 * incompatible with the protocol description in the RFC file, it must be 14 * called by a name other than "ssh" or "Secure Shell". 15 */ 16 17#ifndef BUFFER_H 18#define BUFFER_H 19 20typedef struct { 21 u_char *buf; /* Buffer for data. */ 22 u_int alloc; /* Number of bytes allocated for data. */ 23 u_int offset; /* Offset of first byte containing data. */ 24 u_int end; /* Offset of last byte containing data. */ 25} Buffer; 26 27void buffer_init(Buffer *); 28void buffer_clear(Buffer *); 29void buffer_free(Buffer *); 30 31u_int buffer_len(const Buffer *); 32void *buffer_ptr(const Buffer *); 33 34void buffer_append(Buffer *, const void *, u_int); 35void *buffer_append_space(Buffer *, u_int); 36 37int buffer_check_alloc(Buffer *, u_int); 38 39void buffer_get(Buffer *, void *, u_int); 40 41void buffer_consume(Buffer *, u_int); 42void buffer_consume_end(Buffer *, u_int); 43 44void buffer_dump(const Buffer *); 45 46int buffer_get_ret(Buffer *, void *, u_int); 47int buffer_consume_ret(Buffer *, u_int); 48int buffer_consume_end_ret(Buffer *, u_int); 49 50u_int buffer_get_max_len(void); 51 52#include <openssl/bn.h> 53 54void buffer_put_bignum(Buffer *, const BIGNUM *); 55void buffer_put_bignum2(Buffer *, const BIGNUM *); 56void buffer_get_bignum(Buffer *, BIGNUM *); 57void buffer_get_bignum2(Buffer *, BIGNUM *); 58 59u_short buffer_get_short(Buffer *); 60void buffer_put_short(Buffer *, u_short); 61 62u_int buffer_get_int(Buffer *); 63void buffer_put_int(Buffer *, u_int); 64 65u_int64_t buffer_get_int64(Buffer *); 66void buffer_put_int64(Buffer *, u_int64_t); 67 68int buffer_get_char(Buffer *); 69void buffer_put_char(Buffer *, int); 70 71void *buffer_get_string(Buffer *, u_int *); 72void *buffer_get_string_ptr(Buffer *, u_int *); 73void buffer_put_string(Buffer *, const void *, u_int); 74char *buffer_get_cstring(Buffer *, u_int *); 75void buffer_put_cstring(Buffer *, const char *); 76 77#define buffer_skip_string(b) \ 78 do { u_int l = buffer_get_int(b); buffer_consume(b, l); } while (0) 79 80int buffer_put_bignum_ret(Buffer *, const BIGNUM *); 81int buffer_get_bignum_ret(Buffer *, BIGNUM *); 82int buffer_put_bignum2_ret(Buffer *, const BIGNUM *); 83int buffer_get_bignum2_ret(Buffer *, BIGNUM *); 84int buffer_get_short_ret(u_short *, Buffer *); 85int buffer_get_int_ret(u_int *, Buffer *); 86int buffer_get_int64_ret(u_int64_t *, Buffer *); 87void *buffer_get_string_ret(Buffer *, u_int *); 88char *buffer_get_cstring_ret(Buffer *, u_int *); 89void *buffer_get_string_ptr_ret(Buffer *, u_int *); 90int buffer_get_char_ret(u_char *, Buffer *); 91 92void *buffer_get_bignum2_as_string_ret(Buffer *, u_int *); 93void *buffer_get_bignum2_as_string(Buffer *, u_int *); 94void buffer_put_bignum2_from_string(Buffer *, const u_char *, u_int); 95 96#ifdef OPENSSL_HAS_ECC 97#include <openssl/ec.h> 98 99int buffer_put_ecpoint_ret(Buffer *, const EC_GROUP *, const EC_POINT *); 100void buffer_put_ecpoint(Buffer *, const EC_GROUP *, const EC_POINT *); 101int buffer_get_ecpoint_ret(Buffer *, const EC_GROUP *, EC_POINT *); 102void buffer_get_ecpoint(Buffer *, const EC_GROUP *, EC_POINT *); 103#endif 104 105#endif /* BUFFER_H */ 106