1
2
3
4
5 package fips140
6
7 import (
8 "crypto/internal/fips140deps/godebug"
9 "errors"
10 "runtime"
11 )
12
13 var Enabled bool
14
15 var debug bool
16
17 func init() {
18 v := godebug.Value("#fips140")
19 switch v {
20 case "on", "only":
21 Enabled = true
22 case "debug":
23 Enabled = true
24 debug = true
25 case "off", "":
26 default:
27 panic("fips140: unknown GODEBUG setting fips140=" + v)
28 }
29 }
30
31
32 func Supported() error {
33
34
35
36
37
38
39
40 if asanEnabled {
41 return errors.New("FIPS 140-3 mode is incompatible with ASAN")
42 }
43
44
45 switch {
46 case runtime.GOARCH == "wasm",
47 runtime.GOOS == "windows" && runtime.GOARCH == "386",
48 runtime.GOOS == "windows" && runtime.GOARCH == "arm",
49 runtime.GOOS == "openbsd",
50 runtime.GOOS == "aix":
51 return errors.New("FIPS 140-3 mode is not supported on " + runtime.GOOS + "-" + runtime.GOARCH)
52 }
53
54 if boringEnabled {
55 return errors.New("FIPS 140-3 mode is incompatible with GOEXPERIMENT=boringcrypto")
56 }
57
58 return nil
59 }
60
61 func Name() string {
62 return "Go Cryptographic Module"
63 }
64
65 func Version() string {
66 return "v1.0"
67 }
68
View as plain text