From e143f1bbc5acb006e8672171eb1b2bf70486b8aa Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sat, 19 Jan 2019 01:24:21 +0300 Subject: [PATCH] Fix bug with a possible race when running with multiple jobs That could easily lead to different results each time. --- balloon.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/balloon.go b/balloon.go index f0d8390..8e753de 100644 --- a/balloon.go +++ b/balloon.go @@ -141,9 +141,10 @@ func H(hasher func() hash.Hash, passwd, salt []byte, sCost, tCost int, jobs int) results := make(chan []byte) for ; i < jobs; i++ { go func(i int) { - saltBuf := make([]byte, 8) - binary.BigEndian.PutUint64(saltBuf, uint64(i)) - results <- B(hasher(), passwd, append(salt, saltBuf...), sCost, tCost) + saltBuf := make([]byte, len(salt)+8) + copy(saltBuf, salt) + binary.BigEndian.PutUint64(saltBuf[len(salt):], uint64(i)) + results <- B(hasher(), passwd, saltBuf, uint64(sCost), uint64(tCost)) }(i) } h := hasher() -- 2.44.0