(filename string)
| 53 | } |
| 54 | |
| 55 | func checkVectorFile(filename string) int { |
| 56 | data, err := os.ReadFile(filename) |
| 57 | if err != nil { |
| 58 | panic(fmt.Sprintf("failed to read vector file: %v", err)) |
| 59 | } |
| 60 | |
| 61 | var vectors TestVector |
| 62 | if err := json.Unmarshal(data, &vectors); err != nil { |
| 63 | panic(fmt.Sprintf("failed to parse vector JSON: %v", err)) |
| 64 | } |
| 65 | |
| 66 | errors := 0 |
| 67 | for _, group := range vectors.TestGroups { |
| 68 | for _, test := range group.Tests { |
| 69 | |
| 70 | publicKeyBytes, err := extractPublicKey(test.Public) |
| 71 | if err != nil || slices.Contains(test.Flags, "InvalidPublic") { |
| 72 | // Skip test vectors with invalid public keys (different test concern) |
| 73 | continue |
| 74 | } |
| 75 | |
| 76 | var expectedLen int |
| 77 | switch group.Curve { |
| 78 | case "curve25519": |
| 79 | expectedLen = 32 |
| 80 | case "curve448": |
| 81 | expectedLen = 56 |
| 82 | default: |
| 83 | panic(fmt.Sprintf("unknown curve: %s", group.Curve)) |
| 84 | } |
| 85 | |
| 86 | if len(publicKeyBytes) != expectedLen { |
| 87 | // Skip test vectors with invalid key lengths (different test concern) |
| 88 | continue |
| 89 | } |
| 90 | |
| 91 | isOnTwist, err := isPointOnTwist(publicKeyBytes, group.Curve) |
| 92 | if err != nil { |
| 93 | log.Printf("❌ tcId %d: error checking twist: %v", test.TcId, err) |
| 94 | errors++ |
| 95 | continue |
| 96 | } |
| 97 | |
| 98 | hasTwistFlag := slices.Contains(test.Flags, "Twist") |
| 99 | |
| 100 | if !isOnTwist && hasTwistFlag { |
| 101 | log.Printf("❌ tcId %d: point is not on twist but has 'Twist' flag", test.TcId) |
| 102 | errors++ |
| 103 | } else if isOnTwist && !hasTwistFlag { |
| 104 | log.Printf("❌ tcId %d: point is on twist but missing 'Twist' flag", test.TcId) |
| 105 | errors++ |
| 106 | } else if !isOnTwist { |
| 107 | continue |
| 108 | } |
| 109 | |
| 110 | if test.Result != "acceptable" { |
| 111 | log.Printf("❌ tcId %d: point is on twist but result is %q (expected 'acceptable')", test.TcId, test.Result) |
| 112 | errors++ |
no test coverage detected