xref: /openbsd-src/lib/libssl/tls_internal.h (revision 25c4e8bd056e974b28f4a0ffd39d76c190a56013)
1 /* $OpenBSD: tls_internal.h,v 1.8 2022/07/22 19:33:53 jsing Exp $ */
2 /*
3  * Copyright (c) 2018, 2019, 2021 Joel Sing <jsing@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #ifndef HEADER_TLS_INTERNAL_H
19 #define HEADER_TLS_INTERNAL_H
20 
21 #include <openssl/dh.h>
22 #include <openssl/evp.h>
23 
24 #include "bytestring.h"
25 
26 __BEGIN_HIDDEN_DECLS
27 
28 #define TLS_IO_SUCCESS			 1
29 #define TLS_IO_EOF			 0
30 #define TLS_IO_FAILURE			-1
31 #define TLS_IO_ALERT			-2
32 #define TLS_IO_WANT_POLLIN		-3
33 #define TLS_IO_WANT_POLLOUT		-4
34 #define TLS_IO_WANT_RETRY		-5 /* Retry the previous call immediately. */
35 
36 /*
37  * Callbacks.
38  */
39 typedef ssize_t (*tls_read_cb)(void *_buf, size_t _buflen, void *_cb_arg);
40 typedef ssize_t (*tls_write_cb)(const void *_buf, size_t _buflen,
41     void *_cb_arg);
42 typedef ssize_t (*tls_flush_cb)(void *_cb_arg);
43 
44 /*
45  * Buffers.
46  */
47 struct tls_buffer;
48 
49 struct tls_buffer *tls_buffer_new(size_t init_size);
50 void tls_buffer_clear(struct tls_buffer *buf);
51 void tls_buffer_free(struct tls_buffer *buf);
52 void tls_buffer_set_capacity_limit(struct tls_buffer *buf, size_t limit);
53 ssize_t tls_buffer_extend(struct tls_buffer *buf, size_t len,
54     tls_read_cb read_cb, void *cb_arg);
55 ssize_t tls_buffer_read(struct tls_buffer *buf, uint8_t *rbuf, size_t n);
56 ssize_t tls_buffer_write(struct tls_buffer *buf, const uint8_t *wbuf, size_t n);
57 int tls_buffer_append(struct tls_buffer *buf, const uint8_t *wbuf, size_t n);
58 int tls_buffer_data(struct tls_buffer *buf, CBS *cbs);
59 int tls_buffer_finish(struct tls_buffer *buf, uint8_t **out, size_t *out_len);
60 
61 /*
62  * Key shares.
63  */
64 struct tls_key_share;
65 
66 struct tls_key_share *tls_key_share_new(uint16_t group_id);
67 struct tls_key_share *tls_key_share_new_nid(int nid);
68 void tls_key_share_free(struct tls_key_share *ks);
69 
70 uint16_t tls_key_share_group(struct tls_key_share *ks);
71 int tls_key_share_nid(struct tls_key_share *ks);
72 void tls_key_share_set_key_bits(struct tls_key_share *ks, size_t key_bits);
73 int tls_key_share_set_dh_params(struct tls_key_share *ks, DH *dh_params);
74 int tls_key_share_peer_pkey(struct tls_key_share *ks, EVP_PKEY *pkey);
75 int tls_key_share_generate(struct tls_key_share *ks);
76 int tls_key_share_params(struct tls_key_share *ks, CBB *cbb);
77 int tls_key_share_public(struct tls_key_share *ks, CBB *cbb);
78 int tls_key_share_peer_params(struct tls_key_share *ks, CBS *cbs,
79     int *decode_error, int *invalid_params);
80 int tls_key_share_peer_public(struct tls_key_share *ks, CBS *cbs,
81     int *decode_error, int *invalid_key);
82 int tls_key_share_derive(struct tls_key_share *ks, uint8_t **shared_key,
83     size_t *shared_key_len);
84 int tls_key_share_peer_security(const SSL *ssl, struct tls_key_share *ks);
85 
86 __END_HIDDEN_DECLS
87 
88 #endif
89