ipld-eth-server/vendor/github.com/libp2p/go-libp2p-pnet/fingerprint.go
Elizabeth Engelman 36533f7c3f Update vendor directory and make necessary code changes
Fixes for new geth version
2019-09-25 16:32:27 -05:00

25 lines
651 B
Go

package pnet
import (
"golang.org/x/crypto/salsa20"
"golang.org/x/crypto/sha3"
)
var zero64 = make([]byte, 64)
func fingerprint(psk *[32]byte) []byte {
enc := make([]byte, 64)
// We encrypt data first so we don't feed PSK to hash function.
// Salsa20 function is not reversible thus increasing our security margin.
salsa20.XORKeyStream(enc, zero64, []byte("finprint"), psk)
out := make([]byte, 16)
// Then do Shake-128 hash to reduce its length.
// This way if for some reason Shake is broken and Salsa20 preimage is possible,
// attacker has only half of the bytes necessary to recreate psk.
sha3.ShakeSum128(out, enc)
return out
}