codahale / blake2 Goto Github PK
View Code? Open in Web Editor NEWA BLAKE2 wrapper for Go.
License: MIT License
A BLAKE2 wrapper for Go.
License: MIT License
It looks like digest.Sum modifies its internal state:
https://github.com/codahale/blake2/blob/3fa823583a/blake2b.go#L153
C.blake2b_final(d.state, (*C.uint8_t)(&digest[0]), C.uint8_t(d.Size()))
The contract for hash.Hash.Sum prohibits this:
https://godoc.org/hash#Hash.Sum
Sum appends the current hash to b and returns the resulting slice.
It does not change the underlying hash state.
The user should be able to get the sum, then continue writing, then get another sum, etc. Other crypto hash implementations with this problem (where computing the sum is destructive) conform to this requirement by copying the internal state before summing. For example,
https://github.com/golang/go/blob/53c92f95a8/src/crypto/sha256/sha256.go#L129-L130
and
https://github.com/golang/crypto/blob/aedad9a179/sha3/sha3.go#L187-L189
The allocation is unfortunate, but necessary.
I'm pretty sure this could be fixed the same way in this package. Looks like blake2b_state has no internal pointers so it should be safe to copy. Maybe like:
unc (d *digest) Sum(buf []byte) []byte {
digest := make([]byte, d.Size())
// Make a copy of d.state so that caller can keep writing and summing.
s := *d.state
C.blake2b_final(&s, (*C.uint8_t)(&digest[0]), C.uint8_t(d.Size()))
return append(buf, digest...)
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.