diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2018-10-06 04:35:55 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2018-10-06 04:35:55 +0000 |
commit | dcf8e78cee320eee98dca6ea08213bef90f218ac (patch) | |
tree | 71141907de55336d38d4101cf3e7731781b05f9e /regress | |
parent | fff44364f65bed34840f76bb1ebd047891441e0c (diff) |
make allocate/use/defer dances more consistent in ECDSA sig extraction
Diffstat (limited to 'regress')
-rw-r--r-- | regress/lib/libcrypto/wycheproof/wycheproof.go | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/regress/lib/libcrypto/wycheproof/wycheproof.go b/regress/lib/libcrypto/wycheproof/wycheproof.go index ee99050b3e3..1a5aac87f14 100644 --- a/regress/lib/libcrypto/wycheproof/wycheproof.go +++ b/regress/lib/libcrypto/wycheproof/wycheproof.go @@ -1,4 +1,4 @@ -/* $OpenBSD: wycheproof.go,v 1.70 2018/10/05 21:12:43 tb Exp $ */ +/* $OpenBSD: wycheproof.go,v 1.71 2018/10/06 04:35:54 tb Exp $ */ /* * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> @@ -1373,16 +1373,15 @@ func runECDSAWebCryptoTest(ecKey *C.EC_KEY, nid int, h hash.Hash, wt *wycheproof } // DER encode the signature (so that ECDSA_verify() can decode and encode it again...) - sigLen := len(wt.Sig) - r := C.CString(wt.Sig[:sigLen/2]) - s := C.CString(wt.Sig[sigLen/2:]) - cSig := C.ECDSA_SIG_new() - defer C.ECDSA_SIG_free(cSig) - if cSig == nil { log.Fatal("ECDSA_SIG_new() failed") } + defer C.ECDSA_SIG_free(cSig) + + sigLen := len(wt.Sig) + r := C.CString(wt.Sig[:sigLen/2]) + s := C.CString(wt.Sig[sigLen/2:]) if C.BN_hex2bn(&cSig.r, r) == 0 { log.Fatal("Failed to set ECDSA r") } @@ -1396,13 +1395,13 @@ func runECDSAWebCryptoTest(ecKey *C.EC_KEY, nid int, h hash.Hash, wt *wycheproof if derLen == 0 { log.Fatal("i2d_ECDSA_SIG(cSig, nil) failed") } - cDer := (*C.uchar)(C.malloc(C.ulong(derLen))) if cDer == nil { log.Fatal("malloc failed") } - p := cDer defer C.free(unsafe.Pointer(cDer)) + + p := cDer ret := C.i2d_ECDSA_SIG(cSig, (**C.uchar)(&p)) if ret == 0 || ret != derLen { log.Fatalf("i2d_ECDSA_SIG(cSig, nil) failed, got %d, want %d", ret, derLen) |