diff options
-rw-r--r-- | src/regress/lib/libcrypto/wycheproof/wycheproof.go | 122 |
1 files changed, 79 insertions, 43 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go index 3a2a1b7fde..f161211d3e 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.175 2025/09/05 11:25:50 tb Exp $ */ | 1 | /* $OpenBSD: wycheproof.go,v 1.176 2025/09/05 13:47:41 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018,2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2018,2023 Joel Sing <jsing@openbsd.org> |
4 | * Copyright (c) 2018,2019,2022-2024 Theo Buehler <tb@openbsd.org> | 4 | * Copyright (c) 2018,2019,2022-2024 Theo Buehler <tb@openbsd.org> |
@@ -461,15 +461,31 @@ func (wt *wycheproofTestRSA) String() string { | |||
461 | } | 461 | } |
462 | 462 | ||
463 | type wycheproofTestGroupRSA struct { | 463 | type wycheproofTestGroupRSA struct { |
464 | E string `json:"e"` | 464 | PrivateKey *wycheproofRSAPrivateKey `json:"privateKey"` |
465 | KeyASN string `json:"keyAsn"` | 465 | PublicKey *wycheproofRSAPublicKey `json:"publicKey"` |
466 | KeyDER string `json:"keyDer"` | 466 | KeyASN string `json:"keyAsn"` |
467 | KeyPEM string `json:"keyPem"` | 467 | KeyDER string `json:"keyDer"` |
468 | KeySize int `json:"keysize"` | 468 | KeyPEM string `json:"keyPem"` |
469 | N string `json:"n"` | 469 | KeySize int `json:"keysize"` |
470 | SHA string `json:"sha"` | 470 | SHA string `json:"sha"` |
471 | Type string `json:"type"` | 471 | Type string `json:"type"` |
472 | Tests []*wycheproofTestRSA `json:"tests"` | 472 | Tests []*wycheproofTestRSA `json:"tests"` |
473 | } | ||
474 | |||
475 | type wycheproofRSAPublicKey struct { | ||
476 | Modulus string `json:"modulus"` | ||
477 | PublicExponent string `json:"publicExponent"` | ||
478 | } | ||
479 | |||
480 | type wycheproofRSAPrivateKey struct { | ||
481 | Modulus string `json:"modulus"` | ||
482 | PrivateExponent string `json:"privateExponent"` | ||
483 | PublicExponent string `json:"publicExponent"` | ||
484 | Prime1 string `json:"prime1"` | ||
485 | Prime2 string `json:"prime2"` | ||
486 | Exponent1 string `json:"exponent1"` | ||
487 | Exponent2 string `json:"exponent2"` | ||
488 | Coefficient string `json:"coefficient"` | ||
473 | } | 489 | } |
474 | 490 | ||
475 | type wycheproofPrivateKeyJwk struct { | 491 | type wycheproofPrivateKeyJwk struct { |
@@ -501,29 +517,25 @@ func (wt *wycheproofTestRsaes) String() string { | |||
501 | } | 517 | } |
502 | 518 | ||
503 | type wycheproofTestGroupRsaesOaep struct { | 519 | type wycheproofTestGroupRsaesOaep struct { |
504 | D string `json:"d"` | 520 | Type string `json:"type"` |
505 | E string `json:"e"` | ||
506 | KeySize int `json:"keysize"` | 521 | KeySize int `json:"keysize"` |
522 | SHA string `json:"sha"` | ||
507 | MGF string `json:"mgf"` | 523 | MGF string `json:"mgf"` |
508 | MGFSHA string `json:"mgfSha"` | 524 | MGFSHA string `json:"mgfSha"` |
509 | N string `json:"n"` | 525 | PrivateKey *wycheproofRSAPrivateKey `json:"privateKey"` |
510 | PrivateKeyJwk *wycheproofPrivateKeyJwk `json:"privateKeyJwk"` | 526 | PrivateKeyJwk *wycheproofPrivateKeyJwk `json:"privateKeyJwk"` |
511 | PrivateKeyPem string `json:"privateKeyPem"` | 527 | PrivateKeyPem string `json:"privateKeyPem"` |
512 | PrivateKeyPkcs8 string `json:"privateKeyPkcs8"` | 528 | PrivateKeyPkcs8 string `json:"privateKeyPkcs8"` |
513 | SHA string `json:"sha"` | ||
514 | Type string `json:"type"` | ||
515 | Tests []*wycheproofTestRsaes `json:"tests"` | 529 | Tests []*wycheproofTestRsaes `json:"tests"` |
516 | } | 530 | } |
517 | 531 | ||
518 | type wycheproofTestGroupRsaesPkcs1 struct { | 532 | type wycheproofTestGroupRsaesPkcs1 struct { |
519 | D string `json:"d"` | 533 | Type string `json:"type"` |
520 | E string `json:"e"` | 534 | PrivateKey *wycheproofRSAPrivateKey `json:"privateKey"` |
521 | KeySize int `json:"keysize"` | ||
522 | N string `json:"n"` | ||
523 | PrivateKeyJwk *wycheproofPrivateKeyJwk `json:"privateKeyJwk"` | 535 | PrivateKeyJwk *wycheproofPrivateKeyJwk `json:"privateKeyJwk"` |
524 | PrivateKeyPem string `json:"privateKeyPem"` | 536 | PrivateKeyPem string `json:"privateKeyPem"` |
525 | PrivateKeyPkcs8 string `json:"privateKeyPkcs8"` | 537 | PrivateKeyPkcs8 string `json:"privateKeyPkcs8"` |
526 | Type string `json:"type"` | 538 | KeySize int `json:"keysize"` |
527 | Tests []*wycheproofTestRsaes `json:"tests"` | 539 | Tests []*wycheproofTestRsaes `json:"tests"` |
528 | } | 540 | } |
529 | 541 | ||
@@ -541,18 +553,18 @@ func (wt *wycheproofTestRsassa) String() string { | |||
541 | } | 553 | } |
542 | 554 | ||
543 | type wycheproofTestGroupRsassa struct { | 555 | type wycheproofTestGroupRsassa struct { |
544 | E string `json:"e"` | 556 | PrivateKey *wycheproofRSAPrivateKey `json:"privateKey"` |
545 | KeyASN string `json:"keyAsn"` | 557 | PublicKey *wycheproofRSAPublicKey `json:"publicKey"` |
546 | KeyDER string `json:"keyDer"` | 558 | KeyASN string `json:"keyAsn"` |
547 | KeyPEM string `json:"keyPem"` | 559 | KeyDER string `json:"keyDer"` |
548 | KeySize int `json:"keysize"` | 560 | KeyPEM string `json:"keyPem"` |
549 | MGF string `json:"mgf"` | 561 | KeySize int `json:"keysize"` |
550 | MGFSHA string `json:"mgfSha"` | 562 | MGF string `json:"mgf"` |
551 | N string `json:"n"` | 563 | MGFSHA string `json:"mgfSha"` |
552 | SLen int `json:"sLen"` | 564 | SLen int `json:"sLen"` |
553 | SHA string `json:"sha"` | 565 | SHA string `json:"sha"` |
554 | Type string `json:"type"` | 566 | Type string `json:"type"` |
555 | Tests []*wycheproofTestRsassa `json:"tests"` | 567 | Tests []*wycheproofTestRsassa `json:"tests"` |
556 | } | 568 | } |
557 | 569 | ||
558 | type wycheproofTestX25519 struct { | 570 | type wycheproofTestX25519 struct { |
@@ -2303,7 +2315,7 @@ func (wtg *wycheproofTestGroupRsaesOaep) run(algorithm string, variant testVaria | |||
2303 | } | 2315 | } |
2304 | defer C.RSA_free(rsa) | 2316 | defer C.RSA_free(rsa) |
2305 | 2317 | ||
2306 | d := C.CString(wtg.D) | 2318 | d := C.CString(wtg.PrivateKey.PrivateExponent) |
2307 | var rsaD *C.BIGNUM | 2319 | var rsaD *C.BIGNUM |
2308 | defer C.BN_free(rsaD) | 2320 | defer C.BN_free(rsaD) |
2309 | if C.BN_hex2bn(&rsaD, d) == 0 { | 2321 | if C.BN_hex2bn(&rsaD, d) == 0 { |
@@ -2311,7 +2323,7 @@ func (wtg *wycheproofTestGroupRsaesOaep) run(algorithm string, variant testVaria | |||
2311 | } | 2323 | } |
2312 | C.free(unsafe.Pointer(d)) | 2324 | C.free(unsafe.Pointer(d)) |
2313 | 2325 | ||
2314 | e := C.CString(wtg.E) | 2326 | e := C.CString(wtg.PrivateKey.PublicExponent) |
2315 | var rsaE *C.BIGNUM | 2327 | var rsaE *C.BIGNUM |
2316 | defer C.BN_free(rsaE) | 2328 | defer C.BN_free(rsaE) |
2317 | if C.BN_hex2bn(&rsaE, e) == 0 { | 2329 | if C.BN_hex2bn(&rsaE, e) == 0 { |
@@ -2319,7 +2331,7 @@ func (wtg *wycheproofTestGroupRsaesOaep) run(algorithm string, variant testVaria | |||
2319 | } | 2331 | } |
2320 | C.free(unsafe.Pointer(e)) | 2332 | C.free(unsafe.Pointer(e)) |
2321 | 2333 | ||
2322 | n := C.CString(wtg.N) | 2334 | n := C.CString(wtg.PrivateKey.Modulus) |
2323 | var rsaN *C.BIGNUM | 2335 | var rsaN *C.BIGNUM |
2324 | defer C.BN_free(rsaN) | 2336 | defer C.BN_free(rsaN) |
2325 | if C.BN_hex2bn(&rsaN, n) == 0 { | 2337 | if C.BN_hex2bn(&rsaN, n) == 0 { |
@@ -2393,7 +2405,7 @@ func (wtg *wycheproofTestGroupRsaesPkcs1) run(algorithm string, variant testVari | |||
2393 | } | 2405 | } |
2394 | defer C.RSA_free(rsa) | 2406 | defer C.RSA_free(rsa) |
2395 | 2407 | ||
2396 | d := C.CString(wtg.D) | 2408 | d := C.CString(wtg.PrivateKey.PrivateExponent) |
2397 | var rsaD *C.BIGNUM | 2409 | var rsaD *C.BIGNUM |
2398 | defer C.BN_free(rsaD) | 2410 | defer C.BN_free(rsaD) |
2399 | if C.BN_hex2bn(&rsaD, d) == 0 { | 2411 | if C.BN_hex2bn(&rsaD, d) == 0 { |
@@ -2401,7 +2413,7 @@ func (wtg *wycheproofTestGroupRsaesPkcs1) run(algorithm string, variant testVari | |||
2401 | } | 2413 | } |
2402 | C.free(unsafe.Pointer(d)) | 2414 | C.free(unsafe.Pointer(d)) |
2403 | 2415 | ||
2404 | e := C.CString(wtg.E) | 2416 | e := C.CString(wtg.PrivateKey.PublicExponent) |
2405 | var rsaE *C.BIGNUM | 2417 | var rsaE *C.BIGNUM |
2406 | defer C.BN_free(rsaE) | 2418 | defer C.BN_free(rsaE) |
2407 | if C.BN_hex2bn(&rsaE, e) == 0 { | 2419 | if C.BN_hex2bn(&rsaE, e) == 0 { |
@@ -2409,7 +2421,7 @@ func (wtg *wycheproofTestGroupRsaesPkcs1) run(algorithm string, variant testVari | |||
2409 | } | 2421 | } |
2410 | C.free(unsafe.Pointer(e)) | 2422 | C.free(unsafe.Pointer(e)) |
2411 | 2423 | ||
2412 | n := C.CString(wtg.N) | 2424 | n := C.CString(wtg.PrivateKey.Modulus) |
2413 | var rsaN *C.BIGNUM | 2425 | var rsaN *C.BIGNUM |
2414 | defer C.BN_free(rsaN) | 2426 | defer C.BN_free(rsaN) |
2415 | if C.BN_hex2bn(&rsaN, n) == 0 { | 2427 | if C.BN_hex2bn(&rsaN, n) == 0 { |
@@ -2474,7 +2486,19 @@ func (wtg *wycheproofTestGroupRsassa) run(algorithm string, variant testVariant) | |||
2474 | } | 2486 | } |
2475 | defer C.RSA_free(rsa) | 2487 | defer C.RSA_free(rsa) |
2476 | 2488 | ||
2477 | e := C.CString(wtg.E) | 2489 | var publicExponent, modulus string |
2490 | if wtg.PublicKey != nil { | ||
2491 | publicExponent = wtg.PublicKey.PublicExponent | ||
2492 | modulus = wtg.PublicKey.Modulus | ||
2493 | } else if wtg.PrivateKey != nil { | ||
2494 | publicExponent = wtg.PrivateKey.PublicExponent | ||
2495 | modulus = wtg.PrivateKey.Modulus | ||
2496 | } | ||
2497 | if publicExponent == "" || modulus == "" { | ||
2498 | return true | ||
2499 | } | ||
2500 | |||
2501 | e := C.CString(publicExponent) | ||
2478 | var rsaE *C.BIGNUM | 2502 | var rsaE *C.BIGNUM |
2479 | defer C.BN_free(rsaE) | 2503 | defer C.BN_free(rsaE) |
2480 | if C.BN_hex2bn(&rsaE, e) == 0 { | 2504 | if C.BN_hex2bn(&rsaE, e) == 0 { |
@@ -2482,7 +2506,7 @@ func (wtg *wycheproofTestGroupRsassa) run(algorithm string, variant testVariant) | |||
2482 | } | 2506 | } |
2483 | C.free(unsafe.Pointer(e)) | 2507 | C.free(unsafe.Pointer(e)) |
2484 | 2508 | ||
2485 | n := C.CString(wtg.N) | 2509 | n := C.CString(modulus) |
2486 | var rsaN *C.BIGNUM | 2510 | var rsaN *C.BIGNUM |
2487 | defer C.BN_free(rsaN) | 2511 | defer C.BN_free(rsaN) |
2488 | if C.BN_hex2bn(&rsaN, n) == 0 { | 2512 | if C.BN_hex2bn(&rsaN, n) == 0 { |
@@ -2539,7 +2563,19 @@ func (wtg *wycheproofTestGroupRSA) run(algorithm string, variant testVariant) bo | |||
2539 | } | 2563 | } |
2540 | defer C.RSA_free(rsa) | 2564 | defer C.RSA_free(rsa) |
2541 | 2565 | ||
2542 | e := C.CString(wtg.E) | 2566 | var publicExponent, modulus string |
2567 | if wtg.PublicKey != nil { | ||
2568 | publicExponent = wtg.PublicKey.PublicExponent | ||
2569 | modulus = wtg.PublicKey.Modulus | ||
2570 | } else if wtg.PrivateKey != nil { | ||
2571 | publicExponent = wtg.PrivateKey.PublicExponent | ||
2572 | modulus = wtg.PrivateKey.Modulus | ||
2573 | } | ||
2574 | if publicExponent == "" || modulus == "" { | ||
2575 | return true | ||
2576 | } | ||
2577 | |||
2578 | e := C.CString(publicExponent) | ||
2543 | var rsaE *C.BIGNUM | 2579 | var rsaE *C.BIGNUM |
2544 | defer C.BN_free(rsaE) | 2580 | defer C.BN_free(rsaE) |
2545 | if C.BN_hex2bn(&rsaE, e) == 0 { | 2581 | if C.BN_hex2bn(&rsaE, e) == 0 { |
@@ -2547,7 +2583,7 @@ func (wtg *wycheproofTestGroupRSA) run(algorithm string, variant testVariant) bo | |||
2547 | } | 2583 | } |
2548 | C.free(unsafe.Pointer(e)) | 2584 | C.free(unsafe.Pointer(e)) |
2549 | 2585 | ||
2550 | n := C.CString(wtg.N) | 2586 | n := C.CString(modulus) |
2551 | var rsaN *C.BIGNUM | 2587 | var rsaN *C.BIGNUM |
2552 | defer C.BN_free(rsaN) | 2588 | defer C.BN_free(rsaN) |
2553 | if C.BN_hex2bn(&rsaN, n) == 0 { | 2589 | if C.BN_hex2bn(&rsaN, n) == 0 { |
@@ -2775,7 +2811,7 @@ func main() { | |||
2775 | {v0, "JSON webcrypto", "json_web_*_test.json", Skip}, | 2811 | {v0, "JSON webcrypto", "json_web_*_test.json", Skip}, |
2776 | {v0, "KW", "kw_test.json", Normal}, | 2812 | {v0, "KW", "kw_test.json", Normal}, |
2777 | {v0, "Primality test", "primality_test.json", Normal}, | 2813 | {v0, "Primality test", "primality_test.json", Normal}, |
2778 | {v0, "RSA", "rsa_*test.json", Normal}, | 2814 | {v1, "RSA", "rsa_*test.json", Normal}, |
2779 | {v1, "X25519", "x25519_test.json", Normal}, | 2815 | {v1, "X25519", "x25519_test.json", Normal}, |
2780 | {v1, "X25519 ASN", "x25519_asn_test.json", Skip}, | 2816 | {v1, "X25519 ASN", "x25519_asn_test.json", Skip}, |
2781 | {v1, "X25519 JWK", "x25519_jwk_test.json", Skip}, | 2817 | {v1, "X25519 JWK", "x25519_jwk_test.json", Skip}, |