t.Fatalf("go list: %v\n%s", err, out)
}
- // Ensure we don't import any unexpected internal package from the FIPS
- // module, since we can't change the module source after it starts
- // validation. This locks in the API of otherwise internal packages.
+ allPackages := make(map[string]bool)
+
+ // importCheck is the set of packages that import crypto/internal/fips/check.
+ importCheck := make(map[string]bool)
+
for _, line := range strings.Split(string(out), "\n") {
if line == "" {
continue
}
- parts := strings.Fields(line)
- if parts[1] == "crypto/internal/fips" ||
- strings.HasPrefix(parts[1], "crypto/internal/fips/") ||
- strings.HasPrefix(parts[1], "crypto/internal/fipsdeps/") {
+ pkg, importedPkg, _ := strings.Cut(line, " ")
+
+ allPackages[pkg] = true
+
+ if importedPkg == "crypto/internal/fips/check" {
+ importCheck[pkg] = true
+ }
+
+ // Ensure we don't import any unexpected internal package from the FIPS
+ // module, since we can't change the module source after it starts
+ // validation. This locks in the API of otherwise internal packages.
+ if importedPkg == "crypto/internal/fips" ||
+ strings.HasPrefix(importedPkg, "crypto/internal/fips/") ||
+ strings.HasPrefix(importedPkg, "crypto/internal/fipsdeps/") {
continue
}
- if AllowedInternalPackages[parts[1]] {
+ if AllowedInternalPackages[importedPkg] {
continue
}
- if strings.Contains(parts[1], "internal") {
- t.Errorf("unexpected import of internal package: %s -> %s", parts[0], parts[1])
+ if strings.Contains(importedPkg, "internal") {
+ t.Errorf("unexpected import of internal package: %s -> %s", pkg, importedPkg)
+ }
+ }
+
+ // Ensure that all packages except check and check's dependencies import check.
+ for pkg := range allPackages {
+ switch pkg {
+ case "crypto/internal/fips/check":
+ case "crypto/internal/fips":
+ case "crypto/internal/fips/alias":
+ case "crypto/internal/fips/subtle":
+ case "crypto/internal/fips/hmac":
+ case "crypto/internal/fips/sha3":
+ case "crypto/internal/fips/sha256":
+ case "crypto/internal/fips/sha512":
+ default:
+ if !importCheck[pkg] {
+ t.Errorf("package %s does not import crypto/internal/fips/check", pkg)
+ }
}
}
}
< crypto/internal/fips
< crypto/internal/fips/alias
< crypto/internal/fips/subtle
- < crypto/internal/fips/aes
- < crypto/internal/fips/drbg
- < crypto/internal/fips/aes/gcm
< crypto/internal/fips/sha256
< crypto/internal/fips/sha512
< crypto/internal/fips/sha3
< crypto/internal/fips/hmac
< crypto/internal/fips/check
+ < crypto/internal/fips/aes
+ < crypto/internal/fips/drbg
+ < crypto/internal/fips/aes/gcm
< crypto/internal/fips/hkdf
< crypto/internal/fips/mlkem
< crypto/internal/fips/ssh