]> Cypherpunks.ru repositories - balloon.git/commitdiff
Fix bug with a possible race when running with multiple jobs
authorSergey Matveev <stargrave@stargrave.org>
Fri, 18 Jan 2019 22:24:21 +0000 (01:24 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 18 Jan 2019 22:24:23 +0000 (01:24 +0300)
That could easily lead to different results each time.

balloon.go

index f0d8390f75790687e55dc2a24d36a8768668c876..8e753dee0762da41161c991fb82c487a96ac342b 100644 (file)
@@ -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()