summaryrefslogtreecommitdiff
path: root/src/lib/libssl/tls_buffer.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libssl/tls_buffer.c (renamed from src/lib/libssl/tls13_buffer.c)49
1 files changed, 26 insertions, 23 deletions
diff --git a/src/lib/libssl/tls13_buffer.c b/src/lib/libssl/tls_buffer.c
index b46ac65ecf..5c0ca7e40e 100644
--- a/src/lib/libssl/tls13_buffer.c
+++ b/src/lib/libssl/tls_buffer.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_buffer.c,v 1.5 2021/05/16 14:19:04 jsing Exp $ */ 1/* $OpenBSD: tls_buffer.c,v 1.1 2021/10/23 13:12:14 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -15,49 +15,52 @@
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */ 16 */
17 17
18#include <stdlib.h>
19#include <string.h>
20
18#include "bytestring.h" 21#include "bytestring.h"
19#include "tls13_internal.h" 22#include "tls_internal.h"
20 23
21struct tls13_buffer { 24struct tls_buffer {
22 size_t capacity; 25 size_t capacity;
23 uint8_t *data; 26 uint8_t *data;
24 size_t len; 27 size_t len;
25 size_t offset; 28 size_t offset;
26}; 29};
27 30
28static int tls13_buffer_resize(struct tls13_buffer *buf, size_t capacity); 31static int tls_buffer_resize(struct tls_buffer *buf, size_t capacity);
29 32
30struct tls13_buffer * 33struct tls_buffer *
31tls13_buffer_new(size_t init_size) 34tls_buffer_new(size_t init_size)
32{ 35{
33 struct tls13_buffer *buf = NULL; 36 struct tls_buffer *buf = NULL;
34 37
35 if ((buf = calloc(1, sizeof(struct tls13_buffer))) == NULL) 38 if ((buf = calloc(1, sizeof(struct tls_buffer))) == NULL)
36 goto err; 39 goto err;
37 40
38 if (!tls13_buffer_resize(buf, init_size)) 41 if (!tls_buffer_resize(buf, init_size))
39 goto err; 42 goto err;
40 43
41 return buf; 44 return buf;
42 45
43 err: 46 err:
44 tls13_buffer_free(buf); 47 tls_buffer_free(buf);
45 48
46 return NULL; 49 return NULL;
47} 50}
48 51
49void 52void
50tls13_buffer_free(struct tls13_buffer *buf) 53tls_buffer_free(struct tls_buffer *buf)
51{ 54{
52 if (buf == NULL) 55 if (buf == NULL)
53 return; 56 return;
54 57
55 freezero(buf->data, buf->capacity); 58 freezero(buf->data, buf->capacity);
56 freezero(buf, sizeof(struct tls13_buffer)); 59 freezero(buf, sizeof(struct tls_buffer));
57} 60}
58 61
59static int 62static int
60tls13_buffer_resize(struct tls13_buffer *buf, size_t capacity) 63tls_buffer_resize(struct tls_buffer *buf, size_t capacity)
61{ 64{
62 uint8_t *data; 65 uint8_t *data;
63 66
@@ -74,17 +77,17 @@ tls13_buffer_resize(struct tls13_buffer *buf, size_t capacity)
74} 77}
75 78
76int 79int
77tls13_buffer_set_data(struct tls13_buffer *buf, CBS *data) 80tls_buffer_set_data(struct tls_buffer *buf, CBS *data)
78{ 81{
79 if (!tls13_buffer_resize(buf, CBS_len(data))) 82 if (!tls_buffer_resize(buf, CBS_len(data)))
80 return 0; 83 return 0;
81 memcpy(buf->data, CBS_data(data), CBS_len(data)); 84 memcpy(buf->data, CBS_data(data), CBS_len(data));
82 return 1; 85 return 1;
83} 86}
84 87
85ssize_t 88ssize_t
86tls13_buffer_extend(struct tls13_buffer *buf, size_t len, 89tls_buffer_extend(struct tls_buffer *buf, size_t len,
87 tls13_read_cb read_cb, void *cb_arg) 90 tls_read_cb read_cb, void *cb_arg)
88{ 91{
89 ssize_t ret; 92 ssize_t ret;
90 93
@@ -92,10 +95,10 @@ tls13_buffer_extend(struct tls13_buffer *buf, size_t len,
92 return buf->len; 95 return buf->len;
93 96
94 if (len < buf->len) 97 if (len < buf->len)
95 return TLS13_IO_FAILURE; 98 return TLS_IO_FAILURE;
96 99
97 if (!tls13_buffer_resize(buf, len)) 100 if (!tls_buffer_resize(buf, len))
98 return TLS13_IO_FAILURE; 101 return TLS_IO_FAILURE;
99 102
100 for (;;) { 103 for (;;) {
101 if ((ret = read_cb(&buf->data[buf->len], 104 if ((ret = read_cb(&buf->data[buf->len],
@@ -103,7 +106,7 @@ tls13_buffer_extend(struct tls13_buffer *buf, size_t len,
103 return ret; 106 return ret;
104 107
105 if (ret > buf->capacity - buf->len) 108 if (ret > buf->capacity - buf->len)
106 return TLS13_IO_FAILURE; 109 return TLS_IO_FAILURE;
107 110
108 buf->len += ret; 111 buf->len += ret;
109 112
@@ -113,13 +116,13 @@ tls13_buffer_extend(struct tls13_buffer *buf, size_t len,
113} 116}
114 117
115void 118void
116tls13_buffer_cbs(struct tls13_buffer *buf, CBS *cbs) 119tls_buffer_cbs(struct tls_buffer *buf, CBS *cbs)
117{ 120{
118 CBS_init(cbs, buf->data, buf->len); 121 CBS_init(cbs, buf->data, buf->len);
119} 122}
120 123
121int 124int
122tls13_buffer_finish(struct tls13_buffer *buf, uint8_t **out, size_t *out_len) 125tls_buffer_finish(struct tls_buffer *buf, uint8_t **out, size_t *out_len)
123{ 126{
124 if (out == NULL || out_len == NULL) 127 if (out == NULL || out_len == NULL)
125 return 0; 128 return 0;