1.\" $OpenBSD: BUF_MEM_new.3,v 1.19 2024/07/24 08:57:58 tb Exp $ 2.\" OpenSSL doc/crypto/buffer.pod 18edda0f Sep 20 03:28:54 2000 +0000 3.\" not merged: 74924dcb, 58e3457a, 21b0fa91, 7644a9ae 4.\" OpenSSL doc/crypto/BUF_MEM_new.pod 53934822 Jun 9 16:39:19 2016 -0400 5.\" not merged: c952780c, 91da5e77 6.\" OpenSSL doc/man3/BUF_MEM_new.pod 498180de Dec 12 15:35:09 2016 +0300 7.\" 8.\" This file was written by Ralf S. Engelschall <rse@openssl.org>. 9.\" Copyright (c) 1999, 2000, 2016 The OpenSSL Project. All rights reserved. 10.\" 11.\" Redistribution and use in source and binary forms, with or without 12.\" modification, are permitted provided that the following conditions 13.\" are met: 14.\" 15.\" 1. Redistributions of source code must retain the above copyright 16.\" notice, this list of conditions and the following disclaimer. 17.\" 18.\" 2. Redistributions in binary form must reproduce the above copyright 19.\" notice, this list of conditions and the following disclaimer in 20.\" the documentation and/or other materials provided with the 21.\" distribution. 22.\" 23.\" 3. All advertising materials mentioning features or use of this 24.\" software must display the following acknowledgment: 25.\" "This product includes software developed by the OpenSSL Project 26.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 27.\" 28.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 29.\" endorse or promote products derived from this software without 30.\" prior written permission. For written permission, please contact 31.\" openssl-core@openssl.org. 32.\" 33.\" 5. Products derived from this software may not be called "OpenSSL" 34.\" nor may "OpenSSL" appear in their names without prior written 35.\" permission of the OpenSSL Project. 36.\" 37.\" 6. Redistributions of any form whatsoever must retain the following 38.\" acknowledgment: 39.\" "This product includes software developed by the OpenSSL Project 40.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 41.\" 42.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 43.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 44.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 45.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 46.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 47.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 48.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 49.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 50.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 51.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 52.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 53.\" OF THE POSSIBILITY OF SUCH DAMAGE. 54.\" 55.Dd $Mdocdate: July 24 2024 $ 56.Dt BUF_MEM_NEW 3 57.Os 58.Sh NAME 59.Nm BUF_MEM_new , 60.Nm BUF_MEM_free , 61.Nm BUF_MEM_grow , 62.Nm BUF_MEM_grow_clean 63.Nd simple character arrays structure 64.Sh SYNOPSIS 65.In openssl/buffer.h 66.Ft BUF_MEM * 67.Fo BUF_MEM_new 68.Fa void 69.Fc 70.Ft void 71.Fo BUF_MEM_free 72.Fa "BUF_MEM *a" 73.Fc 74.Ft int 75.Fo BUF_MEM_grow 76.Fa "BUF_MEM *str" 77.Fa "size_t len" 78.Fc 79.Ft int 80.Fo BUF_MEM_grow_clean 81.Fa "BUF_MEM *str" 82.Fa "size_t len" 83.Fc 84.Sh DESCRIPTION 85The buffer library handles simple character arrays. 86Buffers are used for various purposes in the library, most notably 87memory BIOs. 88.Pp 89The library uses the 90.Vt BUF_MEM 91structure defined in buffer.h: 92.Bd -literal 93typedef struct buf_mem_st { 94 size_t length; /* current number of bytes */ 95 char *data; 96 size_t max; /* size of buffer */ 97} BUF_MEM; 98.Ed 99.Pp 100.Fa length 101is the current size of the buffer in bytes; 102.Fa max 103is the amount of memory allocated to the buffer. 104There are three functions which handle these and one miscellaneous function. 105.Pp 106.Fn BUF_MEM_new 107allocates a new buffer of zero size. 108.Pp 109.Fn BUF_MEM_free 110frees up an already existing buffer. 111The data is zeroed before freeing up in case the buffer contains 112sensitive data. 113If 114.Fa a 115is a 116.Dv NULL 117pointer, no action occurs. 118.Pp 119.Fn BUF_MEM_grow 120changes the size of an already existing buffer to 121.Fa len . 122Any data already in the buffer is preserved if it increases in size. 123.Pp 124.Fn BUF_MEM_grow_clean 125is similar to 126.Fn BUF_MEM_grow , 127but it sets any freed or additionally allocated memory to zero. 128.Sh RETURN VALUES 129.Fn BUF_MEM_new 130returns the buffer or 131.Dv NULL 132on error. 133.Pp 134.Fn BUF_MEM_grow 135and 136.Fn BUF_MEM_grow_clean 137return zero on error or the new size (i.e.\& 138.Fa len ) . 139.Sh SEE ALSO 140.Xr BIO_new 3 , 141.Xr BIO_s_mem 3 142.Sh HISTORY 143.Fn BUF_MEM_new , 144.Fn BUF_MEM_free , 145and 146.Fn BUF_MEM_grow 147first appeared in SSLeay 0.6.0. 148All these functions have been available since 149.Ox 2.4 . 150.Pp 151.Fn BUF_MEM_grow_clean 152first appeared in OpenSSL 0.9.7 and has been available since 153.Ox 3.2 . 154