1 /* $OpenBSD: tls13_internal.h,v 1.7 2019/01/18 06:51:29 tb Exp $ */ 2 /* 3 * Copyright (c) 2018 Bob Beck <beck@openbsd.org> 4 * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> 5 * 6 * Permission to use, copy, modify, and/or distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef HEADER_TLS13_INTERNAL_H 20 #define HEADER_TLS13_INTERNAL_H 21 22 #include <openssl/evp.h> 23 24 #include "bytestring.h" 25 26 __BEGIN_HIDDEN_DECLS 27 28 #define TLS13_IO_EOF 0 29 #define TLS13_IO_FAILURE -1 30 #define TLS13_IO_WANT_POLLIN -2 31 #define TLS13_IO_WANT_POLLOUT -3 32 33 typedef ssize_t (*tls13_read_cb)(void *_buf, size_t _buflen, void *_cb_arg); 34 typedef ssize_t (*tls13_write_cb)(const void *_buf, size_t _buflen, void *_cb_arg); 35 36 struct tls13_buffer; 37 38 struct tls13_buffer *tls13_buffer_new(size_t init_size); 39 void tls13_buffer_free(struct tls13_buffer *buf); 40 ssize_t tls13_buffer_extend(struct tls13_buffer *buf, size_t len, 41 tls13_read_cb read_cb, void *cb_arg); 42 void tls13_buffer_cbs(struct tls13_buffer *buf, CBS *cbs); 43 int tls13_buffer_finish(struct tls13_buffer *buf, uint8_t **out, size_t *out_len); 44 45 struct tls13_secret { 46 uint8_t *data; 47 size_t len; 48 }; 49 50 /* RFC 8446 Section 7.1 Page 92 */ 51 struct tls13_secrets { 52 const EVP_MD *digest; 53 int resumption; 54 int init_done; 55 int early_done; 56 int handshake_done; 57 int schedule_done; 58 int insecure; /* Set by tests */ 59 struct tls13_secret zeros; 60 struct tls13_secret empty_hash; 61 struct tls13_secret extracted_early; 62 struct tls13_secret binder_key; 63 struct tls13_secret client_early_traffic; 64 struct tls13_secret early_exporter_master; 65 struct tls13_secret derived_early; 66 struct tls13_secret extracted_handshake; 67 struct tls13_secret client_handshake_traffic; 68 struct tls13_secret server_handshake_traffic; 69 struct tls13_secret derived_handshake; 70 struct tls13_secret extracted_master; 71 struct tls13_secret client_application_traffic; 72 struct tls13_secret server_application_traffic; 73 struct tls13_secret exporter_master; 74 struct tls13_secret resumption_master; 75 }; 76 77 struct tls13_secrets *tls13_secrets_create(const EVP_MD *digest, 78 int resumption); 79 void tls13_secrets_destroy(struct tls13_secrets *secrets); 80 81 int tls13_hkdf_expand_label(struct tls13_secret *out, const EVP_MD *digest, 82 const struct tls13_secret *secret, const char *label, 83 const struct tls13_secret *context); 84 85 int tls13_derive_early_secrets(struct tls13_secrets *secrets, uint8_t *psk, 86 size_t psk_len, const struct tls13_secret *context); 87 int tls13_derive_handshake_secrets(struct tls13_secrets *secrets, 88 const uint8_t *ecdhe, size_t ecdhe_len, const struct tls13_secret *context); 89 int tls13_derive_application_secrets(struct tls13_secrets *secrets, 90 const struct tls13_secret *context); 91 92 struct tls13_ctx; 93 94 /* 95 * RFC 8446, Section B.3 96 * 97 * Values listed as "_RESERVED" were used in previous versions of TLS and are 98 * listed here for completeness. TLS 1.3 implementations MUST NOT send them but 99 * might receive them from older TLS implementations. 100 */ 101 #define TLS13_MT_HELLO_REQUEST_RESERVED 0 102 #define TLS13_MT_CLIENT_HELLO 1 103 #define TLS13_MT_SERVER_HELLO 2 104 #define TLS13_MT_HELLO_VERIFY_REQUEST_RESERVED 3 105 #define TLS13_MT_NEW_SESSION_TICKET 4 106 #define TLS13_MT_END_OF_EARLY_DATA 5 107 #define TLS13_MT_HELLO_RETRY_REQUEST_RESERVED 6 108 #define TLS13_MT_ENCRYPTED_EXTENSIONS 8 109 #define TLS13_MT_CERTIFICATE 11 110 #define TLS13_MT_SERVER_KEY_EXCHANGE_RESERVED 12 111 #define TLS13_MT_CERTIFICATE_REQUEST 13 112 #define TLS13_MT_SERVER_HELLO_DONE_RESERVED 14 113 #define TLS13_MT_CERTIFICATE_VERIFY 15 114 #define TLS13_MT_CLIENT_KEY_EXCHANGE_RESERVED 16 115 #define TLS13_MT_FINISHED 20 116 #define TLS13_MT_CERTIFICATE_URL_RESERVED 21 117 #define TLS13_MT_CERTIFICATE_STATUS_RESERVED 22 118 #define TLS13_MT_SUPPLEMENTAL_DATA_RESERVED 23 119 #define TLS13_MT_KEY_UPDATE 24 120 #define TLS13_MT_MESSAGE_HASH 254 121 122 int tls13_client_hello_send(struct tls13_ctx *ctx); 123 int tls13_client_hello_recv(struct tls13_ctx *ctx); 124 int tls13_client_hello_retry_send(struct tls13_ctx *ctx); 125 int tls13_client_hello_retry_recv(struct tls13_ctx *ctx); 126 int tls13_client_end_of_early_data_send(struct tls13_ctx *ctx); 127 int tls13_client_end_of_early_data_recv(struct tls13_ctx *ctx); 128 int tls13_client_certificate_send(struct tls13_ctx *ctx); 129 int tls13_client_certificate_recv(struct tls13_ctx *ctx); 130 int tls13_client_certificate_verify_send(struct tls13_ctx *ctx); 131 int tls13_client_certificate_verify_recv(struct tls13_ctx *ctx); 132 int tls13_client_finished_recv(struct tls13_ctx *ctx); 133 int tls13_client_finished_send(struct tls13_ctx *ctx); 134 int tls13_client_key_update_send(struct tls13_ctx *ctx); 135 int tls13_client_key_update_recv(struct tls13_ctx *ctx); 136 int tls13_server_hello_recv(struct tls13_ctx *ctx); 137 int tls13_server_hello_send(struct tls13_ctx *ctx); 138 int tls13_server_encrypted_extensions_recv(struct tls13_ctx *ctx); 139 int tls13_server_encrypted_extensions_send(struct tls13_ctx *ctx); 140 int tls13_server_certificate_recv(struct tls13_ctx *ctx); 141 int tls13_server_certificate_send(struct tls13_ctx *ctx); 142 int tls13_server_certificate_request_recv(struct tls13_ctx *ctx); 143 int tls13_server_certificate_request_send(struct tls13_ctx *ctx); 144 int tls13_server_certificate_verify_send(struct tls13_ctx *ctx); 145 int tls13_server_certificate_verify_recv(struct tls13_ctx *ctx); 146 int tls13_server_finished_recv(struct tls13_ctx *ctx); 147 int tls13_server_finished_send(struct tls13_ctx *ctx); 148 149 __END_HIDDEN_DECLS 150 151 #endif 152