diff options
| author | tb <> | 2018-09-15 19:06:47 +0000 |
|---|---|---|
| committer | tb <> | 2018-09-15 19:06:47 +0000 |
| commit | 237c42869fa63acc2b13ff7d4c25c00b297dc71f (patch) | |
| tree | ad068ec12f24554a085b826a8cb6e92d2f366f24 /src | |
| parent | ced7261c41eab36b593cbe297c70adbea362d817 (diff) | |
| download | openbsd-237c42869fa63acc2b13ff7d4c25c00b297dc71f.tar.gz openbsd-237c42869fa63acc2b13ff7d4c25c00b297dc71f.tar.bz2 openbsd-237c42869fa63acc2b13ff7d4c25c00b297dc71f.zip | |
Merge AES CCM, AES GCM and ChaCha20 data structures into
single AEAD types. Will be used in upcoming commits.
Diffstat (limited to '')
| -rw-r--r-- | src/regress/lib/libcrypto/wycheproof/wycheproof.go | 63 |
1 files changed, 21 insertions, 42 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go index 55c10c6634..dfbc721076 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.47 2018/09/15 16:05:17 tb Exp $ */ | 1 | /* $OpenBSD: wycheproof.go,v 1.48 2018/09/15 19:06:47 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> |
| @@ -75,15 +75,15 @@ type wycheproofTestAesCbcPkcs5 struct { | |||
| 75 | Flags []string `json:"flags"` | 75 | Flags []string `json:"flags"` |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | type wycheproofTestGroupAesCcmOrGcm struct { | 78 | type wycheproofTestGroupAead struct { |
| 79 | IVSize int `json:"ivSize"` | 79 | IVSize int `json:"ivSize"` |
| 80 | KeySize int `json:"keySize"` | 80 | KeySize int `json:"keySize"` |
| 81 | TagSize int `json:"tagSize"` | 81 | TagSize int `json:"tagSize"` |
| 82 | Type string `json:"type"` | 82 | Type string `json:"type"` |
| 83 | Tests []*wycheproofTestAesCcmOrGcm `json:"tests"` | 83 | Tests []*wycheproofTestAead `json:"tests"` |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | type wycheproofTestAesCcmOrGcm struct { | 86 | type wycheproofTestAead struct { |
| 87 | TCID int `json:"tcId"` | 87 | TCID int `json:"tcId"` |
| 88 | Comment string `json:"comment"` | 88 | Comment string `json:"comment"` |
| 89 | Key string `json:"key"` | 89 | Key string `json:"key"` |
| @@ -113,27 +113,6 @@ type wycheproofTestAesCmac struct { | |||
| 113 | Flags []string `json:"flags"` | 113 | Flags []string `json:"flags"` |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | type wycheproofTestGroupChaCha20Poly1305 struct { | ||
| 117 | IVSize int `json:"ivSize"` | ||
| 118 | KeySize int `json:"keySize"` | ||
| 119 | TagSize int `json:"tagSize"` | ||
| 120 | Type string `json:"type"` | ||
| 121 | Tests []*wycheproofTestChaCha20Poly1305 `json:"tests"` | ||
| 122 | } | ||
| 123 | |||
| 124 | type wycheproofTestChaCha20Poly1305 struct { | ||
| 125 | TCID int `json:"tcId"` | ||
| 126 | Comment string `json:"comment"` | ||
| 127 | Key string `json:"key"` | ||
| 128 | IV string `json:"iv"` | ||
| 129 | AAD string `json:"aad"` | ||
| 130 | Msg string `json:"msg"` | ||
| 131 | CT string `json:"ct"` | ||
| 132 | Tag string `json:"tag"` | ||
| 133 | Result string `json:"result"` | ||
| 134 | Flags []string `json:"flags"` | ||
| 135 | } | ||
| 136 | |||
| 137 | type wycheproofDSAKey struct { | 116 | type wycheproofDSAKey struct { |
| 138 | G string `json:"g"` | 117 | G string `json:"g"` |
| 139 | KeySize int `json:"keySize"` | 118 | KeySize int `json:"keySize"` |
| @@ -470,7 +449,7 @@ func runAesCbcPkcs5TestGroup(algorithm string, wtg *wycheproofTestGroupAesCbcPkc | |||
| 470 | return success | 449 | return success |
| 471 | } | 450 | } |
| 472 | 451 | ||
| 473 | func checkAesCcmOrGcm(algorithm string, ctx *C.EVP_CIPHER_CTX, doEncrypt int, key []byte, keyLen int, iv []byte, ivLen int, aad []byte, aadLen int, in []byte, inLen int, out []byte, outLen int, tag []byte, tagLen int, wt *wycheproofTestAesCcmOrGcm) bool { | 452 | func checkAesCcmOrGcm(algorithm string, ctx *C.EVP_CIPHER_CTX, doEncrypt int, key []byte, keyLen int, iv []byte, ivLen int, aad []byte, aadLen int, in []byte, inLen int, out []byte, outLen int, tag []byte, tagLen int, wt *wycheproofTestAead) bool { |
| 474 | var ctrlSetIVLen C.int | 453 | var ctrlSetIVLen C.int |
| 475 | var ctrlSetTag C.int | 454 | var ctrlSetTag C.int |
| 476 | var ctrlGetTag C.int | 455 | var ctrlGetTag C.int |
| @@ -597,7 +576,7 @@ func checkAesCcmOrGcm(algorithm string, ctx *C.EVP_CIPHER_CTX, doEncrypt int, ke | |||
| 597 | return success | 576 | return success |
| 598 | } | 577 | } |
| 599 | 578 | ||
| 600 | func runAesCcmOrGcmTest(algorithm string, ctx *C.EVP_CIPHER_CTX, wt *wycheproofTestAesCcmOrGcm) bool { | 579 | func runAesCcmOrGcmTest(algorithm string, ctx *C.EVP_CIPHER_CTX, wt *wycheproofTestAead) bool { |
| 601 | key, err := hex.DecodeString(wt.Key) | 580 | key, err := hex.DecodeString(wt.Key) |
| 602 | if err != nil { | 581 | if err != nil { |
| 603 | log.Fatalf("Failed to decode key %q: %v", wt.Key, err) | 582 | log.Fatalf("Failed to decode key %q: %v", wt.Key, err) |
| @@ -655,7 +634,7 @@ func runAesCcmOrGcmTest(algorithm string, ctx *C.EVP_CIPHER_CTX, wt *wycheproofT | |||
| 655 | return openSuccess && sealSuccess | 634 | return openSuccess && sealSuccess |
| 656 | } | 635 | } |
| 657 | 636 | ||
| 658 | func runAesCcmOrGcmTestGroup(algorithm string, wtg *wycheproofTestGroupAesCcmOrGcm) bool { | 637 | func runAesCcmOrGcmTestGroup(algorithm string, wtg *wycheproofTestGroupAead) bool { |
| 659 | 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) | 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) |
| 660 | 639 | ||
| 661 | var cipher *C.EVP_CIPHER | 640 | var cipher *C.EVP_CIPHER |
| @@ -793,7 +772,7 @@ func runAesCmacTestGroup(algorithm string, wtg *wycheproofTestGroupAesCmac) bool | |||
| 793 | return success | 772 | return success |
| 794 | } | 773 | } |
| 795 | 774 | ||
| 796 | func checkChaCha20Poly1305Open(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen int, msg []byte, msgLen int, ct []byte, ctLen int, tag []byte, tagLen int, wt *wycheproofTestChaCha20Poly1305) bool { | 775 | func checkChaCha20Poly1305Open(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen int, msg []byte, msgLen int, ct []byte, ctLen int, tag []byte, tagLen int, wt *wycheproofTestAead) bool { |
| 797 | maxOutLen := ctLen + tagLen | 776 | maxOutLen := ctLen + tagLen |
| 798 | 777 | ||
| 799 | opened := make([]byte, maxOutLen) | 778 | opened := make([]byte, maxOutLen) |
| @@ -829,7 +808,7 @@ func checkChaCha20Poly1305Open(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad [] | |||
| 829 | return success | 808 | return success |
| 830 | } | 809 | } |
| 831 | 810 | ||
| 832 | func checkChaCha20Poly1305Seal(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen int, msg []byte, msgLen int, ct []byte, ctLen int, tag []byte, tagLen int, wt *wycheproofTestChaCha20Poly1305) bool { | 811 | func checkChaCha20Poly1305Seal(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen int, msg []byte, msgLen int, ct []byte, ctLen int, tag []byte, tagLen int, wt *wycheproofTestAead) bool { |
| 833 | maxOutLen := msgLen + tagLen | 812 | maxOutLen := msgLen + tagLen |
| 834 | 813 | ||
| 835 | sealed := make([]byte, maxOutLen) | 814 | sealed := make([]byte, maxOutLen) |
| @@ -859,7 +838,7 @@ func checkChaCha20Poly1305Seal(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad [] | |||
| 859 | return success | 838 | return success |
| 860 | } | 839 | } |
| 861 | 840 | ||
| 862 | func runChaCha20Poly1305Test(iv_len int, key_len int, tag_len int, wt *wycheproofTestChaCha20Poly1305) bool { | 841 | func runChaCha20Poly1305Test(iv_len int, key_len int, tag_len int, wt *wycheproofTestAead) bool { |
| 863 | aead := C.EVP_aead_chacha20_poly1305() | 842 | aead := C.EVP_aead_chacha20_poly1305() |
| 864 | if aead == nil { | 843 | if aead == nil { |
| 865 | log.Fatal("EVP_aead_chacha20_poly1305 failed") | 844 | log.Fatal("EVP_aead_chacha20_poly1305 failed") |
| @@ -924,7 +903,7 @@ func runChaCha20Poly1305Test(iv_len int, key_len int, tag_len int, wt *wycheproo | |||
| 924 | return openSuccess && sealSuccess | 903 | return openSuccess && sealSuccess |
| 925 | } | 904 | } |
| 926 | 905 | ||
| 927 | func runChaCha20Poly1305TestGroup(algorithm string, wtg *wycheproofTestGroupChaCha20Poly1305) bool { | 906 | func runChaCha20Poly1305TestGroup(algorithm string, wtg *wycheproofTestGroupAead) bool { |
| 928 | // We currently only support nonces of length 12 (96 bits) | 907 | // We currently only support nonces of length 12 (96 bits) |
| 929 | if wtg.IVSize != 96 { | 908 | if wtg.IVSize != 96 { |
| 930 | return true | 909 | return true |
| @@ -1513,13 +1492,13 @@ func runTestVectors(path string) bool { | |||
| 1513 | case "AES-CBC-PKCS5": | 1492 | case "AES-CBC-PKCS5": |
| 1514 | wtg = &wycheproofTestGroupAesCbcPkcs5{} | 1493 | wtg = &wycheproofTestGroupAesCbcPkcs5{} |
| 1515 | case "AES-CCM": | 1494 | case "AES-CCM": |
| 1516 | wtg = &wycheproofTestGroupAesCcmOrGcm{} | 1495 | wtg = &wycheproofTestGroupAead{} |
| 1517 | case "AES-CMAC": | 1496 | case "AES-CMAC": |
| 1518 | wtg = &wycheproofTestGroupAesCmac{} | 1497 | wtg = &wycheproofTestGroupAesCmac{} |
| 1519 | case "AES-GCM": | 1498 | case "AES-GCM": |
| 1520 | wtg = &wycheproofTestGroupAesCcmOrGcm{} | 1499 | wtg = &wycheproofTestGroupAead{} |
| 1521 | case "CHACHA20-POLY1305": | 1500 | case "CHACHA20-POLY1305": |
| 1522 | wtg = &wycheproofTestGroupChaCha20Poly1305{} | 1501 | wtg = &wycheproofTestGroupAead{} |
| 1523 | case "DSA": | 1502 | case "DSA": |
| 1524 | wtg = &wycheproofTestGroupDSA{} | 1503 | wtg = &wycheproofTestGroupDSA{} |
| 1525 | case "ECDH": | 1504 | case "ECDH": |
| @@ -1547,7 +1526,7 @@ func runTestVectors(path string) bool { | |||
| 1547 | success = false | 1526 | success = false |
| 1548 | } | 1527 | } |
| 1549 | case "AES-CCM": | 1528 | case "AES-CCM": |
| 1550 | if !runAesCcmOrGcmTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupAesCcmOrGcm)) { | 1529 | if !runAesCcmOrGcmTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupAead)) { |
| 1551 | success = false | 1530 | success = false |
| 1552 | } | 1531 | } |
| 1553 | case "AES-CMAC": | 1532 | case "AES-CMAC": |
| @@ -1555,11 +1534,11 @@ func runTestVectors(path string) bool { | |||
| 1555 | success = false | 1534 | success = false |
| 1556 | } | 1535 | } |
| 1557 | case "AES-GCM": | 1536 | case "AES-GCM": |
| 1558 | if !runAesCcmOrGcmTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupAesCcmOrGcm)) { | 1537 | if !runAesCcmOrGcmTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupAead)) { |
| 1559 | success = false | 1538 | success = false |
| 1560 | } | 1539 | } |
| 1561 | case "CHACHA20-POLY1305": | 1540 | case "CHACHA20-POLY1305": |
| 1562 | if !runChaCha20Poly1305TestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupChaCha20Poly1305)) { | 1541 | if !runChaCha20Poly1305TestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupAead)) { |
| 1563 | success = false | 1542 | success = false |
| 1564 | } | 1543 | } |
| 1565 | case "DSA": | 1544 | case "DSA": |
