xref: /dflybsd-src/crypto/libressl/include/openssl/buffer.h (revision f5b1c8a1e6dbe9333aed363dba27c2ff58be6174)
1*f5b1c8a1SJohn Marino /* $OpenBSD: buffer.h,v 1.14 2014/10/16 03:19:02 beck Exp $ */
2*f5b1c8a1SJohn Marino /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3*f5b1c8a1SJohn Marino  * All rights reserved.
4*f5b1c8a1SJohn Marino  *
5*f5b1c8a1SJohn Marino  * This package is an SSL implementation written
6*f5b1c8a1SJohn Marino  * by Eric Young (eay@cryptsoft.com).
7*f5b1c8a1SJohn Marino  * The implementation was written so as to conform with Netscapes SSL.
8*f5b1c8a1SJohn Marino  *
9*f5b1c8a1SJohn Marino  * This library is free for commercial and non-commercial use as long as
10*f5b1c8a1SJohn Marino  * the following conditions are aheared to.  The following conditions
11*f5b1c8a1SJohn Marino  * apply to all code found in this distribution, be it the RC4, RSA,
12*f5b1c8a1SJohn Marino  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13*f5b1c8a1SJohn Marino  * included with this distribution is covered by the same copyright terms
14*f5b1c8a1SJohn Marino  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15*f5b1c8a1SJohn Marino  *
16*f5b1c8a1SJohn Marino  * Copyright remains Eric Young's, and as such any Copyright notices in
17*f5b1c8a1SJohn Marino  * the code are not to be removed.
18*f5b1c8a1SJohn Marino  * If this package is used in a product, Eric Young should be given attribution
19*f5b1c8a1SJohn Marino  * as the author of the parts of the library used.
20*f5b1c8a1SJohn Marino  * This can be in the form of a textual message at program startup or
21*f5b1c8a1SJohn Marino  * in documentation (online or textual) provided with the package.
22*f5b1c8a1SJohn Marino  *
23*f5b1c8a1SJohn Marino  * Redistribution and use in source and binary forms, with or without
24*f5b1c8a1SJohn Marino  * modification, are permitted provided that the following conditions
25*f5b1c8a1SJohn Marino  * are met:
26*f5b1c8a1SJohn Marino  * 1. Redistributions of source code must retain the copyright
27*f5b1c8a1SJohn Marino  *    notice, this list of conditions and the following disclaimer.
28*f5b1c8a1SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
29*f5b1c8a1SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
30*f5b1c8a1SJohn Marino  *    documentation and/or other materials provided with the distribution.
31*f5b1c8a1SJohn Marino  * 3. All advertising materials mentioning features or use of this software
32*f5b1c8a1SJohn Marino  *    must display the following acknowledgement:
33*f5b1c8a1SJohn Marino  *    "This product includes cryptographic software written by
34*f5b1c8a1SJohn Marino  *     Eric Young (eay@cryptsoft.com)"
35*f5b1c8a1SJohn Marino  *    The word 'cryptographic' can be left out if the rouines from the library
36*f5b1c8a1SJohn Marino  *    being used are not cryptographic related :-).
37*f5b1c8a1SJohn Marino  * 4. If you include any Windows specific code (or a derivative thereof) from
38*f5b1c8a1SJohn Marino  *    the apps directory (application code) you must include an acknowledgement:
39*f5b1c8a1SJohn Marino  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40*f5b1c8a1SJohn Marino  *
41*f5b1c8a1SJohn Marino  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42*f5b1c8a1SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43*f5b1c8a1SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44*f5b1c8a1SJohn Marino  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45*f5b1c8a1SJohn Marino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46*f5b1c8a1SJohn Marino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47*f5b1c8a1SJohn Marino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48*f5b1c8a1SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49*f5b1c8a1SJohn Marino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50*f5b1c8a1SJohn Marino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51*f5b1c8a1SJohn Marino  * SUCH DAMAGE.
52*f5b1c8a1SJohn Marino  *
53*f5b1c8a1SJohn Marino  * The licence and distribution terms for any publically available version or
54*f5b1c8a1SJohn Marino  * derivative of this code cannot be changed.  i.e. this code cannot simply be
55*f5b1c8a1SJohn Marino  * copied and put under another distribution licence
56*f5b1c8a1SJohn Marino  * [including the GNU Public Licence.]
57*f5b1c8a1SJohn Marino  */
58*f5b1c8a1SJohn Marino 
59*f5b1c8a1SJohn Marino #ifndef HEADER_BUFFER_H
60*f5b1c8a1SJohn Marino #define HEADER_BUFFER_H
61*f5b1c8a1SJohn Marino #if !defined(HAVE_ATTRIBUTE__BOUNDED__) && !defined(__OpenBSD__)
62*f5b1c8a1SJohn Marino #define __bounded__(x, y, z)
63*f5b1c8a1SJohn Marino #endif
64*f5b1c8a1SJohn Marino 
65*f5b1c8a1SJohn Marino #include <openssl/ossl_typ.h>
66*f5b1c8a1SJohn Marino 
67*f5b1c8a1SJohn Marino #ifdef  __cplusplus
68*f5b1c8a1SJohn Marino extern "C" {
69*f5b1c8a1SJohn Marino #endif
70*f5b1c8a1SJohn Marino 
71*f5b1c8a1SJohn Marino #include <stddef.h>
72*f5b1c8a1SJohn Marino #include <sys/types.h>
73*f5b1c8a1SJohn Marino 
74*f5b1c8a1SJohn Marino /* Already declared in ossl_typ.h */
75*f5b1c8a1SJohn Marino /* typedef struct buf_mem_st BUF_MEM; */
76*f5b1c8a1SJohn Marino 
77*f5b1c8a1SJohn Marino struct buf_mem_st {
78*f5b1c8a1SJohn Marino 	size_t length;	/* current number of bytes */
79*f5b1c8a1SJohn Marino 	char *data;
80*f5b1c8a1SJohn Marino 	size_t max;	/* size of buffer */
81*f5b1c8a1SJohn Marino };
82*f5b1c8a1SJohn Marino 
83*f5b1c8a1SJohn Marino BUF_MEM *BUF_MEM_new(void);
84*f5b1c8a1SJohn Marino void	BUF_MEM_free(BUF_MEM *a);
85*f5b1c8a1SJohn Marino int	BUF_MEM_grow(BUF_MEM *str, size_t len);
86*f5b1c8a1SJohn Marino int	BUF_MEM_grow_clean(BUF_MEM *str, size_t len);
87*f5b1c8a1SJohn Marino 
88*f5b1c8a1SJohn Marino #ifndef LIBRESSL_INTERNAL
89*f5b1c8a1SJohn Marino char *	BUF_strdup(const char *str);
90*f5b1c8a1SJohn Marino char *	BUF_strndup(const char *str, size_t siz);
91*f5b1c8a1SJohn Marino void *	BUF_memdup(const void *data, size_t siz);
92*f5b1c8a1SJohn Marino void	BUF_reverse(unsigned char *out, const unsigned char *in, size_t siz);
93*f5b1c8a1SJohn Marino 
94*f5b1c8a1SJohn Marino /* safe string functions */
95*f5b1c8a1SJohn Marino size_t BUF_strlcpy(char *dst, const char *src, size_t siz)
96*f5b1c8a1SJohn Marino 	__attribute__ ((__bounded__(__string__,1,3)));
97*f5b1c8a1SJohn Marino size_t BUF_strlcat(char *dst, const char *src, size_t siz)
98*f5b1c8a1SJohn Marino 	__attribute__ ((__bounded__(__string__,1,3)));
99*f5b1c8a1SJohn Marino #endif
100*f5b1c8a1SJohn Marino 
101*f5b1c8a1SJohn Marino /* BEGIN ERROR CODES */
102*f5b1c8a1SJohn Marino /* The following lines are auto generated by the script mkerr.pl. Any changes
103*f5b1c8a1SJohn Marino  * made after this point may be overwritten when the script is next run.
104*f5b1c8a1SJohn Marino  */
105*f5b1c8a1SJohn Marino void ERR_load_BUF_strings(void);
106*f5b1c8a1SJohn Marino 
107*f5b1c8a1SJohn Marino /* Error codes for the BUF functions. */
108*f5b1c8a1SJohn Marino 
109*f5b1c8a1SJohn Marino /* Function codes. */
110*f5b1c8a1SJohn Marino #define BUF_F_BUF_MEMDUP				 103
111*f5b1c8a1SJohn Marino #define BUF_F_BUF_MEM_GROW				 100
112*f5b1c8a1SJohn Marino #define BUF_F_BUF_MEM_GROW_CLEAN			 105
113*f5b1c8a1SJohn Marino #define BUF_F_BUF_MEM_NEW				 101
114*f5b1c8a1SJohn Marino #define BUF_F_BUF_STRDUP				 102
115*f5b1c8a1SJohn Marino #define BUF_F_BUF_STRNDUP				 104
116*f5b1c8a1SJohn Marino 
117*f5b1c8a1SJohn Marino /* Reason codes. */
118*f5b1c8a1SJohn Marino 
119*f5b1c8a1SJohn Marino #ifdef  __cplusplus
120*f5b1c8a1SJohn Marino }
121*f5b1c8a1SJohn Marino #endif
122*f5b1c8a1SJohn Marino #endif
123