Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cng/hkdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package cng

import (
"encoding/binary"
"errors"
"hash"
"runtime"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}