@@ -105,6 +105,16 @@ func symCryptUnmarshalBinary(d []byte, chain, buffer []byte) _UINT64 {
105
105
return newUINT64 (length )
106
106
}
107
107
108
+ // swapEndianessInt32 swaps the endianness of the given byte slice
109
+ // in place. It assumes the slice is a backup of a 32-bit integer array.
110
+ func swapEndianessInt32 (d []uint8 ) {
111
+ for i := 0 ; i < len (d ); i += 4 {
112
+ d [i ], d [i + 3 ] = d [i + 3 ], d [i ]
113
+ d [i + 1 ], d [i + 2 ] = d [i + 2 ], d [i + 1 ]
114
+ }
115
+
116
+ }
117
+
108
118
type _SYMCRYPT_MD5_STATE_EXPORT_BLOB struct {
109
119
header _SYMCRYPT_BLOB_HEADER
110
120
chain [16 ]uint8 // little endian
@@ -117,21 +127,13 @@ type _SYMCRYPT_MD5_STATE_EXPORT_BLOB struct {
117
127
func (b * _SYMCRYPT_MD5_STATE_EXPORT_BLOB ) appendBinary (d []byte ) ([]byte , error ) {
118
128
// b.chain is little endian, but Go expects big endian,
119
129
// we need to swap the bytes.
120
- for i := 0 ; i < len (b .chain ); i += 4 {
121
- b .chain [i ], b .chain [i + 3 ] = b .chain [i + 3 ], b .chain [i ]
122
- b .chain [i + 1 ], b .chain [i + 2 ] = b .chain [i + 2 ], b .chain [i + 1 ]
123
- }
130
+ swapEndianessInt32 (b .chain [:])
124
131
return symCryptAppendBinary (d , b .chain [:], b .buffer [:], b .length ), nil
125
132
}
126
133
127
134
func (b * _SYMCRYPT_MD5_STATE_EXPORT_BLOB ) unmarshalBinary (d []byte ) {
128
135
b .length = symCryptUnmarshalBinary (d , b .chain [:], b .buffer [:])
129
- // b.chain should be little endian, but Go uses big endian,
130
- // we need to swap the bytes.
131
- for i := 0 ; i < len (b .chain ); i += 4 {
132
- b .chain [i ], b .chain [i + 3 ] = b .chain [i + 3 ], b .chain [i ]
133
- b .chain [i + 1 ], b .chain [i + 2 ] = b .chain [i + 2 ], b .chain [i + 1 ]
134
- }
136
+ swapEndianessInt32 (b .chain [:])
135
137
}
136
138
137
139
type _SYMCRYPT_SHA1_STATE_EXPORT_BLOB struct {
@@ -283,12 +285,8 @@ func symCryptHashUnmarshalBinary(ctx ossl.EVP_MD_CTX_PTR, ch crypto.Hash, magic
283
285
if err != nil {
284
286
return err
285
287
}
286
- if _ , err := ossl .EVP_MD_CTX_set_params (ctx , params ); err != nil {
287
- // Old versions of SCOSSL don't support SCOSSL_DIGEST_PARAM_STATE
288
- // nor _SCOSSL_DIGEST_PARAM_RECOMPUTE_CHECKSUM.
289
- return errHashNotMarshallable
290
- }
291
- return nil
288
+ _ , err = ossl .EVP_MD_CTX_set_params (ctx , params )
289
+ return err
292
290
}
293
291
294
292
func symCryptHashStateInfo (ch crypto.Hash ) (size , typ uint32 , serializable bool ) {
0 commit comments