2022-11-01 11:22:00 +00:00
|
|
|
package crypto
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"git.gammaspectra.live/P2Pool/moneroutil"
|
|
|
|
)
|
|
|
|
|
2022-11-05 05:29:12 +00:00
|
|
|
func GetDerivationSharedDataForOutputIndex(derivation PublicKey, outputIndex uint64) PrivateKey {
|
2022-11-07 14:58:02 +00:00
|
|
|
var k = derivation.AsBytes()
|
|
|
|
var varIntBuf [binary.MaxVarintLen64]byte
|
|
|
|
return PrivateKeyFromScalar(HashToScalar(k[:], varIntBuf[:binary.PutUvarint(varIntBuf[:], outputIndex)]))
|
2022-11-01 11:22:00 +00:00
|
|
|
}
|
|
|
|
|
2022-11-05 05:29:12 +00:00
|
|
|
func GetDerivationViewTagForOutputIndex(derivation PublicKey, outputIndex uint64) uint8 {
|
2022-11-07 14:58:02 +00:00
|
|
|
var k = derivation.AsBytes()
|
|
|
|
var varIntBuf [binary.MaxVarintLen64]byte
|
|
|
|
h := moneroutil.Keccak256([]byte("view_tag"), k[:], varIntBuf[:binary.PutUvarint(varIntBuf[:], outputIndex)])
|
2022-11-01 11:22:00 +00:00
|
|
|
return h[0]
|
|
|
|
}
|
2022-11-06 06:57:36 +00:00
|
|
|
|
2022-11-07 14:58:02 +00:00
|
|
|
func GetDerivationSharedDataAndViewTagForOutputIndex(derivation PublicKey, outputIndex uint64) (PrivateKey, uint8) {
|
|
|
|
var k = derivation.AsBytes()
|
|
|
|
var varIntBuf [binary.MaxVarintLen64]byte
|
|
|
|
|
|
|
|
n := binary.PutUvarint(varIntBuf[:], outputIndex)
|
|
|
|
pK := PrivateKeyFromScalar(HashToScalar(k[:], varIntBuf[:n]))
|
|
|
|
h := moneroutil.Keccak256([]byte("view_tag"), k[:], varIntBuf[:n])
|
|
|
|
return pK, h[0]
|
|
|
|
}
|
|
|
|
|
2022-11-06 06:57:36 +00:00
|
|
|
func GetKeyImage(pair *KeyPair) PublicKey {
|
|
|
|
return PublicKeyFromPoint(HashToPoint(pair.PublicKey)).Multiply(pair.PrivateKey.AsScalar())
|
|
|
|
}
|