diff options
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 | ||
| 21 | struct tls13_buffer { | 24 | struct 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 | ||
| 28 | static int tls13_buffer_resize(struct tls13_buffer *buf, size_t capacity); | 31 | static int tls_buffer_resize(struct tls_buffer *buf, size_t capacity); |
| 29 | 32 | ||
| 30 | struct tls13_buffer * | 33 | struct tls_buffer * |
| 31 | tls13_buffer_new(size_t init_size) | 34 | tls_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 | ||
| 49 | void | 52 | void |
| 50 | tls13_buffer_free(struct tls13_buffer *buf) | 53 | tls_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 | ||
| 59 | static int | 62 | static int |
| 60 | tls13_buffer_resize(struct tls13_buffer *buf, size_t capacity) | 63 | tls_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 | ||
| 76 | int | 79 | int |
| 77 | tls13_buffer_set_data(struct tls13_buffer *buf, CBS *data) | 80 | tls_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 | ||
| 85 | ssize_t | 88 | ssize_t |
| 86 | tls13_buffer_extend(struct tls13_buffer *buf, size_t len, | 89 | tls_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 | ||
| 115 | void | 118 | void |
| 116 | tls13_buffer_cbs(struct tls13_buffer *buf, CBS *cbs) | 119 | tls_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 | ||
| 121 | int | 124 | int |
| 122 | tls13_buffer_finish(struct tls13_buffer *buf, uint8_t **out, size_t *out_len) | 125 | tls_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; |
