Merge pull request #13 from nspcc-dev/fix/cpuid

Detect CPU features in Sum()
This commit is contained in:
Evgeniy Kulikov 2019-10-04 18:00:24 +03:00 committed by GitHub
commit 06362477ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -70,9 +70,19 @@ func New() hash.Hash {
// Sum returns Tillich-Zémor checksum of data. // Sum returns Tillich-Zémor checksum of data.
func Sum(data []byte) [hashSize]byte { func Sum(data []byte) [hashSize]byte {
if hasAVX2 {
d := newAVX2Inline() d := newAVX2Inline()
_, _ = d.Write(data) // no errors _, _ = d.Write(data) // no errors
return d.checkSum() return d.checkSum()
} else if hasAVX {
d := newAVX()
_, _ = d.Write(data) // no errors
return d.checkSum()
} else {
d := newPure()
_, _ = d.Write(data) // no errors
return d.checkSum()
}
} }
// Concat performs combining of hashes based on homomorphic property. // Concat performs combining of hashes based on homomorphic property.