From eb9d67981acc2795da64ed1850dcf071a7082a28 Mon Sep 17 00:00:00 2001 From: tb <> Date: Tue, 5 Jan 2021 17:40:11 +0000 Subject: Add tls13_secret_{init,cleanup}() These are two functions that will help streamlining various functions in the TLSv1.3 code that do not need to know about the interna of this struct. input/ok jsing --- src/lib/libssl/tls13_internal.h | 4 +++- src/lib/libssl/tls13_key_schedule.c | 27 ++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libssl/tls13_internal.h b/src/lib/libssl/tls13_internal.h index ea5f9a1473..c339a8ef10 100644 --- a/src/lib/libssl/tls13_internal.h +++ b/src/lib/libssl/tls13_internal.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tls13_internal.h,v 1.87 2020/11/16 18:55:15 jsing Exp $ */ +/* $OpenBSD: tls13_internal.h,v 1.88 2021/01/05 17:40:11 tb Exp $ */ /* * Copyright (c) 2018 Bob Beck * Copyright (c) 2018 Theo Buehler @@ -141,6 +141,8 @@ struct tls13_secrets { struct tls13_secret resumption_master; }; +int tls13_secret_init(struct tls13_secret *secret, size_t len); +void tls13_secret_cleanup(struct tls13_secret *secret); struct tls13_secrets *tls13_secrets_create(const EVP_MD *digest, int resumption); void tls13_secrets_destroy(struct tls13_secrets *secrets); diff --git a/src/lib/libssl/tls13_key_schedule.c b/src/lib/libssl/tls13_key_schedule.c index 35180cfe5c..bf8699dc31 100644 --- a/src/lib/libssl/tls13_key_schedule.c +++ b/src/lib/libssl/tls13_key_schedule.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls13_key_schedule.c,v 1.9 2020/11/16 18:55:15 jsing Exp $ */ +/* $OpenBSD: tls13_key_schedule.c,v 1.10 2021/01/05 17:40:11 tb Exp $ */ /* Copyright (c) 2018, Bob Beck * * Permission to use, copy, modify, and/or distribute this software for any @@ -22,6 +22,31 @@ #include "bytestring.h" #include "tls13_internal.h" +int +tls13_secret_init(struct tls13_secret *secret, size_t len) +{ + uint8_t *data; + + if (secret->data != NULL) + return 0; + + if ((data = calloc(1, len)) == NULL) + return 0; + + secret->data = data; + secret->len = len; + + return 1; +} + +void +tls13_secret_cleanup(struct tls13_secret *secret) +{ + freezero(secret->data, secret->len); + secret->data = NULL; + secret->len = 0; +} + void tls13_secrets_destroy(struct tls13_secrets *secrets) { -- cgit v1.2.3-55-g6feb