
Since I turned out to be implementing parts of Noise which I did not need to implement, I'm taking a different approach, and doing an unmodified Noise transport first and then making our modifications to it. That should reduce what I need to do to message pre-processing mostly, I think.
28 lines
487 B
Go
28 lines
487 B
Go
package data
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"io"
|
|
)
|
|
|
|
// sha256 hash of some data
|
|
type Hash [32]byte
|
|
|
|
// calculate sha256 of a byte slice
|
|
func HashData(data []byte) (h Hash) {
|
|
h = sha256.Sum256(data)
|
|
return
|
|
}
|
|
|
|
// calulate sha256 of all data being read from an io.Reader
|
|
// return error if one occurs while reading from reader
|
|
func HashReader(r io.Reader) (h Hash, err error) {
|
|
sha := sha256.New()
|
|
_, err = io.Copy(sha, r)
|
|
if err == nil {
|
|
d := sha.Sum(nil)
|
|
copy(h[:], d)
|
|
}
|
|
return
|
|
}
|