From 05df66360f354ae86e98a98f38534d041726f923 Mon Sep 17 00:00:00 2001
From: jsing <>
Date: Sat, 9 Feb 2019 15:30:52 +0000
Subject: Rename the file that contains the transcript handling code.

ok inoguchi@ tb@
---
 src/lib/libssl/Makefile         |   4 +-
 src/lib/libssl/ssl_transcript.c | 201 ++++++++++++++++++++++++++++++++++++++++
 src/lib/libssl/t1_hash.c        | 201 ----------------------------------------
 3 files changed, 203 insertions(+), 203 deletions(-)
 create mode 100644 src/lib/libssl/ssl_transcript.c
 delete mode 100644 src/lib/libssl/t1_hash.c

(limited to 'src/lib')

diff --git a/src/lib/libssl/Makefile b/src/lib/libssl/Makefile
index cd37f3ce86..2ede8a77b0 100644
--- a/src/lib/libssl/Makefile
+++ b/src/lib/libssl/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.55 2019/02/04 15:55:16 jsing Exp $
+# $OpenBSD: Makefile,v 1.56 2019/02/09 15:30:52 jsing Exp $
 
 .include <bsd.own.mk>
 .ifndef NOMAN
@@ -60,10 +60,10 @@ SRCS= \
 	ssl_srvr.c \
 	ssl_stat.c \
 	ssl_tlsext.c \
+	ssl_transcript.c \
 	ssl_txt.c \
 	ssl_versions.c \
 	t1_enc.c \
-	t1_hash.c \
 	t1_lib.c \
 	tls13_buffer.c \
 	tls13_client.c \
diff --git a/src/lib/libssl/ssl_transcript.c b/src/lib/libssl/ssl_transcript.c
new file mode 100644
index 0000000000..e94eb8de80
--- /dev/null
+++ b/src/lib/libssl/ssl_transcript.c
@@ -0,0 +1,201 @@
+/* $OpenBSD: ssl_transcript.c,v 1.1 2019/02/09 15:30:52 jsing Exp $ */
+/*
+ * Copyright (c) 2017 Joel Sing <jsing@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "ssl_locl.h"
+
+#include <openssl/ssl.h>
+
+int
+tls1_transcript_hash_init(SSL *s)
+{
+	const unsigned char *data;
+	const EVP_MD *md;
+	size_t len;
+
+	tls1_transcript_hash_free(s);
+
+	if (!ssl_get_handshake_evp_md(s, &md)) {
+		SSLerrorx(ERR_R_INTERNAL_ERROR);
+		goto err;
+	}
+
+	if ((S3I(s)->handshake_hash = EVP_MD_CTX_new()) == NULL) {
+		SSLerror(s, ERR_R_MALLOC_FAILURE);
+		goto err;
+	}
+	if (!EVP_DigestInit_ex(S3I(s)->handshake_hash, md, NULL)) {
+		SSLerror(s, ERR_R_EVP_LIB);
+		goto err;
+	}
+
+	if (!tls1_transcript_data(s, &data, &len)) {
+		SSLerror(s, SSL_R_BAD_HANDSHAKE_LENGTH);
+		goto err;
+	}
+	if (!tls1_transcript_hash_update(s, data, len)) {
+		SSLerror(s, ERR_R_EVP_LIB);
+		goto err;
+	}
+		
+	return 1;
+
+ err:
+	tls1_transcript_hash_free(s);
+
+	return 0;
+}
+
+int
+tls1_transcript_hash_update(SSL *s, const unsigned char *buf, size_t len)
+{
+	if (S3I(s)->handshake_hash == NULL)
+		return 1;
+
+	return EVP_DigestUpdate(S3I(s)->handshake_hash, buf, len);
+}
+
+int
+tls1_transcript_hash_value(SSL *s, const unsigned char *out, size_t len,
+    size_t *outlen)
+{
+	EVP_MD_CTX *mdctx = NULL;
+	unsigned int mdlen;
+	int ret = 0;
+
+	if (EVP_MD_CTX_size(S3I(s)->handshake_hash) > len)
+		goto err;
+
+	if ((mdctx = EVP_MD_CTX_new()) == NULL) {
+		SSLerror(s, ERR_R_MALLOC_FAILURE);
+		goto err;
+	}
+	if (!EVP_MD_CTX_copy_ex(mdctx, S3I(s)->handshake_hash)) {
+		SSLerror(s, ERR_R_EVP_LIB);
+		goto err;
+	}
+	if (!EVP_DigestFinal_ex(mdctx, (unsigned char *)out, &mdlen)) {
+		SSLerror(s, ERR_R_EVP_LIB);
+		goto err;
+	}
+	if (outlen != NULL)
+		*outlen = mdlen;
+
+	ret = 1;
+
+ err:
+	EVP_MD_CTX_free(mdctx);
+
+	return (ret);
+}
+
+void
+tls1_transcript_hash_free(SSL *s)
+{
+	EVP_MD_CTX_free(S3I(s)->handshake_hash);
+	S3I(s)->handshake_hash = NULL;
+}
+
+int
+tls1_transcript_init(SSL *s)
+{
+	if (S3I(s)->handshake_transcript != NULL)
+		return 0;
+
+	if ((S3I(s)->handshake_transcript = BUF_MEM_new()) == NULL)
+		return 0;
+
+	tls1_transcript_reset(s);
+
+	return 1;
+}
+
+void
+tls1_transcript_free(SSL *s)
+{
+	BUF_MEM_free(S3I(s)->handshake_transcript);
+	S3I(s)->handshake_transcript = NULL;
+}
+
+void
+tls1_transcript_reset(SSL *s)
+{
+	/*
+	 * We should check the return value of BUF_MEM_grow_clean(), however
+	 * due to yet another bad API design, when called with a length of zero
+	 * it is impossible to tell if it succeeded (returning a length of zero)
+	 * or if it failed (and returned zero)... our implementation never
+	 * fails with a length of zero, so we trust all is okay...
+	 */ 
+	(void)BUF_MEM_grow_clean(S3I(s)->handshake_transcript, 0);
+
+	s->s3->flags &= ~TLS1_FLAGS_FREEZE_TRANSCRIPT;
+}
+
+int
+tls1_transcript_append(SSL *s, const unsigned char *buf, size_t len)
+{
+	size_t olen, nlen;
+
+	if (S3I(s)->handshake_transcript == NULL)
+		return 1;
+
+	if (s->s3->flags & TLS1_FLAGS_FREEZE_TRANSCRIPT)
+		return 1;
+
+	olen = S3I(s)->handshake_transcript->length;
+	nlen = olen + len;
+
+	if (nlen < olen)
+		return 0;
+
+	if (BUF_MEM_grow(S3I(s)->handshake_transcript, nlen) == 0)
+		return 0;
+
+	memcpy(S3I(s)->handshake_transcript->data + olen, buf, len);
+
+	return 1;
+}
+
+int
+tls1_transcript_data(SSL *s, const unsigned char **data, size_t *len)
+{
+	if (S3I(s)->handshake_transcript == NULL)
+		return 0;
+
+	*data = S3I(s)->handshake_transcript->data;
+	*len = S3I(s)->handshake_transcript->length;
+
+	return 1;
+}
+
+void
+tls1_transcript_freeze(SSL *s)
+{
+	s->s3->flags |= TLS1_FLAGS_FREEZE_TRANSCRIPT;
+}
+
+int
+tls1_transcript_record(SSL *s, const unsigned char *buf, size_t len)
+{
+	if (!tls1_transcript_hash_update(s, buf, len))
+		return 0;
+
+	if (!tls1_transcript_append(s, buf, len))
+		return 0;
+
+	return 1;
+}
diff --git a/src/lib/libssl/t1_hash.c b/src/lib/libssl/t1_hash.c
deleted file mode 100644
index 12d66d4def..0000000000
--- a/src/lib/libssl/t1_hash.c
+++ /dev/null
@@ -1,201 +0,0 @@
-/* $OpenBSD: t1_hash.c,v 1.6 2019/02/09 15:26:15 jsing Exp $ */
-/*
- * Copyright (c) 2017 Joel Sing <jsing@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include "ssl_locl.h"
-
-#include <openssl/ssl.h>
-
-int
-tls1_transcript_hash_init(SSL *s)
-{
-	const unsigned char *data;
-	const EVP_MD *md;
-	size_t len;
-
-	tls1_transcript_hash_free(s);
-
-	if (!ssl_get_handshake_evp_md(s, &md)) {
-		SSLerrorx(ERR_R_INTERNAL_ERROR);
-		goto err;
-	}
-
-	if ((S3I(s)->handshake_hash = EVP_MD_CTX_new()) == NULL) {
-		SSLerror(s, ERR_R_MALLOC_FAILURE);
-		goto err;
-	}
-	if (!EVP_DigestInit_ex(S3I(s)->handshake_hash, md, NULL)) {
-		SSLerror(s, ERR_R_EVP_LIB);
-		goto err;
-	}
-
-	if (!tls1_transcript_data(s, &data, &len)) {
-		SSLerror(s, SSL_R_BAD_HANDSHAKE_LENGTH);
-		goto err;
-	}
-	if (!tls1_transcript_hash_update(s, data, len)) {
-		SSLerror(s, ERR_R_EVP_LIB);
-		goto err;
-	}
-		
-	return 1;
-
- err:
-	tls1_transcript_hash_free(s);
-
-	return 0;
-}
-
-int
-tls1_transcript_hash_update(SSL *s, const unsigned char *buf, size_t len)
-{
-	if (S3I(s)->handshake_hash == NULL)
-		return 1;
-
-	return EVP_DigestUpdate(S3I(s)->handshake_hash, buf, len);
-}
-
-int
-tls1_transcript_hash_value(SSL *s, const unsigned char *out, size_t len,
-    size_t *outlen)
-{
-	EVP_MD_CTX *mdctx = NULL;
-	unsigned int mdlen;
-	int ret = 0;
-
-	if (EVP_MD_CTX_size(S3I(s)->handshake_hash) > len)
-		goto err;
-
-	if ((mdctx = EVP_MD_CTX_new()) == NULL) {
-		SSLerror(s, ERR_R_MALLOC_FAILURE);
-		goto err;
-	}
-	if (!EVP_MD_CTX_copy_ex(mdctx, S3I(s)->handshake_hash)) {
-		SSLerror(s, ERR_R_EVP_LIB);
-		goto err;
-	}
-	if (!EVP_DigestFinal_ex(mdctx, (unsigned char *)out, &mdlen)) {
-		SSLerror(s, ERR_R_EVP_LIB);
-		goto err;
-	}
-	if (outlen != NULL)
-		*outlen = mdlen;
-
-	ret = 1;
-
- err:
-	EVP_MD_CTX_free(mdctx);
-
-	return (ret);
-}
-
-void
-tls1_transcript_hash_free(SSL *s)
-{
-	EVP_MD_CTX_free(S3I(s)->handshake_hash);
-	S3I(s)->handshake_hash = NULL;
-}
-
-int
-tls1_transcript_init(SSL *s)
-{
-	if (S3I(s)->handshake_transcript != NULL)
-		return 0;
-
-	if ((S3I(s)->handshake_transcript = BUF_MEM_new()) == NULL)
-		return 0;
-
-	tls1_transcript_reset(s);
-
-	return 1;
-}
-
-void
-tls1_transcript_free(SSL *s)
-{
-	BUF_MEM_free(S3I(s)->handshake_transcript);
-	S3I(s)->handshake_transcript = NULL;
-}
-
-void
-tls1_transcript_reset(SSL *s)
-{
-	/*
-	 * We should check the return value of BUF_MEM_grow_clean(), however
-	 * due to yet another bad API design, when called with a length of zero
-	 * it is impossible to tell if it succeeded (returning a length of zero)
-	 * or if it failed (and returned zero)... our implementation never
-	 * fails with a length of zero, so we trust all is okay...
-	 */ 
-	(void)BUF_MEM_grow_clean(S3I(s)->handshake_transcript, 0);
-
-	s->s3->flags &= ~TLS1_FLAGS_FREEZE_TRANSCRIPT;
-}
-
-int
-tls1_transcript_append(SSL *s, const unsigned char *buf, size_t len)
-{
-	size_t olen, nlen;
-
-	if (S3I(s)->handshake_transcript == NULL)
-		return 1;
-
-	if (s->s3->flags & TLS1_FLAGS_FREEZE_TRANSCRIPT)
-		return 1;
-
-	olen = S3I(s)->handshake_transcript->length;
-	nlen = olen + len;
-
-	if (nlen < olen)
-		return 0;
-
-	if (BUF_MEM_grow(S3I(s)->handshake_transcript, nlen) == 0)
-		return 0;
-
-	memcpy(S3I(s)->handshake_transcript->data + olen, buf, len);
-
-	return 1;
-}
-
-int
-tls1_transcript_data(SSL *s, const unsigned char **data, size_t *len)
-{
-	if (S3I(s)->handshake_transcript == NULL)
-		return 0;
-
-	*data = S3I(s)->handshake_transcript->data;
-	*len = S3I(s)->handshake_transcript->length;
-
-	return 1;
-}
-
-void
-tls1_transcript_freeze(SSL *s)
-{
-	s->s3->flags |= TLS1_FLAGS_FREEZE_TRANSCRIPT;
-}
-
-int
-tls1_transcript_record(SSL *s, const unsigned char *buf, size_t len)
-{
-	if (!tls1_transcript_hash_update(s, buf, len))
-		return 0;
-
-	if (!tls1_transcript_append(s, buf, len))
-		return 0;
-
-	return 1;
-}
-- 
cgit v1.2.3-55-g6feb