diff --git a/cng/hkdf.go b/cng/hkdf.go index 20bcc79..2647c6b 100644 --- a/cng/hkdf.go +++ b/cng/hkdf.go @@ -7,7 +7,6 @@ package cng import ( - "encoding/binary" "errors" "hash" "runtime" @@ -83,7 +82,7 @@ func ExtractHKDF(h func() hash.Hash, secret, salt []byte) ([]byte, error) { if len(blob) < 4 { return nil, errors.New("cng: exported key is corrupted") } - cbHashName := binary.BigEndian.Uint32(blob) + cbHashName := bigEndianUint32(blob) blob = blob[4:] if len(blob) < int(cbHashName) { return nil, errors.New("cng: exported key is corrupted") @@ -122,3 +121,8 @@ func ExpandHKDF(h func() hash.Hash, pseudorandomKey, info []byte, keyLength int) } return out, err } + +func bigEndianUint32(b []byte) uint32 { + _ = b[3] // bounds check hint to compiler; see golang.org/issue/14808 + return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24 +}