diff options
| author | tb <> | 2018-09-15 19:12:31 +0000 |
|---|---|---|
| committer | tb <> | 2018-09-15 19:12:31 +0000 |
| commit | 3875c458d6db4d4a2f8351955225e12d113781ec (patch) | |
| tree | f95d39d0b3d230cfe8361cbdca35ab96abe66058 /src | |
| parent | 7e0e5259b21e1e4717aecffec84ee32f0cdc0b02 (diff) | |
| download | openbsd-3875c458d6db4d4a2f8351955225e12d113781ec.tar.gz openbsd-3875c458d6db4d4a2f8351955225e12d113781ec.tar.bz2 openbsd-3875c458d6db4d4a2f8351955225e12d113781ec.zip | |
Also exercise EVP_aead_aes_128_gcm() and EVP_aead_aes_256_gcm().
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/wycheproof/wycheproof.go | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go index 77011ef616..6cb853ad6f 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.49 2018/09/15 19:09:07 tb Exp $ */ | 1 | /* $OpenBSD: wycheproof.go,v 1.50 2018/09/15 19:12:31 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> |
| @@ -576,7 +576,7 @@ func checkAesCcmOrGcm(algorithm string, ctx *C.EVP_CIPHER_CTX, doEncrypt int, ke | |||
| 576 | return success | 576 | return success |
| 577 | } | 577 | } |
| 578 | 578 | ||
| 579 | func runAesCcmOrGcmTest(algorithm string, ctx *C.EVP_CIPHER_CTX, wt *wycheproofTestAead) bool { | 579 | func runAesCcmOrGcmTest(algorithm string, ctx *C.EVP_CIPHER_CTX, aead *C.EVP_AEAD, wt *wycheproofTestAead) bool { |
| 580 | key, err := hex.DecodeString(wt.Key) | 580 | key, err := hex.DecodeString(wt.Key) |
| 581 | if err != nil { | 581 | if err != nil { |
| 582 | log.Fatalf("Failed to decode key %q: %v", wt.Key, err) | 582 | log.Fatalf("Failed to decode key %q: %v", wt.Key, err) |
| @@ -628,16 +628,34 @@ func runAesCcmOrGcmTest(algorithm string, ctx *C.EVP_CIPHER_CTX, wt *wycheproofT | |||
| 628 | tag = append(tag, 0) | 628 | tag = append(tag, 0) |
| 629 | } | 629 | } |
| 630 | 630 | ||
| 631 | openSuccess := checkAesCcmOrGcm(algorithm, ctx, 0, key, keyLen, iv, ivLen, aad, aadLen, ct, ctLen, msg, msgLen, tag, tagLen, wt) | 631 | openEvp := checkAesCcmOrGcm(algorithm, ctx, 0, key, keyLen, iv, ivLen, aad, aadLen, ct, ctLen, msg, msgLen, tag, tagLen, wt) |
| 632 | sealSuccess := checkAesCcmOrGcm(algorithm, ctx, 1, key, keyLen, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt) | 632 | sealEvp := checkAesCcmOrGcm(algorithm, ctx, 1, key, keyLen, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt) |
| 633 | 633 | ||
| 634 | return openSuccess && sealSuccess | 634 | openAead, sealAead := true, true |
| 635 | if aead != nil { | ||
| 636 | var ctx C.EVP_AEAD_CTX | ||
| 637 | if C.EVP_AEAD_CTX_init(&ctx, aead, (*C.uchar)(unsafe.Pointer(&key[0])), C.size_t(keyLen), C.size_t(tagLen), nil) != 1 { | ||
| 638 | log.Fatal("Failed to initialize AEAD context") | ||
| 639 | } | ||
| 640 | defer C.EVP_AEAD_CTX_cleanup(&ctx) | ||
| 641 | |||
| 642 | // Make sure we don't accidentally prepend or compare against a 0. | ||
| 643 | if ctLen == 0 { | ||
| 644 | ct = nil | ||
| 645 | } | ||
| 646 | |||
| 647 | openAead = checkAeadOpen(&ctx, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt) | ||
| 648 | sealAead = checkAeadSeal(&ctx, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt) | ||
| 649 | } | ||
| 650 | |||
| 651 | return openEvp && sealEvp && openAead && sealAead | ||
| 635 | } | 652 | } |
| 636 | 653 | ||
| 637 | func runAesCcmOrGcmTestGroup(algorithm string, wtg *wycheproofTestGroupAead) bool { | 654 | func runAesCcmOrGcmTestGroup(algorithm string, wtg *wycheproofTestGroupAead) bool { |
| 638 | fmt.Printf("Running %v test group %v with IV size %d, key size %d and tag size %d...\n", algorithm, wtg.Type, wtg.IVSize, wtg.KeySize, wtg.TagSize) | 655 | fmt.Printf("Running %v test group %v with IV size %d, key size %d and tag size %d...\n", algorithm, wtg.Type, wtg.IVSize, wtg.KeySize, wtg.TagSize) |
| 639 | 656 | ||
| 640 | var cipher *C.EVP_CIPHER | 657 | var cipher *C.EVP_CIPHER |
| 658 | var aead *C.EVP_AEAD | ||
| 641 | switch algorithm { | 659 | switch algorithm { |
| 642 | case "AES-CCM": | 660 | case "AES-CCM": |
| 643 | switch wtg.KeySize { | 661 | switch wtg.KeySize { |
| @@ -655,10 +673,12 @@ func runAesCcmOrGcmTestGroup(algorithm string, wtg *wycheproofTestGroupAead) boo | |||
| 655 | switch wtg.KeySize { | 673 | switch wtg.KeySize { |
| 656 | case 128: | 674 | case 128: |
| 657 | cipher = C.EVP_aes_128_gcm() | 675 | cipher = C.EVP_aes_128_gcm() |
| 676 | aead = C.EVP_aead_aes_128_gcm() | ||
| 658 | case 192: | 677 | case 192: |
| 659 | cipher = C.EVP_aes_192_gcm() | 678 | cipher = C.EVP_aes_192_gcm() |
| 660 | case 256: | 679 | case 256: |
| 661 | cipher = C.EVP_aes_256_gcm() | 680 | cipher = C.EVP_aes_256_gcm() |
| 681 | aead = C.EVP_aead_aes_256_gcm() | ||
| 662 | default: | 682 | default: |
| 663 | fmt.Printf("INFO: Skipping tests with invalid key size %d\n", wtg.KeySize) | 683 | fmt.Printf("INFO: Skipping tests with invalid key size %d\n", wtg.KeySize) |
| 664 | return true | 684 | return true |
| @@ -675,7 +695,7 @@ func runAesCcmOrGcmTestGroup(algorithm string, wtg *wycheproofTestGroupAead) boo | |||
| 675 | 695 | ||
| 676 | success := true | 696 | success := true |
| 677 | for _, wt := range wtg.Tests { | 697 | for _, wt := range wtg.Tests { |
| 678 | if !runAesCcmOrGcmTest(algorithm, ctx, wt) { | 698 | if !runAesCcmOrGcmTest(algorithm, ctx, aead, wt) { |
| 679 | success = false | 699 | success = false |
| 680 | } | 700 | } |
| 681 | } | 701 | } |
