summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2021-11-21 11:55:00 +0000
committertb <>2021-11-21 11:55:00 +0000
commitff6fd818e90db619298226b17102f94cb10a855c (patch)
tree97155f00000316eefe734e55b80aa8379228dd2f /src
parenta5c73ac97b067daed19c07515f4e72156bfa21d4 (diff)
downloadopenbsd-ff6fd818e90db619298226b17102f94cb10a855c.tar.gz
openbsd-ff6fd818e90db619298226b17102f94cb10a855c.tar.bz2
openbsd-ff6fd818e90db619298226b17102f94cb10a855c.zip
wycheproof: modify RSA tests to work with opaque RSA struct
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/wycheproof/wycheproof.go68
1 files changed, 57 insertions, 11 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go
index b10792ab6f..e23b100bf7 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.123 2021/11/21 11:41:18 tb Exp $ */ 1/* $OpenBSD: wycheproof.go,v 1.124 2021/11/21 11:55:00 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, 2019 Theo Buehler <tb@openbsd.org> 4 * Copyright (c) 2018, 2019 Theo Buehler <tb@openbsd.org>
@@ -2229,23 +2229,36 @@ func runRsaesOaepTestGroup(algorithm string, wtg *wycheproofTestGroupRsaesOaep)
2229 defer C.RSA_free(rsa) 2229 defer C.RSA_free(rsa)
2230 2230
2231 d := C.CString(wtg.D) 2231 d := C.CString(wtg.D)
2232 if C.BN_hex2bn(&rsa.d, d) == 0 { 2232 var rsaD *C.BIGNUM
2233 defer C.BN_free(rsaD)
2234 if C.BN_hex2bn(&rsaD, d) == 0 {
2233 log.Fatal("Failed to set RSA d") 2235 log.Fatal("Failed to set RSA d")
2234 } 2236 }
2235 C.free(unsafe.Pointer(d)) 2237 C.free(unsafe.Pointer(d))
2236 2238
2237 e := C.CString(wtg.E) 2239 e := C.CString(wtg.E)
2238 if C.BN_hex2bn(&rsa.e, e) == 0 { 2240 var rsaE *C.BIGNUM
2241 defer C.BN_free(rsaE)
2242 if C.BN_hex2bn(&rsaE, e) == 0 {
2239 log.Fatal("Failed to set RSA e") 2243 log.Fatal("Failed to set RSA e")
2240 } 2244 }
2241 C.free(unsafe.Pointer(e)) 2245 C.free(unsafe.Pointer(e))
2242 2246
2243 n := C.CString(wtg.N) 2247 n := C.CString(wtg.N)
2244 if C.BN_hex2bn(&rsa.n, n) == 0 { 2248 var rsaN *C.BIGNUM
2249 defer C.BN_free(rsaN)
2250 if C.BN_hex2bn(&rsaN, n) == 0 {
2245 log.Fatal("Failed to set RSA n") 2251 log.Fatal("Failed to set RSA n")
2246 } 2252 }
2247 C.free(unsafe.Pointer(n)) 2253 C.free(unsafe.Pointer(n))
2248 2254
2255 if C.RSA_set0_key(rsa, rsaN, rsaE, rsaD) == 0 {
2256 log.Fatal("RSA_set0_key failed")
2257 }
2258 rsaN = nil
2259 rsaE = nil
2260 rsaD = nil
2261
2249 sha, err := hashEvpMdFromString(wtg.SHA) 2262 sha, err := hashEvpMdFromString(wtg.SHA)
2250 if err != nil { 2263 if err != nil {
2251 log.Fatalf("Failed to get hash: %v", err) 2264 log.Fatalf("Failed to get hash: %v", err)
@@ -2316,23 +2329,36 @@ func runRsaesPkcs1TestGroup(algorithm string, wtg *wycheproofTestGroupRsaesPkcs1
2316 defer C.RSA_free(rsa) 2329 defer C.RSA_free(rsa)
2317 2330
2318 d := C.CString(wtg.D) 2331 d := C.CString(wtg.D)
2319 if C.BN_hex2bn(&rsa.d, d) == 0 { 2332 var rsaD *C.BIGNUM
2333 defer C.BN_free(rsaD)
2334 if C.BN_hex2bn(&rsaD, d) == 0 {
2320 log.Fatal("Failed to set RSA d") 2335 log.Fatal("Failed to set RSA d")
2321 } 2336 }
2322 C.free(unsafe.Pointer(d)) 2337 C.free(unsafe.Pointer(d))
2323 2338
2324 e := C.CString(wtg.E) 2339 e := C.CString(wtg.E)
2325 if C.BN_hex2bn(&rsa.e, e) == 0 { 2340 var rsaE *C.BIGNUM
2341 defer C.BN_free(rsaE)
2342 if C.BN_hex2bn(&rsaE, e) == 0 {
2326 log.Fatal("Failed to set RSA e") 2343 log.Fatal("Failed to set RSA e")
2327 } 2344 }
2328 C.free(unsafe.Pointer(e)) 2345 C.free(unsafe.Pointer(e))
2329 2346
2330 n := C.CString(wtg.N) 2347 n := C.CString(wtg.N)
2331 if C.BN_hex2bn(&rsa.n, n) == 0 { 2348 var rsaN *C.BIGNUM
2349 defer C.BN_free(rsaN)
2350 if C.BN_hex2bn(&rsaN, n) == 0 {
2332 log.Fatal("Failed to set RSA n") 2351 log.Fatal("Failed to set RSA n")
2333 } 2352 }
2334 C.free(unsafe.Pointer(n)) 2353 C.free(unsafe.Pointer(n))
2335 2354
2355 if C.RSA_set0_key(rsa, rsaN, rsaE, rsaD) == 0 {
2356 log.Fatal("RSA_set0_key failed")
2357 }
2358 rsaN = nil
2359 rsaE = nil
2360 rsaD = nil
2361
2336 success := true 2362 success := true
2337 for _, wt := range wtg.Tests { 2363 for _, wt := range wtg.Tests {
2338 if !runRsaesPkcs1Test(rsa, wt) { 2364 if !runRsaesPkcs1Test(rsa, wt) {
@@ -2411,17 +2437,27 @@ func runRsassaTestGroup(algorithm string, wtg *wycheproofTestGroupRsassa) bool {
2411 defer C.RSA_free(rsa) 2437 defer C.RSA_free(rsa)
2412 2438
2413 e := C.CString(wtg.E) 2439 e := C.CString(wtg.E)
2414 if C.BN_hex2bn(&rsa.e, e) == 0 { 2440 var rsaE *C.BIGNUM
2441 defer C.BN_free(rsaE)
2442 if C.BN_hex2bn(&rsaE, e) == 0 {
2415 log.Fatal("Failed to set RSA e") 2443 log.Fatal("Failed to set RSA e")
2416 } 2444 }
2417 C.free(unsafe.Pointer(e)) 2445 C.free(unsafe.Pointer(e))
2418 2446
2419 n := C.CString(wtg.N) 2447 n := C.CString(wtg.N)
2420 if C.BN_hex2bn(&rsa.n, n) == 0 { 2448 var rsaN *C.BIGNUM
2449 defer C.BN_free(rsaN)
2450 if C.BN_hex2bn(&rsaN, n) == 0 {
2421 log.Fatal("Failed to set RSA n") 2451 log.Fatal("Failed to set RSA n")
2422 } 2452 }
2423 C.free(unsafe.Pointer(n)) 2453 C.free(unsafe.Pointer(n))
2424 2454
2455 if C.RSA_set0_key(rsa, rsaN, rsaE, nil) == 0 {
2456 log.Fatal("RSA_set0_key failed")
2457 }
2458 rsaN = nil
2459 rsaE = nil
2460
2425 h, err := hashFromString(wtg.SHA) 2461 h, err := hashFromString(wtg.SHA)
2426 if err != nil { 2462 if err != nil {
2427 log.Fatalf("Failed to get hash: %v", err) 2463 log.Fatalf("Failed to get hash: %v", err)
@@ -2496,17 +2532,27 @@ func runRSATestGroup(algorithm string, wtg *wycheproofTestGroupRSA) bool {
2496 defer C.RSA_free(rsa) 2532 defer C.RSA_free(rsa)
2497 2533
2498 e := C.CString(wtg.E) 2534 e := C.CString(wtg.E)
2499 if C.BN_hex2bn(&rsa.e, e) == 0 { 2535 var rsaE *C.BIGNUM
2536 defer C.BN_free(rsaE)
2537 if C.BN_hex2bn(&rsaE, e) == 0 {
2500 log.Fatal("Failed to set RSA e") 2538 log.Fatal("Failed to set RSA e")
2501 } 2539 }
2502 C.free(unsafe.Pointer(e)) 2540 C.free(unsafe.Pointer(e))
2503 2541
2504 n := C.CString(wtg.N) 2542 n := C.CString(wtg.N)
2505 if C.BN_hex2bn(&rsa.n, n) == 0 { 2543 var rsaN *C.BIGNUM
2544 defer C.BN_free(rsaN)
2545 if C.BN_hex2bn(&rsaN, n) == 0 {
2506 log.Fatal("Failed to set RSA n") 2546 log.Fatal("Failed to set RSA n")
2507 } 2547 }
2508 C.free(unsafe.Pointer(n)) 2548 C.free(unsafe.Pointer(n))
2509 2549
2550 if C.RSA_set0_key(rsa, rsaN, rsaE, nil) == 0 {
2551 log.Fatal("RSA_set0_key failed")
2552 }
2553 rsaN = nil
2554 rsaE = nil
2555
2510 nid, err := nidFromString(wtg.SHA) 2556 nid, err := nidFromString(wtg.SHA)
2511 if err != nil { 2557 if err != nil {
2512 log.Fatalf("Failed to get MD NID: %v", err) 2558 log.Fatalf("Failed to get MD NID: %v", err)