Created
June 21, 2016 08:49
-
-
Save fwessels/02cb94777817f69798dec002cb5d6363 to your computer and use it in GitHub Desktop.
blake512 computation using codahale lib (SSE-optimized)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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