From a5c73ac97b067daed19c07515f4e72156bfa21d4 Mon Sep 17 00:00:00 2001
From: tb <>
Date: Sun, 21 Nov 2021 11:41:18 +0000
Subject: wycheproof.go: modify some DSA and ECDSA code to work with opaque
 structs

---
 src/regress/lib/libcrypto/wycheproof/wycheproof.go | 28 ++++++++++++++++++----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go
index 9b22f1411e..b10792ab6f 100644
--- a/src/regress/lib/libcrypto/wycheproof/wycheproof.go
+++ b/src/regress/lib/libcrypto/wycheproof/wycheproof.go
@@ -1,4 +1,4 @@
-/* $OpenBSD: wycheproof.go,v 1.122 2021/09/24 20:48:23 tb Exp $ */
+/* $OpenBSD: wycheproof.go,v 1.123 2021/11/21 11:41:18 tb Exp $ */
 /*
  * Copyright (c) 2018 Joel Sing <jsing@openbsd.org>
  * Copyright (c) 2018, 2019 Theo Buehler <tb@openbsd.org>
@@ -1270,12 +1270,21 @@ func encodeDSAP1363Sig(wtSig string) (*C.uchar, C.int) {
 	s := C.CString(wtSig[sigLen/2:])
 	defer C.free(unsafe.Pointer(r))
 	defer C.free(unsafe.Pointer(s))
-	if C.BN_hex2bn(&cSig.r, r) == 0 {
+	var sigR *C.BIGNUM
+	var sigS *C.BIGNUM
+	defer C.BN_free(sigR)
+	defer C.BN_free(sigS)
+	if C.BN_hex2bn(&sigR, r) == 0 {
 		return nil, 0
 	}
-	if C.BN_hex2bn(&cSig.s, s) == 0 {
+	if C.BN_hex2bn(&sigS, s) == 0 {
 		return nil, 0
 	}
+	if C.DSA_SIG_set0(cSig, sigR, sigS) == 0 {
+		return nil, 0
+	}
+	sigR = nil
+	sigS = nil
 
 	derLen := C.i2d_DSA_SIG(cSig, nil)
 	if derLen == 0 {
@@ -1805,12 +1814,21 @@ func encodeECDSAWebCryptoSig(wtSig string) (*C.uchar, C.int) {
 	s := C.CString(wtSig[sigLen/2:])
 	defer C.free(unsafe.Pointer(r))
 	defer C.free(unsafe.Pointer(s))
-	if C.BN_hex2bn(&cSig.r, r) == 0 {
+	var sigR *C.BIGNUM
+	var sigS *C.BIGNUM
+	defer C.BN_free(sigR)
+	defer C.BN_free(sigS)
+	if C.BN_hex2bn(&sigR, r) == 0 {
+		return nil, 0
+	}
+	if C.BN_hex2bn(&sigS, s) == 0 {
 		return nil, 0
 	}
-	if C.BN_hex2bn(&cSig.s, s) == 0 {
+	if C.ECDSA_SIG_set0(cSig, sigR, sigS) == 0 {
 		return nil, 0
 	}
+	sigR = nil
+	sigS = nil
 
 	derLen := C.i2d_ECDSA_SIG(cSig, nil)
 	if derLen == 0 {
-- 
cgit v1.2.3-55-g6feb