From ba368822d0a197cb84c46c911d40d0c52cf9c391 Mon Sep 17 00:00:00 2001
From: Hal Murray <hmurray@megapathdsl.net>
Date: Sun, 2 May 2021 22:24:26 -0700
Subject: [PATCH] Update to OpenSSL 3.0.0-alpha15

Upstream-Status: Backport [https://gitlab.com/NTPsec/ntpsec/-/commit/ba368822d0a197cb84c46c911d40d0c52cf9c391]
Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Kiernan <alexk@zuma.ai>
---
 attic/cmac-timing.c | 37 ++++++++++++++-----------------------
 1 file changed, 14 insertions(+), 23 deletions(-)

diff --git a/attic/cmac-timing.c b/attic/cmac-timing.c
index c2088db63a4c..464daa76b9e6 100644
--- a/attic/cmac-timing.c
+++ b/attic/cmac-timing.c
@@ -225,28 +225,14 @@ static void DoPKEY(
 #if OPENSSL_VERSION_NUMBER > 0x20000000L
 static size_t One_EVP_MAC(
   EVP_MAC_CTX *ctx,         /* context  */
-  char *cipher,
   uint8_t *key,             /* key pointer */
   int     keylength,        /* key length */
   uint8_t *pkt,             /* packet pointer */
   int     pktlength         /* packet length */
 ) {
-	OSSL_PARAM params[3];
 	size_t len = EVP_MAX_MD_SIZE;
 
-	params[0] =
-          OSSL_PARAM_construct_utf8_string("cipher", cipher, 0);
-	params[1] =
-          OSSL_PARAM_construct_octet_string("key", key, keylength);
-	params[2] = OSSL_PARAM_construct_end();
-	if (0 == EVP_MAC_CTX_set_params(ctx, params)) {
-		unsigned long err = ERR_get_error();
-		char * str = ERR_error_string(err, NULL);
-		printf("## Oops, EVP_MAC_CTX_set_params() failed: %s.\n", str);
-		return 0;
-	}
-
-	if (0 == EVP_MAC_init(ctx)) {
+	if (0 == EVP_MAC_init(ctx, key, keylength, NULL)) {
 		unsigned long err = ERR_get_error();
 		char * str = ERR_error_string(err, NULL);
 		printf("## Oops, EVP_MAC_init() failed: %s.\n", str);
@@ -255,13 +241,13 @@ static size_t One_EVP_MAC(
 	if (0 == EVP_MAC_update(ctx, pkt, pktlength)) {
 		unsigned long err = ERR_get_error();
 		char * str = ERR_error_string(err, NULL);
-		printf("## Oops, EVP_MAC_init() failed: %s.\n", str);
+		printf("## Oops, EVP_MAC_update() failed: %s.\n", str);
 		return 0;
 	}
 	if (0 == EVP_MAC_final(ctx, answer, &len, sizeof(answer))) {
 		unsigned long err = ERR_get_error();
 		char * str = ERR_error_string(err, NULL);
-		printf("## Oops, EVP_MAC_init() failed: %s.\n", str);
+		printf("## Oops, EVP_MAC_final() failed: %s.\n", str);
 		return 0;
 	}
 	return len;
@@ -290,7 +276,7 @@ static void Do_EVP_MAC(
 
 	clock_gettime(CLOCK_MONOTONIC, &start);
 	for (int i = 0; i < SAMPLESIZE; i++) {
-		digestlength = One_EVP_MAC(evp, cbc, key, keylength, pkt, pktlength);
+		digestlength = One_EVP_MAC(evp, key, keylength, pkt, pktlength);
 if (0 == digestlength) break;
 	}
 	clock_gettime(CLOCK_MONOTONIC, &stop);
@@ -305,26 +291,31 @@ static size_t One_EVP_MAC2(
   uint8_t *pkt,             /* packet pointer */
   int     pktlength         /* packet length */
 ) {
+	EVP_MAC_CTX *dup;
 	size_t len = EVP_MAX_MD_SIZE;
 
-	if (0 == EVP_MAC_init(ctx)) {
+	// dup = ctx;
+	dup = EVP_MAC_CTX_dup(ctx);
+
+	if (0 == EVP_MAC_init(dup, NULL, 0, NULL)) {
 		unsigned long err = ERR_get_error();
 		char * str = ERR_error_string(err, NULL);
 		printf("## Oops, EVP_MAC_init() failed: %s.\n", str);
 		return 0;
 	}
-	if (0 == EVP_MAC_update(ctx, pkt, pktlength)) {
+	if (0 == EVP_MAC_update(dup, pkt, pktlength)) {
 		unsigned long err = ERR_get_error();
 		char * str = ERR_error_string(err, NULL);
-		printf("## Oops, EVP_MAC_init() failed: %s.\n", str);
+		printf("## Oops, EVP_MAC_update() failed: %s.\n", str);
 		return 0;
 	}
-	if (0 == EVP_MAC_final(ctx, answer, &len, sizeof(answer))) {
+	if (0 == EVP_MAC_final(dup, answer, &len, sizeof(answer))) {
 		unsigned long err = ERR_get_error();
 		char * str = ERR_error_string(err, NULL);
-		printf("## Oops, EVP_MAC_init() failed: %s.\n", str);
+		printf("## Oops, EVP_MAC_final() failed: %s.\n", str);
 		return 0;
 	}
+	EVP_MAC_CTX_free(dup);
 	return len;
 }
 
-- 
2.33.0

