diff options
| author | tb <> | 2018-10-06 04:35:54 +0000 |
|---|---|---|
| committer | tb <> | 2018-10-06 04:35:54 +0000 |
| commit | d71da30e07b96f3f7dd7607572929aacecc19475 (patch) | |
| tree | 4cffbd50e958b8f64ffa88bc2c05ec73251bcefd | |
| parent | c4825ca3364ed70107566706d8bcdf1d1ba8718e (diff) | |
| download | openbsd-d71da30e07b96f3f7dd7607572929aacecc19475.tar.gz openbsd-d71da30e07b96f3f7dd7607572929aacecc19475.tar.bz2 openbsd-d71da30e07b96f3f7dd7607572929aacecc19475.zip | |
make allocate/use/defer dances more consistent in ECDSA sig extraction
Diffstat (limited to '')
| -rw-r--r-- | src/regress/lib/libcrypto/wycheproof/wycheproof.go | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go index ee99050b3e..1a5aac87f1 100644 --- a/src/regress/lib/libcrypto/wycheproof/wycheproof.go +++ b/src/regress/lib/libcrypto/wycheproof/wycheproof.go | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: wycheproof.go,v 1.70 2018/10/05 21:12:43 tb Exp $ */ | 1 | /* $OpenBSD: wycheproof.go,v 1.71 2018/10/06 04:35:54 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> |
| 4 | * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> | 4 | * 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 | |||
| 1373 | } | 1373 | } |
| 1374 | 1374 | ||
| 1375 | // DER encode the signature (so that ECDSA_verify() can decode and encode it again...) | 1375 | // DER encode the signature (so that ECDSA_verify() can decode and encode it again...) |
| 1376 | sigLen := len(wt.Sig) | ||
| 1377 | r := C.CString(wt.Sig[:sigLen/2]) | ||
| 1378 | s := C.CString(wt.Sig[sigLen/2:]) | ||
| 1379 | |||
| 1380 | cSig := C.ECDSA_SIG_new() | 1376 | cSig := C.ECDSA_SIG_new() |
| 1381 | defer C.ECDSA_SIG_free(cSig) | ||
| 1382 | |||
| 1383 | if cSig == nil { | 1377 | if cSig == nil { |
| 1384 | log.Fatal("ECDSA_SIG_new() failed") | 1378 | log.Fatal("ECDSA_SIG_new() failed") |
| 1385 | } | 1379 | } |
| 1380 | defer C.ECDSA_SIG_free(cSig) | ||
| 1381 | |||
| 1382 | sigLen := len(wt.Sig) | ||
| 1383 | r := C.CString(wt.Sig[:sigLen/2]) | ||
| 1384 | s := C.CString(wt.Sig[sigLen/2:]) | ||
| 1386 | if C.BN_hex2bn(&cSig.r, r) == 0 { | 1385 | if C.BN_hex2bn(&cSig.r, r) == 0 { |
| 1387 | log.Fatal("Failed to set ECDSA r") | 1386 | log.Fatal("Failed to set ECDSA r") |
| 1388 | } | 1387 | } |
| @@ -1396,13 +1395,13 @@ func runECDSAWebCryptoTest(ecKey *C.EC_KEY, nid int, h hash.Hash, wt *wycheproof | |||
| 1396 | if derLen == 0 { | 1395 | if derLen == 0 { |
| 1397 | log.Fatal("i2d_ECDSA_SIG(cSig, nil) failed") | 1396 | log.Fatal("i2d_ECDSA_SIG(cSig, nil) failed") |
| 1398 | } | 1397 | } |
| 1399 | |||
| 1400 | cDer := (*C.uchar)(C.malloc(C.ulong(derLen))) | 1398 | cDer := (*C.uchar)(C.malloc(C.ulong(derLen))) |
| 1401 | if cDer == nil { | 1399 | if cDer == nil { |
| 1402 | log.Fatal("malloc failed") | 1400 | log.Fatal("malloc failed") |
| 1403 | } | 1401 | } |
| 1404 | p := cDer | ||
| 1405 | defer C.free(unsafe.Pointer(cDer)) | 1402 | defer C.free(unsafe.Pointer(cDer)) |
| 1403 | |||
| 1404 | p := cDer | ||
| 1406 | ret := C.i2d_ECDSA_SIG(cSig, (**C.uchar)(&p)) | 1405 | ret := C.i2d_ECDSA_SIG(cSig, (**C.uchar)(&p)) |
| 1407 | if ret == 0 || ret != derLen { | 1406 | if ret == 0 || ret != derLen { |
| 1408 | log.Fatalf("i2d_ECDSA_SIG(cSig, nil) failed, got %d, want %d", ret, derLen) | 1407 | log.Fatalf("i2d_ECDSA_SIG(cSig, nil) failed, got %d, want %d", ret, derLen) |
