diff options
-rw-r--r-- | src/regress/lib/libcrypto/wycheproof/wycheproof.go | 104 |
1 files changed, 32 insertions, 72 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go index dea2f2e5f8..286bbe5965 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.155 2023/11/07 16:46:12 tb Exp $ */ | 1 | /* $OpenBSD: wycheproof.go,v 1.156 2023/11/07 16:54:43 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,2022 Theo Buehler <tb@openbsd.org> | 4 | * Copyright (c) 2018,2019,2022 Theo Buehler <tb@openbsd.org> |
@@ -738,9 +738,7 @@ func mustDecodeHexString(str, descr string) (out []byte, outLen int) { | |||
738 | return out, outLen | 738 | return out, outLen |
739 | } | 739 | } |
740 | 740 | ||
741 | func checkAesCbcPkcs5(ctx *C.EVP_CIPHER_CTX, doEncrypt int, key []byte, keyLen int, | 741 | 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 { |
742 | iv []byte, ivLen int, in []byte, inLen int, out []byte, outLen int, | ||
743 | wt *wycheproofTestAesCbcPkcs5) bool { | ||
744 | var action string | 742 | var action string |
745 | if doEncrypt == 1 { | 743 | if doEncrypt == 1 { |
746 | action = "encrypting" | 744 | action = "encrypting" |
@@ -748,8 +746,7 @@ func checkAesCbcPkcs5(ctx *C.EVP_CIPHER_CTX, doEncrypt int, key []byte, keyLen i | |||
748 | action = "decrypting" | 746 | action = "decrypting" |
749 | } | 747 | } |
750 | 748 | ||
751 | ret := C.EVP_CipherInit_ex(ctx, nil, nil, (*C.uchar)(unsafe.Pointer(&key[0])), | 749 | ret := C.EVP_CipherInit_ex(ctx, nil, nil, (*C.uchar)(unsafe.Pointer(&key[0])), (*C.uchar)(unsafe.Pointer(&iv[0])), C.int(doEncrypt)) |
752 | (*C.uchar)(unsafe.Pointer(&iv[0])), C.int(doEncrypt)) | ||
753 | if ret != 1 { | 750 | if ret != 1 { |
754 | log.Fatalf("EVP_CipherInit_ex failed: %d", ret) | 751 | log.Fatalf("EVP_CipherInit_ex failed: %d", ret) |
755 | } | 752 | } |
@@ -757,8 +754,7 @@ func checkAesCbcPkcs5(ctx *C.EVP_CIPHER_CTX, doEncrypt int, key []byte, keyLen i | |||
757 | cipherOut := make([]byte, inLen+C.EVP_MAX_BLOCK_LENGTH) | 754 | cipherOut := make([]byte, inLen+C.EVP_MAX_BLOCK_LENGTH) |
758 | var cipherOutLen C.int | 755 | var cipherOutLen C.int |
759 | 756 | ||
760 | ret = C.EVP_CipherUpdate(ctx, (*C.uchar)(unsafe.Pointer(&cipherOut[0])), &cipherOutLen, | 757 | ret = C.EVP_CipherUpdate(ctx, (*C.uchar)(unsafe.Pointer(&cipherOut[0])), &cipherOutLen, (*C.uchar)(unsafe.Pointer(&in[0])), C.int(inLen)) |
761 | (*C.uchar)(unsafe.Pointer(&in[0])), C.int(inLen)) | ||
762 | if ret != 1 { | 758 | if ret != 1 { |
763 | if wt.Result == "invalid" { | 759 | if wt.Result == "invalid" { |
764 | fmt.Printf("INFO: %s [%v] - EVP_CipherUpdate() = %d\n", wt, action, ret) | 760 | fmt.Printf("INFO: %s [%v] - EVP_CipherUpdate() = %d\n", wt, action, ret) |
@@ -811,8 +807,7 @@ func runAesCbcPkcs5Test(ctx *C.EVP_CIPHER_CTX, wt *wycheproofTestAesCbcPkcs5) bo | |||
811 | } | 807 | } |
812 | 808 | ||
813 | func (wtg *wycheproofTestGroupAesCbcPkcs5) run(algorithm string, variant testVariant) bool { | 809 | func (wtg *wycheproofTestGroupAesCbcPkcs5) run(algorithm string, variant testVariant) bool { |
814 | fmt.Printf("Running %v test group %v with IV size %d and key size %d...\n", | 810 | fmt.Printf("Running %v test group %v with IV size %d and key size %d...\n", algorithm, wtg.Type, wtg.IVSize, wtg.KeySize) |
815 | algorithm, wtg.Type, wtg.IVSize, wtg.KeySize) | ||
816 | 811 | ||
817 | cipher, err := cipherAes("AES-CBC", wtg.KeySize) | 812 | cipher, err := cipherAes("AES-CBC", wtg.KeySize) |
818 | if err != nil { | 813 | if err != nil { |
@@ -839,10 +834,7 @@ func (wtg *wycheproofTestGroupAesCbcPkcs5) run(algorithm string, variant testVar | |||
839 | return success | 834 | return success |
840 | } | 835 | } |
841 | 836 | ||
842 | func checkAesAead(algorithm string, ctx *C.EVP_CIPHER_CTX, doEncrypt int, | 837 | 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 { |
843 | key []byte, keyLen int, iv []byte, ivLen int, aad []byte, aadLen int, | ||
844 | in []byte, inLen int, out []byte, outLen int, tag []byte, tagLen int, | ||
845 | wt *wycheproofTestAead) bool { | ||
846 | var ctrlSetIVLen C.int | 838 | var ctrlSetIVLen C.int |
847 | var ctrlSetTag C.int | 839 | var ctrlSetTag C.int |
848 | var ctrlGetTag C.int | 840 | var ctrlGetTag C.int |
@@ -896,8 +888,7 @@ func checkAesAead(algorithm string, ctx *C.EVP_CIPHER_CTX, doEncrypt int, | |||
896 | } | 888 | } |
897 | } | 889 | } |
898 | 890 | ||
899 | ret = C.EVP_CipherInit_ex(ctx, nil, nil, (*C.uchar)(unsafe.Pointer(&key[0])), | 891 | ret = C.EVP_CipherInit_ex(ctx, nil, nil, (*C.uchar)(unsafe.Pointer(&key[0])), (*C.uchar)(unsafe.Pointer(&iv[0])), C.int(doEncrypt)) |
900 | (*C.uchar)(unsafe.Pointer(&iv[0])), C.int(doEncrypt)) | ||
901 | if ret != 1 { | 892 | if ret != 1 { |
902 | fmt.Printf("FAIL: %s [%v] - setting key and IV failed: %d.\n", wt, action, ret) | 893 | fmt.Printf("FAIL: %s [%v] - setting key and IV failed: %d.\n", wt, action, ret) |
903 | return false | 894 | return false |
@@ -924,8 +915,7 @@ func checkAesAead(algorithm string, ctx *C.EVP_CIPHER_CTX, doEncrypt int, | |||
924 | cipherOut = append(cipherOut, 0) | 915 | cipherOut = append(cipherOut, 0) |
925 | } | 916 | } |
926 | 917 | ||
927 | ret = C.EVP_CipherUpdate(ctx, (*C.uchar)(unsafe.Pointer(&cipherOut[0])), &cipherOutLen, | 918 | ret = C.EVP_CipherUpdate(ctx, (*C.uchar)(unsafe.Pointer(&cipherOut[0])), &cipherOutLen, (*C.uchar)(unsafe.Pointer(&in[0])), C.int(inLen)) |
928 | (*C.uchar)(unsafe.Pointer(&in[0])), C.int(inLen)) | ||
929 | if ret != 1 { | 919 | if ret != 1 { |
930 | if wt.Result == "invalid" { | 920 | if wt.Result == "invalid" { |
931 | return true | 921 | return true |
@@ -1014,8 +1004,7 @@ func runAesAeadTest(algorithm string, ctx *C.EVP_CIPHER_CTX, aead *C.EVP_AEAD, w | |||
1014 | } | 1004 | } |
1015 | 1005 | ||
1016 | func (wtg *wycheproofTestGroupAesAead) run(algorithm string, variant testVariant) bool { | 1006 | func (wtg *wycheproofTestGroupAesAead) run(algorithm string, variant testVariant) bool { |
1017 | fmt.Printf("Running %v test group %v with IV size %d, key size %d and tag size %d...\n", | 1007 | 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) |
1018 | algorithm, wtg.Type, wtg.IVSize, wtg.KeySize, wtg.TagSize) | ||
1019 | 1008 | ||
1020 | cipher, err := cipherAes(algorithm, wtg.KeySize) | 1009 | cipher, err := cipherAes(algorithm, wtg.KeySize) |
1021 | if err != nil { | 1010 | if err != nil { |
@@ -1090,8 +1079,7 @@ func runAesCmacTest(cipher *C.EVP_CIPHER, wt *wycheproofTestAesCmac) bool { | |||
1090 | } | 1079 | } |
1091 | 1080 | ||
1092 | func (wtg *wycheproofTestGroupAesCmac) run(algorithm string, variant testVariant) bool { | 1081 | func (wtg *wycheproofTestGroupAesCmac) run(algorithm string, variant testVariant) bool { |
1093 | fmt.Printf("Running %v test group %v with key size %d and tag size %d...\n", | 1082 | fmt.Printf("Running %v test group %v with key size %d and tag size %d...\n", algorithm, wtg.Type, wtg.KeySize, wtg.TagSize) |
1094 | algorithm, wtg.Type, wtg.KeySize, wtg.TagSize) | ||
1095 | 1083 | ||
1096 | cipher, err := cipherAes("AES-CBC", wtg.KeySize) | 1084 | cipher, err := cipherAes("AES-CBC", wtg.KeySize) |
1097 | if err != nil { | 1085 | if err != nil { |
@@ -1108,8 +1096,7 @@ func (wtg *wycheproofTestGroupAesCmac) run(algorithm string, variant testVariant | |||
1108 | return success | 1096 | return success |
1109 | } | 1097 | } |
1110 | 1098 | ||
1111 | func checkAeadOpen(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen int, msg []byte, msgLen int, | 1099 | 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 { |
1112 | ct []byte, ctLen int, tag []byte, tagLen int, wt *wycheproofTestAead) bool { | ||
1113 | maxOutLen := ctLen + tagLen | 1100 | maxOutLen := ctLen + tagLen |
1114 | 1101 | ||
1115 | opened := make([]byte, maxOutLen) | 1102 | opened := make([]byte, maxOutLen) |
@@ -1123,11 +1110,7 @@ func checkAeadOpen(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen | |||
1123 | if catCtTagLen == 0 { | 1110 | if catCtTagLen == 0 { |
1124 | catCtTag = append(catCtTag, 0) | 1111 | catCtTag = append(catCtTag, 0) |
1125 | } | 1112 | } |
1126 | openRet := C.EVP_AEAD_CTX_open(ctx, (*C.uint8_t)(unsafe.Pointer(&opened[0])), | 1113 | 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(catCtTagLen), (*C.uint8_t)(unsafe.Pointer(&aad[0])), C.size_t(aadLen)) |
1127 | (*C.size_t)(unsafe.Pointer(&openedMsgLen)), C.size_t(maxOutLen), | ||
1128 | (*C.uint8_t)(unsafe.Pointer(&iv[0])), C.size_t(ivLen), | ||
1129 | (*C.uint8_t)(unsafe.Pointer(&catCtTag[0])), C.size_t(catCtTagLen), | ||
1130 | (*C.uint8_t)(unsafe.Pointer(&aad[0])), C.size_t(aadLen)) | ||
1131 | 1114 | ||
1132 | if openRet != 1 { | 1115 | if openRet != 1 { |
1133 | if wt.Result == "invalid" { | 1116 | if wt.Result == "invalid" { |
@@ -1156,8 +1139,7 @@ func checkAeadOpen(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen | |||
1156 | return success | 1139 | return success |
1157 | } | 1140 | } |
1158 | 1141 | ||
1159 | func checkAeadSeal(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen int, msg []byte, | 1142 | 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 { |
1160 | msgLen int, ct []byte, ctLen int, tag []byte, tagLen int, wt *wycheproofTestAead) bool { | ||
1161 | maxOutLen := msgLen + tagLen | 1143 | maxOutLen := msgLen + tagLen |
1162 | 1144 | ||
1163 | sealed := make([]byte, maxOutLen) | 1145 | sealed := make([]byte, maxOutLen) |
@@ -1166,11 +1148,7 @@ func checkAeadSeal(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen | |||
1166 | } | 1148 | } |
1167 | var sealedLen C.size_t | 1149 | var sealedLen C.size_t |
1168 | 1150 | ||
1169 | sealRet := C.EVP_AEAD_CTX_seal(ctx, (*C.uint8_t)(unsafe.Pointer(&sealed[0])), | 1151 | 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)) |
1170 | (*C.size_t)(unsafe.Pointer(&sealedLen)), C.size_t(maxOutLen), | ||
1171 | (*C.uint8_t)(unsafe.Pointer(&iv[0])), C.size_t(ivLen), | ||
1172 | (*C.uint8_t)(unsafe.Pointer(&msg[0])), C.size_t(msgLen), | ||
1173 | (*C.uint8_t)(unsafe.Pointer(&aad[0])), C.size_t(aadLen)) | ||
1174 | 1152 | ||
1175 | if sealRet != 1 { | 1153 | if sealRet != 1 { |
1176 | success := (wt.Result == "invalid") | 1154 | success := (wt.Result == "invalid") |
@@ -1244,8 +1222,7 @@ func (wtg *wycheproofTestGroupChaCha) run(algorithm string, variant testVariant) | |||
1244 | return true | 1222 | return true |
1245 | } | 1223 | } |
1246 | 1224 | ||
1247 | fmt.Printf("Running %v test group %v with IV size %d, key size %d, tag size %d...\n", | 1225 | fmt.Printf("Running %v test group %v with IV size %d, key size %d, tag size %d...\n", algorithm, wtg.Type, wtg.IVSize, wtg.KeySize, wtg.TagSize) |
1248 | algorithm, wtg.Type, wtg.IVSize, wtg.KeySize, wtg.TagSize) | ||
1249 | 1226 | ||
1250 | success := true | 1227 | success := true |
1251 | for _, wt := range wtg.Tests { | 1228 | for _, wt := range wtg.Tests { |
@@ -1316,12 +1293,10 @@ func runDSATest(dsa *C.DSA, md *C.EVP_MD, variant testVariant, wt *wycheproofTes | |||
1316 | } | 1293 | } |
1317 | defer C.free(unsafe.Pointer(cDer)) | 1294 | defer C.free(unsafe.Pointer(cDer)) |
1318 | 1295 | ||
1319 | ret = C.DSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen), | 1296 | ret = C.DSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen), (*C.uchar)(unsafe.Pointer(cDer)), C.int(derLen), dsa) |
1320 | (*C.uchar)(unsafe.Pointer(cDer)), C.int(derLen), dsa) | ||
1321 | } else { | 1297 | } else { |
1322 | sig, sigLen := mustDecodeHexString(wt.Sig, "sig") | 1298 | sig, sigLen := mustDecodeHexString(wt.Sig, "sig") |
1323 | ret = C.DSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen), | 1299 | ret = C.DSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen), (*C.uchar)(unsafe.Pointer(&sig[0])), C.int(sigLen), dsa) |
1324 | (*C.uchar)(unsafe.Pointer(&sig[0])), C.int(sigLen), dsa) | ||
1325 | } | 1300 | } |
1326 | 1301 | ||
1327 | success := true | 1302 | success := true |
@@ -1333,8 +1308,7 @@ func runDSATest(dsa *C.DSA, md *C.EVP_MD, variant testVariant, wt *wycheproofTes | |||
1333 | } | 1308 | } |
1334 | 1309 | ||
1335 | func (wtg *wycheproofTestGroupDSA) run(algorithm string, variant testVariant) bool { | 1310 | func (wtg *wycheproofTestGroupDSA) run(algorithm string, variant testVariant) bool { |
1336 | fmt.Printf("Running %v test group %v, key size %d and %v...\n", | 1311 | fmt.Printf("Running %v test group %v, key size %d and %v...\n", algorithm, wtg.Type, wtg.Key.KeySize, wtg.SHA) |
1337 | algorithm, wtg.Type, wtg.Key.KeySize, wtg.SHA) | ||
1338 | 1312 | ||
1339 | dsa := C.DSA_new() | 1313 | dsa := C.DSA_new() |
1340 | if dsa == nil { | 1314 | if dsa == nil { |
@@ -1517,8 +1491,7 @@ func runECDHTest(nid int, variant testVariant, wt *wycheproofTestECDH) bool { | |||
1517 | } | 1491 | } |
1518 | 1492 | ||
1519 | func (wtg *wycheproofTestGroupECDH) run(algorithm string, variant testVariant) bool { | 1493 | func (wtg *wycheproofTestGroupECDH) run(algorithm string, variant testVariant) bool { |
1520 | fmt.Printf("Running %v test group %v with curve %v and %v encoding...\n", | 1494 | fmt.Printf("Running %v test group %v with curve %v and %v encoding...\n", algorithm, wtg.Type, wtg.Curve, wtg.Encoding) |
1521 | algorithm, wtg.Type, wtg.Curve, wtg.Encoding) | ||
1522 | 1495 | ||
1523 | nid, err := nidFromString(wtg.Curve) | 1496 | nid, err := nidFromString(wtg.Curve) |
1524 | if err != nil { | 1497 | if err != nil { |
@@ -1622,8 +1595,7 @@ func runECDHWebCryptoTest(nid int, wt *wycheproofTestECDHWebCrypto) bool { | |||
1622 | } | 1595 | } |
1623 | 1596 | ||
1624 | func (wtg *wycheproofTestGroupECDHWebCrypto) run(algorithm string, variant testVariant) bool { | 1597 | func (wtg *wycheproofTestGroupECDHWebCrypto) run(algorithm string, variant testVariant) bool { |
1625 | fmt.Printf("Running %v test group %v with curve %v and %v encoding...\n", | 1598 | fmt.Printf("Running %v test group %v with curve %v and %v encoding...\n", algorithm, wtg.Type, wtg.Curve, wtg.Encoding) |
1626 | algorithm, wtg.Type, wtg.Curve, wtg.Encoding) | ||
1627 | 1599 | ||
1628 | nid, err := nidFromString(wtg.Curve) | 1600 | nid, err := nidFromString(wtg.Curve) |
1629 | if err != nil { | 1601 | if err != nil { |
@@ -1651,13 +1623,11 @@ func runECDSATest(ecKey *C.EC_KEY, md *C.EVP_MD, nid int, variant testVariant, w | |||
1651 | } | 1623 | } |
1652 | defer C.free(unsafe.Pointer(cDer)) | 1624 | defer C.free(unsafe.Pointer(cDer)) |
1653 | 1625 | ||
1654 | ret = C.ECDSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen), | 1626 | ret = C.ECDSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen), (*C.uchar)(unsafe.Pointer(cDer)), C.int(derLen), ecKey) |
1655 | (*C.uchar)(unsafe.Pointer(cDer)), C.int(derLen), ecKey) | ||
1656 | } else { | 1627 | } else { |
1657 | sig, sigLen := mustDecodeHexString(wt.Sig, "sig") | 1628 | sig, sigLen := mustDecodeHexString(wt.Sig, "sig") |
1658 | 1629 | ||
1659 | ret = C.ECDSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen), | 1630 | ret = C.ECDSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen), (*C.uchar)(unsafe.Pointer(&sig[0])), C.int(sigLen), ecKey) |
1660 | (*C.uchar)(unsafe.Pointer(&sig[0])), C.int(sigLen), ecKey) | ||
1661 | } | 1631 | } |
1662 | 1632 | ||
1663 | // XXX audit acceptable cases... | 1633 | // XXX audit acceptable cases... |
@@ -1670,8 +1640,7 @@ func runECDSATest(ecKey *C.EC_KEY, md *C.EVP_MD, nid int, variant testVariant, w | |||
1670 | } | 1640 | } |
1671 | 1641 | ||
1672 | func (wtg *wycheproofTestGroupECDSA) run(algorithm string, variant testVariant) bool { | 1642 | func (wtg *wycheproofTestGroupECDSA) run(algorithm string, variant testVariant) bool { |
1673 | fmt.Printf("Running %v test group %v with curve %v, key size %d and %v...\n", | 1643 | fmt.Printf("Running %v test group %v with curve %v, key size %d and %v...\n", algorithm, wtg.Type, wtg.Key.Curve, wtg.Key.KeySize, wtg.SHA) |
1674 | algorithm, wtg.Type, wtg.Key.Curve, wtg.Key.KeySize, wtg.SHA) | ||
1675 | 1644 | ||
1676 | nid, err := nidFromString(wtg.Key.Curve) | 1645 | nid, err := nidFromString(wtg.Key.Curve) |
1677 | if err != nil { | 1646 | if err != nil { |
@@ -1770,8 +1739,7 @@ func encodeECDSAWebCryptoSig(wtSig string) (*C.uchar, C.int) { | |||
1770 | } | 1739 | } |
1771 | 1740 | ||
1772 | func (wtg *wycheproofTestGroupECDSAWebCrypto) run(algorithm string, variant testVariant) bool { | 1741 | func (wtg *wycheproofTestGroupECDSAWebCrypto) run(algorithm string, variant testVariant) bool { |
1773 | fmt.Printf("Running %v test group %v with curve %v, key size %d and %v...\n", | 1742 | fmt.Printf("Running %v test group %v with curve %v, key size %d and %v...\n", algorithm, wtg.Type, wtg.Key.Curve, wtg.Key.KeySize, wtg.SHA) |
1774 | algorithm, wtg.Type, wtg.Key.Curve, wtg.Key.KeySize, wtg.SHA) | ||
1775 | 1743 | ||
1776 | nid, err := nidFromString(wtg.JWK.Crv) | 1744 | nid, err := nidFromString(wtg.JWK.Crv) |
1777 | if err != nil { | 1745 | if err != nil { |
@@ -2071,8 +2039,7 @@ func runKWTest(keySize int, wt *wycheproofTestKW) bool { | |||
2071 | } | 2039 | } |
2072 | 2040 | ||
2073 | func (wtg *wycheproofTestGroupKW) run(algorithm string, variant testVariant) bool { | 2041 | func (wtg *wycheproofTestGroupKW) run(algorithm string, variant testVariant) bool { |
2074 | fmt.Printf("Running %v test group %v with key size %d...\n", | 2042 | fmt.Printf("Running %v test group %v with key size %d...\n", algorithm, wtg.Type, wtg.KeySize) |
2075 | algorithm, wtg.Type, wtg.KeySize) | ||
2076 | 2043 | ||
2077 | success := true | 2044 | success := true |
2078 | for _, wt := range wtg.Tests { | 2045 | for _, wt := range wtg.Tests { |
@@ -2157,8 +2124,7 @@ func runRsaesOaepTest(rsa *C.RSA, sha *C.EVP_MD, mgfSha *C.EVP_MD, wt *wycheproo | |||
2157 | } | 2124 | } |
2158 | 2125 | ||
2159 | func (wtg *wycheproofTestGroupRsaesOaep) run(algorithm string, variant testVariant) bool { | 2126 | func (wtg *wycheproofTestGroupRsaesOaep) run(algorithm string, variant testVariant) bool { |
2160 | fmt.Printf("Running %v test group %v with key size %d MGF %v and %v...\n", | 2127 | fmt.Printf("Running %v test group %v with key size %d MGF %v and %v...\n", algorithm, wtg.Type, wtg.KeySize, wtg.MGFSHA, wtg.SHA) |
2161 | algorithm, wtg.Type, wtg.KeySize, wtg.MGFSHA, wtg.SHA) | ||
2162 | 2128 | ||
2163 | rsa := C.RSA_new() | 2129 | rsa := C.RSA_new() |
2164 | if rsa == nil { | 2130 | if rsa == nil { |
@@ -2305,8 +2271,7 @@ func runRsassaTest(rsa *C.RSA, sha *C.EVP_MD, mgfSha *C.EVP_MD, sLen int, wt *wy | |||
2305 | sigOut = append(sigOut, 0) | 2271 | sigOut = append(sigOut, 0) |
2306 | } | 2272 | } |
2307 | 2273 | ||
2308 | ret := C.RSA_public_decrypt(C.int(sigLen), (*C.uchar)(unsafe.Pointer(&sig[0])), | 2274 | 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) |
2309 | (*C.uchar)(unsafe.Pointer(&sigOut[0])), rsa, C.RSA_NO_PADDING) | ||
2310 | if ret == -1 { | 2275 | if ret == -1 { |
2311 | if wt.Result == "invalid" { | 2276 | if wt.Result == "invalid" { |
2312 | return true | 2277 | return true |
@@ -2315,8 +2280,7 @@ func runRsassaTest(rsa *C.RSA, sha *C.EVP_MD, mgfSha *C.EVP_MD, sLen int, wt *wy | |||
2315 | return false | 2280 | return false |
2316 | } | 2281 | } |
2317 | 2282 | ||
2318 | ret = C.RSA_verify_PKCS1_PSS_mgf1(rsa, (*C.uchar)(unsafe.Pointer(&msg[0])), sha, mgfSha, | 2283 | 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)) |
2319 | (*C.uchar)(unsafe.Pointer(&sigOut[0])), C.int(sLen)) | ||
2320 | 2284 | ||
2321 | success := false | 2285 | success := false |
2322 | if ret == 1 && (wt.Result == "valid" || wt.Result == "acceptable") { | 2286 | if ret == 1 && (wt.Result == "valid" || wt.Result == "acceptable") { |
@@ -2332,8 +2296,7 @@ func runRsassaTest(rsa *C.RSA, sha *C.EVP_MD, mgfSha *C.EVP_MD, sLen int, wt *wy | |||
2332 | } | 2296 | } |
2333 | 2297 | ||
2334 | func (wtg *wycheproofTestGroupRsassa) run(algorithm string, variant testVariant) bool { | 2298 | func (wtg *wycheproofTestGroupRsassa) run(algorithm string, variant testVariant) bool { |
2335 | fmt.Printf("Running %v test group %v with key size %d and %v...\n", | 2299 | fmt.Printf("Running %v test group %v with key size %d and %v...\n", algorithm, wtg.Type, wtg.KeySize, wtg.SHA) |
2336 | algorithm, wtg.Type, wtg.KeySize, wtg.SHA) | ||
2337 | rsa := C.RSA_new() | 2300 | rsa := C.RSA_new() |
2338 | if rsa == nil { | 2301 | if rsa == nil { |
2339 | log.Fatal("RSA_new failed") | 2302 | log.Fatal("RSA_new failed") |
@@ -2385,8 +2348,7 @@ func runRSATest(rsa *C.RSA, md *C.EVP_MD, nid int, wt *wycheproofTestRSA) bool { | |||
2385 | msg, msgLen := mustHashHexMessage(md, wt.Msg) | 2348 | msg, msgLen := mustHashHexMessage(md, wt.Msg) |
2386 | sig, sigLen := mustDecodeHexString(wt.Sig, "sig") | 2349 | sig, sigLen := mustDecodeHexString(wt.Sig, "sig") |
2387 | 2350 | ||
2388 | ret := C.RSA_verify(C.int(nid), (*C.uchar)(unsafe.Pointer(&msg[0])), C.uint(msgLen), | 2351 | ret := C.RSA_verify(C.int(nid), (*C.uchar)(unsafe.Pointer(&msg[0])), C.uint(msgLen), (*C.uchar)(unsafe.Pointer(&sig[0])), C.uint(sigLen), rsa) |
2389 | (*C.uchar)(unsafe.Pointer(&sig[0])), C.uint(sigLen), rsa) | ||
2390 | 2352 | ||
2391 | // XXX audit acceptable cases... | 2353 | // XXX audit acceptable cases... |
2392 | success := true | 2354 | success := true |
@@ -2398,8 +2360,7 @@ func runRSATest(rsa *C.RSA, md *C.EVP_MD, nid int, wt *wycheproofTestRSA) bool { | |||
2398 | } | 2360 | } |
2399 | 2361 | ||
2400 | func (wtg *wycheproofTestGroupRSA) run(algorithm string, variant testVariant) bool { | 2362 | func (wtg *wycheproofTestGroupRSA) run(algorithm string, variant testVariant) bool { |
2401 | fmt.Printf("Running %v test group %v with key size %d and %v...\n", | 2363 | fmt.Printf("Running %v test group %v with key size %d and %v...\n", algorithm, wtg.Type, wtg.KeySize, wtg.SHA) |
2402 | algorithm, wtg.Type, wtg.KeySize, wtg.SHA) | ||
2403 | 2364 | ||
2404 | rsa := C.RSA_new() | 2365 | rsa := C.RSA_new() |
2405 | if rsa == nil { | 2366 | if rsa == nil { |
@@ -2542,8 +2503,7 @@ func runTestVectors(path string, variant testVariant) bool { | |||
2542 | if err := json.Unmarshal(b, wtv); err != nil { | 2503 | if err := json.Unmarshal(b, wtv); err != nil { |
2543 | log.Fatalf("Failed to unmarshal JSON: %v", err) | 2504 | log.Fatalf("Failed to unmarshal JSON: %v", err) |
2544 | } | 2505 | } |
2545 | fmt.Printf("Loaded Wycheproof test vectors for %v with %d tests from %q\n", | 2506 | fmt.Printf("Loaded Wycheproof test vectors for %v with %d tests from %q\n", wtv.Algorithm, wtv.NumberOfTests, filepath.Base(path)) |
2546 | wtv.Algorithm, wtv.NumberOfTests, filepath.Base(path)) | ||
2547 | 2507 | ||
2548 | success := true | 2508 | success := true |
2549 | for _, tg := range wtv.TestGroups { | 2509 | for _, tg := range wtv.TestGroups { |