summaryrefslogtreecommitdiff
path: root/src/lib/libssl/tls13_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/tls13_lib.c')
-rw-r--r--src/lib/libssl/tls13_lib.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/lib/libssl/tls13_lib.c b/src/lib/libssl/tls13_lib.c
index c4cce26ca5..3860ddefef 100644
--- a/src/lib/libssl/tls13_lib.c
+++ b/src/lib/libssl/tls13_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_lib.c,v 1.2 2019/01/21 10:24:25 jsing Exp $ */ 1/* $OpenBSD: tls13_lib.c,v 1.3 2019/01/21 13:45:57 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 *
@@ -61,6 +61,39 @@ tls13_cipher_hash(const SSL_CIPHER *cipher)
61 return NULL; 61 return NULL;
62} 62}
63 63
64struct tls13_ctx *
65tls13_ctx_new(int mode)
66{
67 struct tls13_ctx *ctx = NULL;
68
69 if ((ctx = calloc(sizeof(struct tls13_ctx), 1)) == NULL)
70 goto err;
71
72 ctx->mode = mode;
73
74 if ((ctx->rl = tls13_record_layer_new(tls13_legacy_wire_read_cb,
75 tls13_legacy_wire_write_cb, NULL, NULL, ctx)) == NULL)
76 goto err;
77
78 return ctx;
79
80 err:
81 tls13_ctx_free(ctx);
82
83 return NULL;
84}
85
86void
87tls13_ctx_free(struct tls13_ctx *ctx)
88{
89 if (ctx == NULL)
90 return;
91
92 tls13_record_layer_free(ctx->rl);
93
94 freezero(ctx, sizeof(struct tls13_ctx));
95}
96
64static ssize_t 97static ssize_t
65tls13_legacy_wire_read(SSL *ssl, uint8_t *buf, size_t len) 98tls13_legacy_wire_read(SSL *ssl, uint8_t *buf, size_t len)
66{ 99{
@@ -131,7 +164,7 @@ tls13_legacy_wire_write_cb(const void *buf, size_t n, void *arg)
131 return tls13_legacy_wire_write(ctx->ssl, buf, n); 164 return tls13_legacy_wire_write(ctx->ssl, buf, n);
132} 165}
133 166
134static int 167int
135tls13_legacy_return_code(SSL *ssl, ssize_t ret) 168tls13_legacy_return_code(SSL *ssl, ssize_t ret)
136{ 169{
137 if (ret > INT_MAX) { 170 if (ret > INT_MAX) {
@@ -139,7 +172,7 @@ tls13_legacy_return_code(SSL *ssl, ssize_t ret)
139 return -1; 172 return -1;
140 } 173 }
141 174
142 /* A successful read or write. */ 175 /* A successful read, write or other operation. */
143 if (ret > 0) 176 if (ret > 0)
144 return ret; 177 return ret;
145 178