@@ -63,11 +63,22 @@ func hashFuncToMD(fn func() hash.Hash) (ossl.EVP_MD_PTR, error) {
63
63
return md , nil
64
64
}
65
65
66
+ // provider is an identifier for a known provider.
67
+ type provider uint8
68
+
69
+ const (
70
+ providerNone provider = iota
71
+ providerOSSLDefault
72
+ providerOSSLFIPS
73
+ providerSymCrypt
74
+ )
75
+
66
76
type hashAlgorithm struct {
67
77
md ossl.EVP_MD_PTR
68
78
ch crypto.Hash
69
79
size int
70
80
blockSize int
81
+ provider provider
71
82
marshallable bool
72
83
magic string
73
84
marshalledSize int
@@ -87,14 +98,14 @@ func loadHash(ch crypto.Hash) *hashAlgorithm {
87
98
hash .md = ossl .EVP_md4 ()
88
99
case crypto .MD5 :
89
100
hash .md = ossl .EVP_md5 ()
90
- hash .magic = md5Magic
91
- hash .marshalledSize = md5MarshaledSize
101
+ hash .magic = magicMD5
102
+ hash .marshalledSize = marshaledSizeMD5
92
103
case crypto .MD5SHA1 :
93
104
hash .md = ossl .EVP_md5_sha1 ()
94
105
case crypto .SHA1 :
95
106
hash .md = ossl .EVP_sha1 ()
96
- hash .magic = sha1Magic
97
- hash .marshalledSize = sha1MarshaledSize
107
+ hash .magic = magic1
108
+ hash .marshalledSize = marshaledSize1
98
109
case crypto .SHA224 :
99
110
hash .md = ossl .EVP_sha224 ()
100
111
hash .magic = magic224
@@ -159,7 +170,34 @@ func loadHash(ch crypto.Hash) *hashAlgorithm {
159
170
hash .md = md
160
171
}
161
172
}
162
- hash .marshallable = hash .magic != "" && isHashMarshallable (hash .md )
173
+ if hash .magic != "" {
174
+ if hash .marshalledSize == 0 {
175
+ panic ("marshalledSize must be set for " + hash .magic )
176
+ }
177
+ }
178
+
179
+ switch vMajor {
180
+ case 1 :
181
+ hash .provider = providerOSSLDefault
182
+ case 3 :
183
+ if prov := ossl .EVP_MD_get0_provider (hash .md ); prov != nil {
184
+ cname := ossl .OSSL_PROVIDER_get0_name (prov )
185
+ switch C .GoString ((* C .char )(unsafe .Pointer (cname ))) {
186
+ case "default" :
187
+ hash .provider = providerOSSLDefault
188
+ hash .marshallable = hash .magic != ""
189
+ case "fips" :
190
+ hash .provider = providerOSSLFIPS
191
+ hash .marshallable = hash .magic != ""
192
+ case "symcryptprovider" :
193
+ hash .provider = providerSymCrypt
194
+ hash .marshallable = hash .magic != "" && isSymCryptHashStateSerializable (hash .md )
195
+ }
196
+ }
197
+ default :
198
+ panic (errUnsupportedVersion ())
199
+ }
200
+
163
201
cacheMD .Store (ch , & hash )
164
202
return & hash
165
203
}
0 commit comments