Archived
1
0
This repository has been archived on 2023-08-12. You can view files and clone it, but cannot push or open issues or pull requests.
nntpchan/contrib/backends/srndv2/src/srnd/cryptography.go

47 lines
884 B
Go
Raw Normal View History

// +build !libsodium
package srnd
import (
"crypto/sha512"
"golang.org/x/crypto/curve25519"
"golang.org/x/crypto/ed25519"
)
func naclCryptoVerifyFucky(h, sig, pk []byte) bool {
pub := make(ed25519.PublicKey, ed25519.PublicKeySize)
copy(pub, pk)
return ed25519.Verify(pub, h, sig)
}
func naclCryptoSignFucky(hash, sk []byte) []byte {
sec := make(ed25519.PrivateKey, ed25519.PrivateKeySize)
copy(sec, sk)
return ed25519.Sign(sec, hash)
}
func naclSeedToKeyPair(seed []byte) (pk, sk []byte) {
h := sha512.Sum512(seed)
sk = h[:]
sk[0] &= 248
2017-08-26 19:48:47 +05:00
sk[31] &= 127
sk[31] |= 64
// scalarmult magick shit
pk = scalarBaseMult(sk)
copy(sk[0:32], seed[0:32])
copy(sk[32:64], pk[0:32])
return
}
func scalarBaseMult(sk []byte) (pk []byte) {
var skey [32]byte
var pkey [32]byte
copy(skey[0:32], sk[0:32])
curve25519.ScalarBaseMult(&pkey, &skey)
pk = pkey[0:32]
return
}