diff options
| author | tb <> | 2018-10-06 11:05:00 +0000 |
|---|---|---|
| committer | tb <> | 2018-10-06 11:05:00 +0000 |
| commit | a6be303a5beb36cad1fdff5640004de8d97738b4 (patch) | |
| tree | 944a5225b15be4f1746bca33db0804a1bb255a56 /src | |
| parent | 0cab3da1fbee7506f4383008de217af42120903c (diff) | |
| download | openbsd-a6be303a5beb36cad1fdff5640004de8d97738b4.tar.gz openbsd-a6be303a5beb36cad1fdff5640004de8d97738b4.tar.bz2 openbsd-a6be303a5beb36cad1fdff5640004de8d97738b4.zip | |
wrap a few more overlong lines
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/wycheproof/wycheproof.go | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go index e151b190e9..1887a1b73c 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.77 2018/10/06 10:58:57 tb Exp $ */ | 1 | /* $OpenBSD: wycheproof.go,v 1.78 2018/10/06 11:05: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 Theo Buehler <tb@openbsd.org> | 4 | * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> |
| @@ -416,7 +416,9 @@ func hashEvpMdFromString(hs string) (*C.EVP_MD, error) { | |||
| 416 | } | 416 | } |
| 417 | } | 417 | } |
| 418 | 418 | ||
| 419 | func checkAesCbcPkcs5(ctx *C.EVP_CIPHER_CTX, doEncrypt int, key []byte, keyLen int, iv []byte, ivLen int, in []byte, inLen int, out []byte, outLen int, wt *wycheproofTestAesCbcPkcs5) bool { | 419 | func checkAesCbcPkcs5(ctx *C.EVP_CIPHER_CTX, doEncrypt int, key []byte, keyLen int, |
| 420 | iv []byte, ivLen int, in []byte, inLen int, out []byte, outLen int, | ||
| 421 | wt *wycheproofTestAesCbcPkcs5) bool { | ||
| 420 | var action string | 422 | var action string |
| 421 | if doEncrypt == 1 { | 423 | if doEncrypt == 1 { |
| 422 | action = "encrypting" | 424 | action = "encrypting" |
| @@ -424,7 +426,8 @@ func checkAesCbcPkcs5(ctx *C.EVP_CIPHER_CTX, doEncrypt int, key []byte, keyLen i | |||
| 424 | action = "decrypting" | 426 | action = "decrypting" |
| 425 | } | 427 | } |
| 426 | 428 | ||
| 427 | ret := C.EVP_CipherInit_ex(ctx, nil, nil, (*C.uchar)(unsafe.Pointer(&key[0])), (*C.uchar)(unsafe.Pointer(&iv[0])), C.int(doEncrypt)) | 429 | ret := C.EVP_CipherInit_ex(ctx, nil, nil, (*C.uchar)(unsafe.Pointer(&key[0])), |
| 430 | (*C.uchar)(unsafe.Pointer(&iv[0])), C.int(doEncrypt)) | ||
| 428 | if ret != 1 { | 431 | if ret != 1 { |
| 429 | log.Fatalf("EVP_CipherInit_ex failed: %d", ret) | 432 | log.Fatalf("EVP_CipherInit_ex failed: %d", ret) |
| 430 | } | 433 | } |
| @@ -432,7 +435,8 @@ func checkAesCbcPkcs5(ctx *C.EVP_CIPHER_CTX, doEncrypt int, key []byte, keyLen i | |||
| 432 | cipherOut := make([]byte, inLen + C.EVP_MAX_BLOCK_LENGTH) | 435 | cipherOut := make([]byte, inLen + C.EVP_MAX_BLOCK_LENGTH) |
| 433 | var cipherOutLen C.int | 436 | var cipherOutLen C.int |
| 434 | 437 | ||
| 435 | ret = C.EVP_CipherUpdate(ctx, (*C.uchar)(unsafe.Pointer(&cipherOut[0])), &cipherOutLen, (*C.uchar)(unsafe.Pointer(&in[0])), C.int(inLen)) | 438 | ret = C.EVP_CipherUpdate(ctx, (*C.uchar)(unsafe.Pointer(&cipherOut[0])), &cipherOutLen, |
| 439 | (*C.uchar)(unsafe.Pointer(&in[0])), C.int(inLen)) | ||
| 436 | if ret != 1 { | 440 | if ret != 1 { |
| 437 | if wt.Result == "invalid" { | 441 | if wt.Result == "invalid" { |
| 438 | fmt.Printf("INFO: Test case %d (%q) [%v] %v - EVP_CipherUpdate() = %d, want %v\n", | 442 | fmt.Printf("INFO: Test case %d (%q) [%v] %v - EVP_CipherUpdate() = %d, want %v\n", |
| @@ -555,7 +559,10 @@ func runAesCbcPkcs5TestGroup(algorithm string, wtg *wycheproofTestGroupAesCbcPkc | |||
| 555 | return success | 559 | return success |
| 556 | } | 560 | } |
| 557 | 561 | ||
| 558 | func checkAesAead(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 { | 562 | func checkAesAead(algorithm string, ctx *C.EVP_CIPHER_CTX, doEncrypt int, |
| 563 | key []byte, keyLen int, iv []byte, ivLen int, aad []byte, aadLen int, | ||
| 564 | in []byte, inLen int, out []byte, outLen int, tag []byte, tagLen int, | ||
| 565 | wt *wycheproofTestAead) bool { | ||
| 559 | var ctrlSetIVLen C.int | 566 | var ctrlSetIVLen C.int |
| 560 | var ctrlSetTag C.int | 567 | var ctrlSetTag C.int |
| 561 | var ctrlGetTag C.int | 568 | var ctrlGetTag C.int |
| @@ -590,7 +597,8 @@ func checkAesAead(algorithm string, ctx *C.EVP_CIPHER_CTX, doEncrypt int, key [] | |||
| 590 | 597 | ||
| 591 | ret = C.EVP_CIPHER_CTX_ctrl(ctx, ctrlSetIVLen, C.int(ivLen), nil) | 598 | ret = C.EVP_CIPHER_CTX_ctrl(ctx, ctrlSetIVLen, C.int(ivLen), nil) |
| 592 | if ret != 1 { | 599 | if ret != 1 { |
| 593 | if wt.Comment == "Nonce is too long" || wt.Comment == "Invalid nonce size" || wt.Comment == "0 size IV is not valid" { | 600 | if wt.Comment == "Nonce is too long" || wt.Comment == "Invalid nonce size" || |
| 601 | wt.Comment == "0 size IV is not valid" { | ||
| 594 | return true | 602 | return true |
| 595 | } | 603 | } |
| 596 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - setting IV len to %d failed. got %d, want %v\n", | 604 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - setting IV len to %d failed. got %d, want %v\n", |
| @@ -610,7 +618,8 @@ func checkAesAead(algorithm string, ctx *C.EVP_CIPHER_CTX, doEncrypt int, key [] | |||
| 610 | } | 618 | } |
| 611 | } | 619 | } |
| 612 | 620 | ||
| 613 | ret = C.EVP_CipherInit_ex(ctx, nil, nil, (*C.uchar)(unsafe.Pointer(&key[0])), (*C.uchar)(unsafe.Pointer(&iv[0])), C.int(doEncrypt)) | 621 | ret = C.EVP_CipherInit_ex(ctx, nil, nil, (*C.uchar)(unsafe.Pointer(&key[0])), |
| 622 | (*C.uchar)(unsafe.Pointer(&iv[0])), C.int(doEncrypt)) | ||
| 614 | if ret != 1 { | 623 | if ret != 1 { |
| 615 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - setting key and IV failed. got %d, want %v\n", | 624 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - setting key and IV failed. got %d, want %v\n", |
| 616 | wt.TCID, wt.Comment, action, wt.Flags, ret, wt.Result) | 625 | wt.TCID, wt.Comment, action, wt.Flags, ret, wt.Result) |
| @@ -640,7 +649,8 @@ func checkAesAead(algorithm string, ctx *C.EVP_CIPHER_CTX, doEncrypt int, key [] | |||
| 640 | cipherOut = append(cipherOut, 0) | 649 | cipherOut = append(cipherOut, 0) |
| 641 | } | 650 | } |
| 642 | 651 | ||
| 643 | ret = C.EVP_CipherUpdate(ctx, (*C.uchar)(unsafe.Pointer(&cipherOut[0])), &cipherOutLen, (*C.uchar)(unsafe.Pointer(&in[0])), C.int(inLen)) | 652 | ret = C.EVP_CipherUpdate(ctx, (*C.uchar)(unsafe.Pointer(&cipherOut[0])), &cipherOutLen, |
| 653 | (*C.uchar)(unsafe.Pointer(&in[0])), C.int(inLen)) | ||
| 644 | if ret != 1 { | 654 | if ret != 1 { |
| 645 | if wt.Result == "invalid" { | 655 | if wt.Result == "invalid" { |
| 646 | return true | 656 | return true |
| @@ -926,14 +936,19 @@ func runAesCmacTestGroup(algorithm string, wtg *wycheproofTestGroupAesCmac) bool | |||
| 926 | return success | 936 | return success |
| 927 | } | 937 | } |
| 928 | 938 | ||
| 929 | func checkAeadOpen(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 { | 939 | func checkAeadOpen(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen int, msg []byte, msgLen int, |
| 940 | ct []byte, ctLen int, tag []byte, tagLen int, wt *wycheproofTestAead) bool { | ||
| 930 | maxOutLen := ctLen + tagLen | 941 | maxOutLen := ctLen + tagLen |
| 931 | 942 | ||
| 932 | opened := make([]byte, maxOutLen) | 943 | opened := make([]byte, maxOutLen) |
| 933 | var openedMsgLen C.size_t | 944 | var openedMsgLen C.size_t |
| 934 | 945 | ||
| 935 | catCtTag := append(ct, tag...) | 946 | catCtTag := append(ct, tag...) |
| 936 | openRet := C.EVP_AEAD_CTX_open(ctx, (*C.uint8_t)(unsafe.Pointer(&opened[0])), (*C.size_t)(unsafe.Pointer(&openedMsgLen)), C.size_t(maxOutLen), (*C.uint8_t)(unsafe.Pointer(&iv[0])), C.size_t(ivLen), (*C.uint8_t)(unsafe.Pointer(&catCtTag[0])), C.size_t(len(catCtTag)), (*C.uint8_t)(unsafe.Pointer(&aad[0])), C.size_t(aadLen)) | 947 | openRet := C.EVP_AEAD_CTX_open(ctx, (*C.uint8_t)(unsafe.Pointer(&opened[0])), |
| 948 | (*C.size_t)(unsafe.Pointer(&openedMsgLen)), C.size_t(maxOutLen), | ||
| 949 | (*C.uint8_t)(unsafe.Pointer(&iv[0])), C.size_t(ivLen), | ||
| 950 | (*C.uint8_t)(unsafe.Pointer(&catCtTag[0])), C.size_t(len(catCtTag)), | ||
| 951 | (*C.uint8_t)(unsafe.Pointer(&aad[0])), C.size_t(aadLen)) | ||
| 937 | 952 | ||
| 938 | if openRet != 1 { | 953 | if openRet != 1 { |
| 939 | if wt.Result == "invalid" { | 954 | if wt.Result == "invalid" { |
| @@ -968,13 +983,18 @@ func checkAeadOpen(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen | |||
| 968 | return success | 983 | return success |
| 969 | } | 984 | } |
| 970 | 985 | ||
| 971 | func checkAeadSeal(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 { | 986 | func checkAeadSeal(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen int, msg []byte, |
| 987 | msgLen int, ct []byte, ctLen int, tag []byte, tagLen int, wt *wycheproofTestAead) bool { | ||
| 972 | maxOutLen := msgLen + tagLen | 988 | maxOutLen := msgLen + tagLen |
| 973 | 989 | ||
| 974 | sealed := make([]byte, maxOutLen) | 990 | sealed := make([]byte, maxOutLen) |
| 975 | var sealedLen C.size_t | 991 | var sealedLen C.size_t |
| 976 | 992 | ||
| 977 | sealRet := C.EVP_AEAD_CTX_seal(ctx, (*C.uint8_t)(unsafe.Pointer(&sealed[0])), (*C.size_t)(unsafe.Pointer(&sealedLen)), C.size_t(maxOutLen), (*C.uint8_t)(unsafe.Pointer(&iv[0])), C.size_t(ivLen), (*C.uint8_t)(unsafe.Pointer(&msg[0])), C.size_t(msgLen), (*C.uint8_t)(unsafe.Pointer(&aad[0])), C.size_t(aadLen)) | 993 | sealRet := C.EVP_AEAD_CTX_seal(ctx, (*C.uint8_t)(unsafe.Pointer(&sealed[0])), |
| 994 | (*C.size_t)(unsafe.Pointer(&sealedLen)), C.size_t(maxOutLen), | ||
| 995 | (*C.uint8_t)(unsafe.Pointer(&iv[0])), C.size_t(ivLen), | ||
| 996 | (*C.uint8_t)(unsafe.Pointer(&msg[0])), C.size_t(msgLen), | ||
| 997 | (*C.uint8_t)(unsafe.Pointer(&aad[0])), C.size_t(aadLen)) | ||
| 978 | 998 | ||
| 979 | if sealRet != 1 { | 999 | if sealRet != 1 { |
| 980 | fmt.Printf("FAIL: Test case %d (%q) %v - EVP_AEAD_CTX_seal() = %d, want %v\n", | 1000 | fmt.Printf("FAIL: Test case %d (%q) %v - EVP_AEAD_CTX_seal() = %d, want %v\n", |
| @@ -1681,7 +1701,8 @@ func runRSASSATest(rsa *C.RSA, h hash.Hash, sha *C.EVP_MD, mgfSha *C.EVP_MD, sLe | |||
| 1681 | sigOut = append(sigOut, 0) | 1701 | sigOut = append(sigOut, 0) |
| 1682 | } | 1702 | } |
| 1683 | 1703 | ||
| 1684 | ret := C.RSA_public_decrypt(C.int(sigLen), (*C.uchar)(unsafe.Pointer(&sig[0])), (*C.uchar)(unsafe.Pointer(&sigOut[0])), rsa, C.RSA_NO_PADDING) | 1704 | ret := C.RSA_public_decrypt(C.int(sigLen), (*C.uchar)(unsafe.Pointer(&sig[0])), |
| 1705 | (*C.uchar)(unsafe.Pointer(&sigOut[0])), rsa, C.RSA_NO_PADDING) | ||
| 1685 | if ret == -1 { | 1706 | if ret == -1 { |
| 1686 | if wt.Result == "invalid" { | 1707 | if wt.Result == "invalid" { |
| 1687 | return true | 1708 | return true |
| @@ -1691,7 +1712,8 @@ func runRSASSATest(rsa *C.RSA, h hash.Hash, sha *C.EVP_MD, mgfSha *C.EVP_MD, sLe | |||
| 1691 | return false | 1712 | return false |
| 1692 | } | 1713 | } |
| 1693 | 1714 | ||
| 1694 | ret = C.RSA_verify_PKCS1_PSS_mgf1(rsa, (*C.uchar)(unsafe.Pointer(&msg[0])), sha, mgfSha, (*C.uchar)(unsafe.Pointer(&sigOut[0])), C.int(sLen)) | 1715 | ret = C.RSA_verify_PKCS1_PSS_mgf1(rsa, (*C.uchar)(unsafe.Pointer(&msg[0])), sha, mgfSha, |
| 1716 | (*C.uchar)(unsafe.Pointer(&sigOut[0])), C.int(sLen)) | ||
| 1695 | 1717 | ||
| 1696 | success := false | 1718 | success := false |
| 1697 | if ret == 1 && (wt.Result == "valid" || wt.Result == "acceptable") { | 1719 | if ret == 1 && (wt.Result == "valid" || wt.Result == "acceptable") { |
