mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
ecies: Append hash.Sum to k directly
This commit is contained in:
parent
830d1382f1
commit
c863c9749e
1 changed files with 5 additions and 7 deletions
|
|
@ -145,17 +145,15 @@ var (
|
||||||
|
|
||||||
// NIST SP 800-56 Concatenation Key Derivation Function (see section 5.8.1).
|
// NIST SP 800-56 Concatenation Key Derivation Function (see section 5.8.1).
|
||||||
func concatKDF(hash hash.Hash, z, s1 []byte, kdLen int) []byte {
|
func concatKDF(hash hash.Hash, z, s1 []byte, kdLen int) []byte {
|
||||||
counter := []byte{0, 0, 0, 1}
|
counterBytes := make([]byte, 4)
|
||||||
k := make([]byte, 0, kdLen+hash.Size())
|
k := make([]byte, 0, kdLen+hash.Size())
|
||||||
for len(k) < kdLen {
|
for counter := uint32(1); len(k) < kdLen; counter++ {
|
||||||
hash.Reset()
|
hash.Reset()
|
||||||
hash.Write(counter)
|
binary.BigEndian.PutUint32(counterBytes, counter)
|
||||||
|
hash.Write(counterBytes)
|
||||||
hash.Write(z)
|
hash.Write(z)
|
||||||
hash.Write(s1)
|
hash.Write(s1)
|
||||||
k = k[:len(k)+hash.Size()]
|
k = hash.Sum(k)
|
||||||
hash.Sum(k[:len(k)-hash.Size()])
|
|
||||||
// increment counter
|
|
||||||
binary.BigEndian.PutUint32(counter, binary.BigEndian.Uint32(counter)+1)
|
|
||||||
}
|
}
|
||||||
return k[:kdLen]
|
return k[:kdLen]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue