diff options
| author | tb <> | 2018-10-07 04:40:14 +0000 |
|---|---|---|
| committer | tb <> | 2018-10-07 04:40:14 +0000 |
| commit | 5f07e3b5efd218c2a558f5960ef6a0eb72020d71 (patch) | |
| tree | 023fc3dd4bfe252b32a999e56ed1a0468bfcc9df /src | |
| parent | ce8053962db29fbb533dc69df4c158c7964007c3 (diff) | |
| download | openbsd-5f07e3b5efd218c2a558f5960ef6a0eb72020d71.tar.gz openbsd-5f07e3b5efd218c2a558f5960ef6a0eb72020d71.tar.bz2 openbsd-5f07e3b5efd218c2a558f5960ef6a0eb72020d71.zip | |
whitespace cleanup and other minor things from gofmt
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/wycheproof/wycheproof.go | 83 |
1 files changed, 39 insertions, 44 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go index 1243be6d60..ff15d30962 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.80 2018/10/06 18:31:47 tb Exp $ */ | 1 | /* $OpenBSD: wycheproof.go,v 1.81 2018/10/07 04:40:14 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> |
| @@ -44,8 +44,8 @@ import ( | |||
| 44 | "crypto/sha1" | 44 | "crypto/sha1" |
| 45 | "crypto/sha256" | 45 | "crypto/sha256" |
| 46 | "crypto/sha512" | 46 | "crypto/sha512" |
| 47 | "encoding/hex" | ||
| 48 | "encoding/base64" | 47 | "encoding/base64" |
| 48 | "encoding/hex" | ||
| 49 | "encoding/json" | 49 | "encoding/json" |
| 50 | "flag" | 50 | "flag" |
| 51 | "fmt" | 51 | "fmt" |
| @@ -878,14 +878,14 @@ func runAesCmacTest(cipher *C.EVP_CIPHER, wt *wycheproofTestAesCmac) bool { | |||
| 878 | ret := C.CMAC_Init(ctx, unsafe.Pointer(&key[0]), C.size_t(keyLen), cipher, nil) | 878 | ret := C.CMAC_Init(ctx, unsafe.Pointer(&key[0]), C.size_t(keyLen), cipher, nil) |
| 879 | if ret != 1 { | 879 | if ret != 1 { |
| 880 | fmt.Printf("FAIL: Test case %d (%q) %v - CMAC_Init() = %d, want %v\n", | 880 | fmt.Printf("FAIL: Test case %d (%q) %v - CMAC_Init() = %d, want %v\n", |
| 881 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) | 881 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) |
| 882 | return false | 882 | return false |
| 883 | } | 883 | } |
| 884 | 884 | ||
| 885 | ret = C.CMAC_Update(ctx, unsafe.Pointer(&msg[0]), C.size_t(msgLen)) | 885 | ret = C.CMAC_Update(ctx, unsafe.Pointer(&msg[0]), C.size_t(msgLen)) |
| 886 | if ret != 1 { | 886 | if ret != 1 { |
| 887 | fmt.Printf("FAIL: Test case %d (%q) %v - CMAC_Update() = %d, want %v\n", | 887 | fmt.Printf("FAIL: Test case %d (%q) %v - CMAC_Update() = %d, want %v\n", |
| 888 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) | 888 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) |
| 889 | return false | 889 | return false |
| 890 | } | 890 | } |
| 891 | 891 | ||
| @@ -895,7 +895,7 @@ func runAesCmacTest(cipher *C.EVP_CIPHER, wt *wycheproofTestAesCmac) bool { | |||
| 895 | ret = C.CMAC_Final(ctx, (*C.uchar)(unsafe.Pointer(&outTag[0])), &outLen) | 895 | ret = C.CMAC_Final(ctx, (*C.uchar)(unsafe.Pointer(&outTag[0])), &outLen) |
| 896 | if ret != 1 { | 896 | if ret != 1 { |
| 897 | fmt.Printf("FAIL: Test case %d (%q) %v - CMAC_Final() = %d, want %v\n", | 897 | fmt.Printf("FAIL: Test case %d (%q) %v - CMAC_Final() = %d, want %v\n", |
| 898 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) | 898 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) |
| 899 | return false | 899 | return false |
| 900 | } | 900 | } |
| 901 | 901 | ||
| @@ -904,7 +904,7 @@ func runAesCmacTest(cipher *C.EVP_CIPHER, wt *wycheproofTestAesCmac) bool { | |||
| 904 | success := true | 904 | success := true |
| 905 | if bytes.Equal(tag, outTag) != (wt.Result == "valid") { | 905 | if bytes.Equal(tag, outTag) != (wt.Result == "valid") { |
| 906 | fmt.Printf("FAIL: Test case %d (%q) %v - want %v\n", | 906 | fmt.Printf("FAIL: Test case %d (%q) %v - want %v\n", |
| 907 | wt.TCID, wt.Comment, wt.Flags, wt.Result) | 907 | wt.TCID, wt.Comment, wt.Flags, wt.Result) |
| 908 | success = false | 908 | success = false |
| 909 | } | 909 | } |
| 910 | return success | 910 | return success |
| @@ -955,13 +955,13 @@ func checkAeadOpen(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen | |||
| 955 | return true | 955 | return true |
| 956 | } | 956 | } |
| 957 | fmt.Printf("FAIL: Test case %d (%q) %v - EVP_AEAD_CTX_open() = %d, want %v\n", | 957 | fmt.Printf("FAIL: Test case %d (%q) %v - EVP_AEAD_CTX_open() = %d, want %v\n", |
| 958 | wt.TCID, wt.Comment, wt.Flags, int(openRet), wt.Result) | 958 | wt.TCID, wt.Comment, wt.Flags, int(openRet), wt.Result) |
| 959 | return false | 959 | return false |
| 960 | } | 960 | } |
| 961 | 961 | ||
| 962 | if openedMsgLen != C.size_t(msgLen) { | 962 | if openedMsgLen != C.size_t(msgLen) { |
| 963 | fmt.Printf("FAIL: Test case %d (%q) %v - open length mismatch: got %d, want %d\n", | 963 | fmt.Printf("FAIL: Test case %d (%q) %v - open length mismatch: got %d, want %d\n", |
| 964 | wt.TCID, wt.Comment, wt.Flags, openedMsgLen, msgLen) | 964 | wt.TCID, wt.Comment, wt.Flags, openedMsgLen, msgLen) |
| 965 | return false | 965 | return false |
| 966 | } | 966 | } |
| 967 | 967 | ||
| @@ -978,7 +978,7 @@ func checkAeadOpen(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen | |||
| 978 | success = true | 978 | success = true |
| 979 | } else { | 979 | } else { |
| 980 | fmt.Printf("FAIL: Test case %d (%q) %v - msg match: %t; want %v\n", | 980 | fmt.Printf("FAIL: Test case %d (%q) %v - msg match: %t; want %v\n", |
| 981 | wt.TCID, wt.Comment, wt.Flags, bytes.Equal(openedMsg, msg), wt.Result) | 981 | wt.TCID, wt.Comment, wt.Flags, bytes.Equal(openedMsg, msg), wt.Result) |
| 982 | } | 982 | } |
| 983 | return success | 983 | return success |
| 984 | } | 984 | } |
| @@ -998,13 +998,13 @@ func checkAeadSeal(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen | |||
| 998 | 998 | ||
| 999 | if sealRet != 1 { | 999 | if sealRet != 1 { |
| 1000 | 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", |
| 1001 | wt.TCID, wt.Comment, wt.Flags, int(sealRet), wt.Result) | 1001 | wt.TCID, wt.Comment, wt.Flags, int(sealRet), wt.Result) |
| 1002 | return false | 1002 | return false |
| 1003 | } | 1003 | } |
| 1004 | 1004 | ||
| 1005 | if sealedLen != C.size_t(maxOutLen) { | 1005 | if sealedLen != C.size_t(maxOutLen) { |
| 1006 | fmt.Printf("FAIL: Test case %d (%q) %v - seal length mismatch: got %d, want %d\n", | 1006 | fmt.Printf("FAIL: Test case %d (%q) %v - seal length mismatch: got %d, want %d\n", |
| 1007 | wt.TCID, wt.Comment, wt.Flags, sealedLen, maxOutLen) | 1007 | wt.TCID, wt.Comment, wt.Flags, sealedLen, maxOutLen) |
| 1008 | return false | 1008 | return false |
| 1009 | } | 1009 | } |
| 1010 | 1010 | ||
| @@ -1019,7 +1019,7 @@ func checkAeadSeal(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen | |||
| 1019 | success = true | 1019 | success = true |
| 1020 | } else { | 1020 | } else { |
| 1021 | fmt.Printf("FAIL: Test case %d (%q) %v - EVP_AEAD_CTX_seal() = %d, ct match: %t, tag match: %t; want %v\n", | 1021 | fmt.Printf("FAIL: Test case %d (%q) %v - EVP_AEAD_CTX_seal() = %d, ct match: %t, tag match: %t; want %v\n", |
| 1022 | wt.TCID, wt.Comment, wt.Flags, int(sealRet), | 1022 | wt.TCID, wt.Comment, wt.Flags, int(sealRet), |
| 1023 | bytes.Equal(sealedCt, ct), bytes.Equal(sealedTag, tag), wt.Result) | 1023 | bytes.Equal(sealedCt, ct), bytes.Equal(sealedTag, tag), wt.Result) |
| 1024 | } | 1024 | } |
| 1025 | return success | 1025 | return success |
| @@ -1122,9 +1122,9 @@ func runDSATest(dsa *C.DSA, h hash.Hash, wt *wycheproofTestDSA) bool { | |||
| 1122 | (*C.uchar)(unsafe.Pointer(&sig[0])), C.int(sigLen), dsa) | 1122 | (*C.uchar)(unsafe.Pointer(&sig[0])), C.int(sigLen), dsa) |
| 1123 | 1123 | ||
| 1124 | success := true | 1124 | success := true |
| 1125 | if (ret == 1) != (wt.Result == "valid") { | 1125 | if ret == 1 != (wt.Result == "valid") { |
| 1126 | fmt.Printf("FAIL: Test case %d (%q) %v - DSA_verify() = %d, want %v\n", | 1126 | fmt.Printf("FAIL: Test case %d (%q) %v - DSA_verify() = %d, want %v\n", |
| 1127 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) | 1127 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) |
| 1128 | success = false | 1128 | success = false |
| 1129 | } | 1129 | } |
| 1130 | return success | 1130 | return success |
| @@ -1183,7 +1183,6 @@ func runDSATestGroup(algorithm string, wtg *wycheproofTestGroupDSA) bool { | |||
| 1183 | log.Fatalf("Failed to get hash: %v", err) | 1183 | log.Fatalf("Failed to get hash: %v", err) |
| 1184 | } | 1184 | } |
| 1185 | 1185 | ||
| 1186 | |||
| 1187 | der, err := hex.DecodeString(wtg.KeyDER) | 1186 | der, err := hex.DecodeString(wtg.KeyDER) |
| 1188 | if err != nil { | 1187 | if err != nil { |
| 1189 | log.Fatalf("Failed to decode DER encoded key: %v", err) | 1188 | log.Fatalf("Failed to decode DER encoded key: %v", err) |
| @@ -1205,7 +1204,6 @@ func runDSATestGroup(algorithm string, wtg *wycheproofTestGroupDSA) bool { | |||
| 1205 | defer C.DSA_free(dsaDER) | 1204 | defer C.DSA_free(dsaDER) |
| 1206 | C.free(unsafe.Pointer(Cder)) | 1205 | C.free(unsafe.Pointer(Cder)) |
| 1207 | 1206 | ||
| 1208 | |||
| 1209 | keyPEM := C.CString(wtg.KeyPEM) | 1207 | keyPEM := C.CString(wtg.KeyPEM) |
| 1210 | bio := C.BIO_new_mem_buf(unsafe.Pointer(keyPEM), C.int(len(wtg.KeyPEM))) | 1208 | bio := C.BIO_new_mem_buf(unsafe.Pointer(keyPEM), C.int(len(wtg.KeyPEM))) |
| 1211 | if bio == nil { | 1209 | if bio == nil { |
| @@ -1220,7 +1218,6 @@ func runDSATestGroup(algorithm string, wtg *wycheproofTestGroupDSA) bool { | |||
| 1220 | } | 1218 | } |
| 1221 | defer C.DSA_free(dsaPEM) | 1219 | defer C.DSA_free(dsaPEM) |
| 1222 | 1220 | ||
| 1223 | |||
| 1224 | success := true | 1221 | success := true |
| 1225 | for _, wt := range wtg.Tests { | 1222 | for _, wt := range wtg.Tests { |
| 1226 | if !runDSATest(dsa, h, wt) { | 1223 | if !runDSATest(dsa, h, wt) { |
| @@ -1254,7 +1251,7 @@ func runECDHTest(nid int, doECpoint bool, wt *wycheproofTestECDH) bool { | |||
| 1254 | ret := C.EC_KEY_set_private_key(privKey, bnPriv) | 1251 | ret := C.EC_KEY_set_private_key(privKey, bnPriv) |
| 1255 | if ret != 1 { | 1252 | if ret != 1 { |
| 1256 | fmt.Printf("FAIL: Test case %d (%q) %v - EC_KEY_set_private_key() = %d, want %v\n", | 1253 | fmt.Printf("FAIL: Test case %d (%q) %v - EC_KEY_set_private_key() = %d, want %v\n", |
| 1257 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) | 1254 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) |
| 1258 | return false | 1255 | return false |
| 1259 | } | 1256 | } |
| 1260 | 1257 | ||
| @@ -1276,7 +1273,7 @@ func runECDHTest(nid int, doECpoint bool, wt *wycheproofTestECDH) bool { | |||
| 1276 | 1273 | ||
| 1277 | p := (*C.uchar)(Cpub) | 1274 | p := (*C.uchar)(Cpub) |
| 1278 | var pubKey *C.EC_KEY | 1275 | var pubKey *C.EC_KEY |
| 1279 | if (doECpoint) { | 1276 | if doECpoint { |
| 1280 | pubKey = C.EC_KEY_new_by_curve_name(C.int(nid)) | 1277 | pubKey = C.EC_KEY_new_by_curve_name(C.int(nid)) |
| 1281 | if pubKey == nil { | 1278 | if pubKey == nil { |
| 1282 | log.Fatal("EC_KEY_new_by_curve_name failed") | 1279 | log.Fatal("EC_KEY_new_by_curve_name failed") |
| @@ -1293,13 +1290,13 @@ func runECDHTest(nid int, doECpoint bool, wt *wycheproofTestECDH) bool { | |||
| 1293 | return true | 1290 | return true |
| 1294 | } | 1291 | } |
| 1295 | fmt.Printf("FAIL: Test case %d (%q) %v - ASN decoding failed: want %v\n", | 1292 | fmt.Printf("FAIL: Test case %d (%q) %v - ASN decoding failed: want %v\n", |
| 1296 | wt.TCID, wt.Comment, wt.Flags, wt.Result) | 1293 | wt.TCID, wt.Comment, wt.Flags, wt.Result) |
| 1297 | return false | 1294 | return false |
| 1298 | } | 1295 | } |
| 1299 | 1296 | ||
| 1300 | privGroup := C.EC_KEY_get0_group(privKey) | 1297 | privGroup := C.EC_KEY_get0_group(privKey) |
| 1301 | 1298 | ||
| 1302 | secLen := (C.EC_GROUP_get_degree(privGroup) + 7) / 8 | 1299 | secLen := (C.EC_GROUP_get_degree(privGroup) + 7) / 8 |
| 1303 | 1300 | ||
| 1304 | secret := make([]byte, secLen) | 1301 | secret := make([]byte, secLen) |
| 1305 | if secLen == 0 { | 1302 | if secLen == 0 { |
| @@ -1314,19 +1311,19 @@ func runECDHTest(nid int, doECpoint bool, wt *wycheproofTestECDH) bool { | |||
| 1314 | return true | 1311 | return true |
| 1315 | } | 1312 | } |
| 1316 | fmt.Printf("FAIL: Test case %d (%q) %v - ECDH_compute_key() = %d, want %d, result: %v\n", | 1313 | fmt.Printf("FAIL: Test case %d (%q) %v - ECDH_compute_key() = %d, want %d, result: %v\n", |
| 1317 | wt.TCID, wt.Comment, wt.Flags, ret, int(secLen), wt.Result) | 1314 | wt.TCID, wt.Comment, wt.Flags, ret, int(secLen), wt.Result) |
| 1318 | return false | 1315 | return false |
| 1319 | } | 1316 | } |
| 1320 | 1317 | ||
| 1321 | shared, err := hex.DecodeString(wt.Shared) | 1318 | shared, err := hex.DecodeString(wt.Shared) |
| 1322 | if err != nil{ | 1319 | if err != nil { |
| 1323 | log.Fatalf("Failed to decode shared secret: %v", err) | 1320 | log.Fatalf("Failed to decode shared secret: %v", err) |
| 1324 | } | 1321 | } |
| 1325 | 1322 | ||
| 1326 | success := true | 1323 | success := true |
| 1327 | if !bytes.Equal(shared, secret) { | 1324 | if !bytes.Equal(shared, secret) { |
| 1328 | fmt.Printf("FAIL: Test case %d (%q) %v - expected and computed shared secret do not match, want %v\n", | 1325 | fmt.Printf("FAIL: Test case %d (%q) %v - expected and computed shared secret do not match, want %v\n", |
| 1329 | wt.TCID, wt.Comment, wt.Flags, wt.Result) | 1326 | wt.TCID, wt.Comment, wt.Flags, wt.Result) |
| 1330 | success = false | 1327 | success = false |
| 1331 | } | 1328 | } |
| 1332 | if acceptableAudit && success && wt.Result == "acceptable" { | 1329 | if acceptableAudit && success && wt.Result == "acceptable" { |
| @@ -1370,7 +1367,7 @@ func runECDHWebCryptoTest(nid int, wt *wycheproofTestECDHWebCrypto) bool { | |||
| 1370 | if err != nil { | 1367 | if err != nil { |
| 1371 | log.Fatalf("Failed to base64 decode d: %v", err) | 1368 | log.Fatalf("Failed to base64 decode d: %v", err) |
| 1372 | } | 1369 | } |
| 1373 | bnD = C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&d[0])), (C.int)(len(d)), nil) | 1370 | bnD = C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&d[0])), C.int(len(d)), nil) |
| 1374 | if bnD == nil { | 1371 | if bnD == nil { |
| 1375 | log.Fatal("Failed to decode D") | 1372 | log.Fatal("Failed to decode D") |
| 1376 | } | 1373 | } |
| @@ -1388,7 +1385,7 @@ func runECDHWebCryptoTest(nid int, wt *wycheproofTestECDHWebCrypto) bool { | |||
| 1388 | if err != nil { | 1385 | if err != nil { |
| 1389 | log.Fatalf("Failed to base64 decode x: %v", err) | 1386 | log.Fatalf("Failed to base64 decode x: %v", err) |
| 1390 | } | 1387 | } |
| 1391 | bnX = C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&x[0])), (C.int)(len(x)), nil) | 1388 | bnX = C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&x[0])), C.int(len(x)), nil) |
| 1392 | if bnX == nil { | 1389 | if bnX == nil { |
| 1393 | log.Fatal("Failed to decode X") | 1390 | log.Fatal("Failed to decode X") |
| 1394 | } | 1391 | } |
| @@ -1399,7 +1396,7 @@ func runECDHWebCryptoTest(nid int, wt *wycheproofTestECDHWebCrypto) bool { | |||
| 1399 | if err != nil { | 1396 | if err != nil { |
| 1400 | log.Fatalf("Failed to base64 decode y: %v", err) | 1397 | log.Fatalf("Failed to base64 decode y: %v", err) |
| 1401 | } | 1398 | } |
| 1402 | bnY = C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&y[0])), (C.int)(len(y)), nil) | 1399 | bnY = C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&y[0])), C.int(len(y)), nil) |
| 1403 | if bnY == nil { | 1400 | if bnY == nil { |
| 1404 | log.Fatal("Failed to decode Y") | 1401 | log.Fatal("Failed to decode Y") |
| 1405 | } | 1402 | } |
| @@ -1424,7 +1421,7 @@ func runECDHWebCryptoTest(nid int, wt *wycheproofTestECDHWebCrypto) bool { | |||
| 1424 | 1421 | ||
| 1425 | privGroup := C.EC_KEY_get0_group(privKey) | 1422 | privGroup := C.EC_KEY_get0_group(privKey) |
| 1426 | 1423 | ||
| 1427 | secLen := (C.EC_GROUP_get_degree(privGroup) + 7) / 8 | 1424 | secLen := (C.EC_GROUP_get_degree(privGroup) + 7) / 8 |
| 1428 | 1425 | ||
| 1429 | secret := make([]byte, secLen) | 1426 | secret := make([]byte, secLen) |
| 1430 | if secLen == 0 { | 1427 | if secLen == 0 { |
| @@ -1437,19 +1434,19 @@ func runECDHWebCryptoTest(nid int, wt *wycheproofTestECDHWebCrypto) bool { | |||
| 1437 | return true | 1434 | return true |
| 1438 | } | 1435 | } |
| 1439 | fmt.Printf("FAIL: Test case %d (%q) %v - ECDH_compute_key() = %d, want %d, result: %v\n", | 1436 | fmt.Printf("FAIL: Test case %d (%q) %v - ECDH_compute_key() = %d, want %d, result: %v\n", |
| 1440 | wt.TCID, wt.Comment, wt.Flags, ret, int(secLen), wt.Result) | 1437 | wt.TCID, wt.Comment, wt.Flags, ret, int(secLen), wt.Result) |
| 1441 | return false | 1438 | return false |
| 1442 | } | 1439 | } |
| 1443 | 1440 | ||
| 1444 | shared, err := hex.DecodeString(wt.Shared) | 1441 | shared, err := hex.DecodeString(wt.Shared) |
| 1445 | if err != nil{ | 1442 | if err != nil { |
| 1446 | log.Fatalf("Failed to decode shared secret: %v", err) | 1443 | log.Fatalf("Failed to decode shared secret: %v", err) |
| 1447 | } | 1444 | } |
| 1448 | 1445 | ||
| 1449 | success := true | 1446 | success := true |
| 1450 | if !bytes.Equal(shared, secret) { | 1447 | if !bytes.Equal(shared, secret) { |
| 1451 | fmt.Printf("FAIL: Test case %d (%q) %v - expected and computed shared secret do not match, want %v\n", | 1448 | fmt.Printf("FAIL: Test case %d (%q) %v - expected and computed shared secret do not match, want %v\n", |
| 1452 | wt.TCID, wt.Comment, wt.Flags, wt.Result) | 1449 | wt.TCID, wt.Comment, wt.Flags, wt.Result) |
| 1453 | success = false | 1450 | success = false |
| 1454 | } | 1451 | } |
| 1455 | if acceptableAudit && success && wt.Result == "acceptable" { | 1452 | if acceptableAudit && success && wt.Result == "acceptable" { |
| @@ -1518,9 +1515,9 @@ func runECDSATest(ecKey *C.EC_KEY, nid int, h hash.Hash, webcrypto bool, wt *wyc | |||
| 1518 | 1515 | ||
| 1519 | // XXX audit acceptable cases... | 1516 | // XXX audit acceptable cases... |
| 1520 | success := true | 1517 | success := true |
| 1521 | if (ret == 1) != (wt.Result == "valid") && wt.Result != "acceptable" { | 1518 | if ret == 1 != (wt.Result == "valid") && wt.Result != "acceptable" { |
| 1522 | fmt.Printf("FAIL: Test case %d (%q) %v - ECDSA_verify() = %d, want %v\n", | 1519 | fmt.Printf("FAIL: Test case %d (%q) %v - ECDSA_verify() = %d, want %v\n", |
| 1523 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) | 1520 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) |
| 1524 | success = false | 1521 | success = false |
| 1525 | } | 1522 | } |
| 1526 | if acceptableAudit && ret == 1 && wt.Result == "acceptable" { | 1523 | if acceptableAudit && ret == 1 && wt.Result == "acceptable" { |
| @@ -1639,7 +1636,7 @@ func runECDSAWebCryptoTestGroup(algorithm string, wtg *wycheproofTestGroupECDSAW | |||
| 1639 | log.Fatalf("Failed to base64 decode X: %v", err) | 1636 | log.Fatalf("Failed to base64 decode X: %v", err) |
| 1640 | } | 1637 | } |
| 1641 | var bnX *C.BIGNUM | 1638 | var bnX *C.BIGNUM |
| 1642 | bnX = C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&x[0])), (C.int)(len(x)), nil) | 1639 | bnX = C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&x[0])), C.int(len(x)), nil) |
| 1643 | if bnX == nil { | 1640 | if bnX == nil { |
| 1644 | log.Fatal("Failed to decode X") | 1641 | log.Fatal("Failed to decode X") |
| 1645 | } | 1642 | } |
| @@ -1650,7 +1647,7 @@ func runECDSAWebCryptoTestGroup(algorithm string, wtg *wycheproofTestGroupECDSAW | |||
| 1650 | log.Fatalf("Failed to base64 decode Y: %v", err) | 1647 | log.Fatalf("Failed to base64 decode Y: %v", err) |
| 1651 | } | 1648 | } |
| 1652 | var bnY *C.BIGNUM | 1649 | var bnY *C.BIGNUM |
| 1653 | bnY = C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&y[0])), (C.int)(len(y)), nil) | 1650 | bnY = C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&y[0])), C.int(len(y)), nil) |
| 1654 | if bnY == nil { | 1651 | if bnY == nil { |
| 1655 | log.Fatal("Failed to decode Y") | 1652 | log.Fatal("Failed to decode Y") |
| 1656 | } | 1653 | } |
| @@ -1713,7 +1710,7 @@ func runRSASSATest(rsa *C.RSA, h hash.Hash, sha *C.EVP_MD, mgfSha *C.EVP_MD, sLe | |||
| 1713 | return true | 1710 | return true |
| 1714 | } | 1711 | } |
| 1715 | fmt.Printf("FAIL: Test case %d (%q) %v - RSA_public_decrypt() = %d, want %v\n", | 1712 | fmt.Printf("FAIL: Test case %d (%q) %v - RSA_public_decrypt() = %d, want %v\n", |
| 1716 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) | 1713 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) |
| 1717 | return false | 1714 | return false |
| 1718 | } | 1715 | } |
| 1719 | 1716 | ||
| @@ -1732,7 +1729,7 @@ func runRSASSATest(rsa *C.RSA, h hash.Hash, sha *C.EVP_MD, mgfSha *C.EVP_MD, sLe | |||
| 1732 | success = true | 1729 | success = true |
| 1733 | } else { | 1730 | } else { |
| 1734 | fmt.Printf("FAIL: Test case %d (%q) %v - RSA_verify_PKCS1_PSS_mgf1() = %d, want %v\n", | 1731 | fmt.Printf("FAIL: Test case %d (%q) %v - RSA_verify_PKCS1_PSS_mgf1() = %d, want %v\n", |
| 1735 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) | 1732 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) |
| 1736 | } | 1733 | } |
| 1737 | return success | 1734 | return success |
| 1738 | } | 1735 | } |
| @@ -1810,9 +1807,9 @@ func runRSATest(rsa *C.RSA, nid int, h hash.Hash, wt *wycheproofTestRSA) bool { | |||
| 1810 | 1807 | ||
| 1811 | // XXX audit acceptable cases... | 1808 | // XXX audit acceptable cases... |
| 1812 | success := true | 1809 | success := true |
| 1813 | if (ret == 1) != (wt.Result == "valid") && wt.Result != "acceptable" { | 1810 | if ret == 1 != (wt.Result == "valid") && wt.Result != "acceptable" { |
| 1814 | fmt.Printf("FAIL: Test case %d (%q) %v - RSA_verify() = %d, want %v\n", | 1811 | fmt.Printf("FAIL: Test case %d (%q) %v - RSA_verify() = %d, want %v\n", |
| 1815 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) | 1812 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) |
| 1816 | success = false | 1813 | success = false |
| 1817 | } | 1814 | } |
| 1818 | if acceptableAudit && ret == 1 && wt.Result == "acceptable" { | 1815 | if acceptableAudit && ret == 1 && wt.Result == "acceptable" { |
| @@ -1888,7 +1885,7 @@ func runX25519Test(wt *wycheproofTestX25519) bool { | |||
| 1888 | success := true | 1885 | success := true |
| 1889 | if result != (wt.Result == "valid") && wt.Result != "acceptable" { | 1886 | if result != (wt.Result == "valid") && wt.Result != "acceptable" { |
| 1890 | fmt.Printf("FAIL: Test case %d (%q) %v - X25519(), want %v\n", | 1887 | fmt.Printf("FAIL: Test case %d (%q) %v - X25519(), want %v\n", |
| 1891 | wt.TCID, wt.Comment, wt.Flags, wt.Result) | 1888 | wt.TCID, wt.Comment, wt.Flags, wt.Result) |
| 1892 | success = false | 1889 | success = false |
| 1893 | } | 1890 | } |
| 1894 | if acceptableAudit && result && wt.Result == "acceptable" { | 1891 | if acceptableAudit && result && wt.Result == "acceptable" { |
| @@ -1947,7 +1944,6 @@ func runTestVectors(path string, webcrypto bool) bool { | |||
| 1947 | } else { | 1944 | } else { |
| 1948 | wtg = &wycheproofTestGroupECDSA{} | 1945 | wtg = &wycheproofTestGroupECDSA{} |
| 1949 | } | 1946 | } |
| 1950 | |||
| 1951 | case "RSASSA-PSS": | 1947 | case "RSASSA-PSS": |
| 1952 | wtg = &wycheproofTestGroupRSASSA{} | 1948 | wtg = &wycheproofTestGroupRSASSA{} |
| 1953 | case "RSASig": | 1949 | case "RSASig": |
| @@ -1998,7 +1994,6 @@ func runTestVectors(path string, webcrypto bool) bool { | |||
| 1998 | success = false | 1994 | success = false |
| 1999 | } | 1995 | } |
| 2000 | } | 1996 | } |
| 2001 | |||
| 2002 | case "ECDSA": | 1997 | case "ECDSA": |
| 2003 | if webcrypto { | 1998 | if webcrypto { |
| 2004 | if !runECDSAWebCryptoTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupECDSAWebCrypto)) { | 1999 | if !runECDSAWebCryptoTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupECDSAWebCrypto)) { |
| @@ -2037,7 +2032,7 @@ func main() { | |||
| 2037 | 2032 | ||
| 2038 | flag.BoolVar(&acceptableAudit, "v", false, "audit acceptable cases") | 2033 | flag.BoolVar(&acceptableAudit, "v", false, "audit acceptable cases") |
| 2039 | flag.Parse() | 2034 | flag.Parse() |
| 2040 | 2035 | ||
| 2041 | acceptableComments = make(map[string]int) | 2036 | acceptableComments = make(map[string]int) |
| 2042 | acceptableFlags = make(map[string]int) | 2037 | acceptableFlags = make(map[string]int) |
| 2043 | 2038 | ||
| @@ -2059,7 +2054,7 @@ func main() { | |||
| 2059 | success := true | 2054 | success := true |
| 2060 | 2055 | ||
| 2061 | for _, test := range tests { | 2056 | for _, test := range tests { |
| 2062 | webcrypto := (test.name == "ECDSAWebCrypto") || test.name == "ECDHWebCrypto" | 2057 | webcrypto := test.name == "ECDSAWebCrypto" || test.name == "ECDHWebCrypto" |
| 2063 | tvs, err := filepath.Glob(filepath.Join(testVectorPath, test.pattern)) | 2058 | tvs, err := filepath.Glob(filepath.Join(testVectorPath, test.pattern)) |
| 2064 | if err != nil { | 2059 | if err != nil { |
| 2065 | log.Fatalf("Failed to glob %v test vectors: %v", test.name, err) | 2060 | log.Fatalf("Failed to glob %v test vectors: %v", test.name, err) |
