-/* $OpenBSD: wycheproof.go,v 1.123 2021/11/21 11:41:18 tb Exp $ */
+/* $OpenBSD: wycheproof.go,v 1.124 2021/11/21 11:55:00 tb Exp $ */
/*
* Copyright (c) 2018 Joel Sing <jsing@openbsd.org>
* Copyright (c) 2018, 2019 Theo Buehler <tb@openbsd.org>
defer C.RSA_free(rsa)
d := C.CString(wtg.D)
- if C.BN_hex2bn(&rsa.d, d) == 0 {
+ var rsaD *C.BIGNUM
+ defer C.BN_free(rsaD)
+ if C.BN_hex2bn(&rsaD, d) == 0 {
log.Fatal("Failed to set RSA d")
}
C.free(unsafe.Pointer(d))
e := C.CString(wtg.E)
- if C.BN_hex2bn(&rsa.e, e) == 0 {
+ var rsaE *C.BIGNUM
+ defer C.BN_free(rsaE)
+ if C.BN_hex2bn(&rsaE, e) == 0 {
log.Fatal("Failed to set RSA e")
}
C.free(unsafe.Pointer(e))
n := C.CString(wtg.N)
- if C.BN_hex2bn(&rsa.n, n) == 0 {
+ var rsaN *C.BIGNUM
+ defer C.BN_free(rsaN)
+ if C.BN_hex2bn(&rsaN, n) == 0 {
log.Fatal("Failed to set RSA n")
}
C.free(unsafe.Pointer(n))
+ if C.RSA_set0_key(rsa, rsaN, rsaE, rsaD) == 0 {
+ log.Fatal("RSA_set0_key failed")
+ }
+ rsaN = nil
+ rsaE = nil
+ rsaD = nil
+
sha, err := hashEvpMdFromString(wtg.SHA)
if err != nil {
log.Fatalf("Failed to get hash: %v", err)
defer C.RSA_free(rsa)
d := C.CString(wtg.D)
- if C.BN_hex2bn(&rsa.d, d) == 0 {
+ var rsaD *C.BIGNUM
+ defer C.BN_free(rsaD)
+ if C.BN_hex2bn(&rsaD, d) == 0 {
log.Fatal("Failed to set RSA d")
}
C.free(unsafe.Pointer(d))
e := C.CString(wtg.E)
- if C.BN_hex2bn(&rsa.e, e) == 0 {
+ var rsaE *C.BIGNUM
+ defer C.BN_free(rsaE)
+ if C.BN_hex2bn(&rsaE, e) == 0 {
log.Fatal("Failed to set RSA e")
}
C.free(unsafe.Pointer(e))
n := C.CString(wtg.N)
- if C.BN_hex2bn(&rsa.n, n) == 0 {
+ var rsaN *C.BIGNUM
+ defer C.BN_free(rsaN)
+ if C.BN_hex2bn(&rsaN, n) == 0 {
log.Fatal("Failed to set RSA n")
}
C.free(unsafe.Pointer(n))
+ if C.RSA_set0_key(rsa, rsaN, rsaE, rsaD) == 0 {
+ log.Fatal("RSA_set0_key failed")
+ }
+ rsaN = nil
+ rsaE = nil
+ rsaD = nil
+
success := true
for _, wt := range wtg.Tests {
if !runRsaesPkcs1Test(rsa, wt) {
defer C.RSA_free(rsa)
e := C.CString(wtg.E)
- if C.BN_hex2bn(&rsa.e, e) == 0 {
+ var rsaE *C.BIGNUM
+ defer C.BN_free(rsaE)
+ if C.BN_hex2bn(&rsaE, e) == 0 {
log.Fatal("Failed to set RSA e")
}
C.free(unsafe.Pointer(e))
n := C.CString(wtg.N)
- if C.BN_hex2bn(&rsa.n, n) == 0 {
+ var rsaN *C.BIGNUM
+ defer C.BN_free(rsaN)
+ if C.BN_hex2bn(&rsaN, n) == 0 {
log.Fatal("Failed to set RSA n")
}
C.free(unsafe.Pointer(n))
+ if C.RSA_set0_key(rsa, rsaN, rsaE, nil) == 0 {
+ log.Fatal("RSA_set0_key failed")
+ }
+ rsaN = nil
+ rsaE = nil
+
h, err := hashFromString(wtg.SHA)
if err != nil {
log.Fatalf("Failed to get hash: %v", err)
defer C.RSA_free(rsa)
e := C.CString(wtg.E)
- if C.BN_hex2bn(&rsa.e, e) == 0 {
+ var rsaE *C.BIGNUM
+ defer C.BN_free(rsaE)
+ if C.BN_hex2bn(&rsaE, e) == 0 {
log.Fatal("Failed to set RSA e")
}
C.free(unsafe.Pointer(e))
n := C.CString(wtg.N)
- if C.BN_hex2bn(&rsa.n, n) == 0 {
+ var rsaN *C.BIGNUM
+ defer C.BN_free(rsaN)
+ if C.BN_hex2bn(&rsaN, n) == 0 {
log.Fatal("Failed to set RSA n")
}
C.free(unsafe.Pointer(n))
+ if C.RSA_set0_key(rsa, rsaN, rsaE, nil) == 0 {
+ log.Fatal("RSA_set0_key failed")
+ }
+ rsaN = nil
+ rsaE = nil
+
nid, err := nidFromString(wtg.SHA)
if err != nil {
log.Fatalf("Failed to get MD NID: %v", err)