Skip to content

Instantly share code, notes, and snippets.

@fwessels
Created June 21, 2016 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fwessels/02cb94777817f69798dec002cb5d6363 to your computer and use it in GitHub Desktop.
Save fwessels/02cb94777817f69798dec002cb5d6363 to your computer and use it in GitHub Desktop.
blake512 computation using codahale lib (SSE-optimized)
package main
import (
"fmt"
"github.com/codahale/blake2"
"io"
"os"
)
func calcStream(r io.Reader) {
leafSize := uint(5 * 1024 * 1024)
h := blake2.NewBlake2B()
for part, totalSize := 0, int64(0); ; part++ {
partBuffer := make([]byte, leafSize)
n, err := r.Read(partBuffer)
if err != nil {
return
}
partBuffer = partBuffer[:n]
h.Write(partBuffer)
totalSize += int64(n)
lastChunk := uint(n) < leafSize
if lastChunk {
break
}
}
d := h.Sum(nil)
fmt.Printf("%X", d)
fmt.Println()
}
func main() {
calcStream(os.Stdin)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment