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 if puregoEnabled {
38 return errors.New("FIPS 140-3 mode is incompatible with the purego build tag")
39 }
40
41
42
43
44
45
46 if asanEnabled {
47 return errors.New("FIPS 140-3 mode is incompatible with ASAN")
48 }
49
50
51
52
53 switch {
54 case runtime.GOARCH == "wasm",
55 runtime.GOOS == "windows" && runtime.GOARCH == "386",
56 runtime.GOOS == "openbsd",
57 runtime.GOOS == "aix":
58 return errors.New("FIPS 140-3 mode is not supported on " + runtime.GOOS + "-" + runtime.GOARCH)
59 }
60
61 if boringEnabled {
62 return errors.New("FIPS 140-3 mode is incompatible with GOEXPERIMENT=boringcrypto")
63 }
64
65 return nil
66 }
67
68 func Name() string {
69 return "Go Cryptographic Module"
70 }
71
72
73
74 func Version() string {
75
76
77 return "latest"
78 }
79
View as plain text