Skip to content

Commit 97653fc

Browse files
authored
Merge pull request #90 from microsoft/removeenc
Don't use encoding/binary
2 parents f49c8e1 + f5d58a7 commit 97653fc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cng/hkdf.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package cng
88

99
import (
10-
"encoding/binary"
1110
"errors"
1211
"hash"
1312
"runtime"
@@ -83,7 +82,7 @@ func ExtractHKDF(h func() hash.Hash, secret, salt []byte) ([]byte, error) {
8382
if len(blob) < 4 {
8483
return nil, errors.New("cng: exported key is corrupted")
8584
}
86-
cbHashName := binary.BigEndian.Uint32(blob)
85+
cbHashName := bigEndianUint32(blob)
8786
blob = blob[4:]
8887
if len(blob) < int(cbHashName) {
8988
return nil, errors.New("cng: exported key is corrupted")
@@ -122,3 +121,8 @@ func ExpandHKDF(h func() hash.Hash, pseudorandomKey, info []byte, keyLength int)
122121
}
123122
return out, err
124123
}
124+
125+
func bigEndianUint32(b []byte) uint32 {
126+
_ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
127+
return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
128+
}

0 commit comments

Comments
 (0)