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