@@ -106,9 +106,9 @@ func symCryptUnmarshalBinary(d []byte, chain, buffer []byte) _UINT64 {
106
106
return newUINT64 (length )
107
107
}
108
108
109
- // swapEndianessInt32 swaps the endianness of the given byte slice
109
+ // swapEndianessUint32 swaps the endianness of the given byte slice
110
110
// in place. It assumes the slice is a backup of a 32-bit integer array.
111
- func swapEndianessInt32 (d []uint8 ) {
111
+ func swapEndianessUint32 (d []uint8 ) {
112
112
for i := 0 ; i < len (d ); i += 4 {
113
113
d [i ], d [i + 3 ] = d [i + 3 ], d [i ]
114
114
d [i + 1 ], d [i + 2 ] = d [i + 2 ], d [i + 1 ]
@@ -128,13 +128,13 @@ type _SYMCRYPT_MD5_STATE_EXPORT_BLOB struct {
128
128
func (b * _SYMCRYPT_MD5_STATE_EXPORT_BLOB ) appendBinary (d []byte ) ([]byte , error ) {
129
129
// b.chain is little endian, but Go expects big endian,
130
130
// we need to swap the bytes.
131
- swapEndianessInt32 (b .chain [:])
131
+ swapEndianessUint32 (b .chain [:])
132
132
return symCryptAppendBinary (d , b .chain [:], b .buffer [:], b .length ), nil
133
133
}
134
134
135
135
func (b * _SYMCRYPT_MD5_STATE_EXPORT_BLOB ) unmarshalBinary (d []byte ) {
136
136
b .length = symCryptUnmarshalBinary (d , b .chain [:], b .buffer [:])
137
- swapEndianessInt32 (b .chain [:])
137
+ swapEndianessUint32 (b .chain [:])
138
138
}
139
139
140
140
type _SYMCRYPT_SHA1_STATE_EXPORT_BLOB struct {
@@ -208,6 +208,9 @@ func symCryptHashAppendBinary(ctx C.GO_EVP_MD_CTX_PTR, ch crypto.Hash, magic str
208
208
if C .go_openssl_EVP_MD_CTX_get_params (ctx , (C .GO_OSSL_PARAM_PTR )(unsafe .Pointer (& params [0 ]))) != 1 {
209
209
return nil , newOpenSSLError ("EVP_MD_CTX_get_params" )
210
210
}
211
+ if ! _OSSL_PARAM_modified (& params [0 ]) {
212
+ return nil , errors .New ("EVP_MD_CTX_get_params did not retrieve the state" )
213
+ }
211
214
212
215
header := (* _SYMCRYPT_BLOB_HEADER )(unsafe .Pointer (& state [0 ]))
213
216
if header .magic != _SYMCRYPT_BLOB_MAGIC {
@@ -275,21 +278,17 @@ func symCryptHashUnmarshalBinary(ctx C.GO_EVP_MD_CTX_PTR, ch crypto.Hash, magic
275
278
default :
276
279
panic ("unsupported hash " + ch .String ())
277
280
}
278
- bld := C .go_openssl_OSSL_PARAM_BLD_new ()
279
- if bld == nil {
280
- return newOpenSSLError ("OSSL_PARAM_BLD_new" )
281
- }
282
- defer C .go_openssl_OSSL_PARAM_BLD_free (bld )
283
- cbytes := C .CBytes (unsafe .Slice ((* byte )(blobPtr ), hdr .size ))
284
- defer C .free (cbytes )
285
- C .go_openssl_OSSL_PARAM_BLD_push_octet_string (bld , _SCOSSL_DIGEST_PARAM_STATE , cbytes , C .size_t (hdr .size ))
286
- C .go_openssl_OSSL_PARAM_BLD_push_int32 (bld , _SCOSSL_DIGEST_PARAM_RECOMPUTE_CHECKSUM , 1 )
287
- params := C .go_openssl_OSSL_PARAM_BLD_to_param (bld )
288
- if params == nil {
289
- return newOpenSSLError ("OSSL_PARAM_BLD_to_param" )
281
+ var checksum int32 = 1
282
+ cbytesBlob := C .CBytes (unsafe .Slice ((* byte )(blobPtr ), hdr .size ))
283
+ defer C .free (cbytesBlob )
284
+ cbytesCheksum := C .CBytes (unsafe .Slice ((* byte )(unsafe .Pointer (& checksum )), 4 ))
285
+ defer C .free (cbytesCheksum )
286
+ params := [3 ]_OSSL_PARAM {
287
+ _OSSL_PARAM_construct_octet_string (_SCOSSL_DIGEST_PARAM_STATE , cbytesBlob , int (hdr .size )),
288
+ _OSSL_PARAM_construct_int32 (_SCOSSL_DIGEST_PARAM_RECOMPUTE_CHECKSUM , (* int32 )(cbytesCheksum )),
289
+ _OSSL_PARAM_construct_end (),
290
290
}
291
- defer C .go_openssl_OSSL_PARAM_free (params )
292
- if C .go_openssl_EVP_MD_CTX_set_params (ctx , params ) == 0 {
291
+ if C .go_openssl_EVP_MD_CTX_set_params (ctx , (C .GO_OSSL_PARAM_PTR )(unsafe .Pointer (& params [0 ]))) != 1 {
293
292
return newOpenSSLError ("EVP_MD_CTX_set_params" )
294
293
}
295
294
return nil
0 commit comments