本文整理汇总了Golang中github.com/yahoo/coname/ed25519/edwards25519.ExtendedGroupElement.FromBytes方法的典型用法代码示例。如果您正苦于以下问题:Golang ExtendedGroupElement.FromBytes方法的具体用法?Golang ExtendedGroupElement.FromBytes怎么用?Golang ExtendedGroupElement.FromBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/yahoo/coname/ed25519/edwards25519.ExtendedGroupElement
的用法示例。
在下文中一共展示了ExtendedGroupElement.FromBytes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Verify
// Verify returns true iff sig is a valid signature of message by publicKey.
func Verify(publicKey *[PublicKeySize]byte, message []byte, sig *[SignatureSize]byte) bool {
if sig[63]&224 != 0 {
return false
}
var A edwards25519.ExtendedGroupElement
if !A.FromBytes(publicKey) {
return false
}
edwards25519.FeNeg(&A.X, &A.X)
edwards25519.FeNeg(&A.T, &A.T)
h := sha512.New()
h.Write(sig[:32])
h.Write(publicKey[:])
h.Write(message)
var digest [64]byte
h.Sum(digest[:0])
var hReduced [32]byte
edwards25519.ScReduce(&hReduced, &digest)
var R edwards25519.ProjectiveGroupElement
var b [32]byte
copy(b[:], sig[32:])
edwards25519.GeDoubleScalarMultVartime(&R, &hReduced, &A, &b)
var checkR [32]byte
R.ToBytes(&checkR)
return subtle.ConstantTimeCompare(sig[:32], checkR[:]) == 1
}
示例2: PublicKeyToCurve25519
// PublicKeyToCurve25519 converts an Ed25519 public key into the curve25519
// public key that would be generated from the same private key.
func PublicKeyToCurve25519(curve25519Public *[32]byte, publicKey *[32]byte) bool {
var A edwards25519.ExtendedGroupElement
if !A.FromBytes(publicKey) {
return false
}
// A.Z = 1 as a postcondition of FromBytes.
var x edwards25519.FieldElement
edwardsToMontgomeryX(&x, &A.Y)
edwards25519.FeToBytes(curve25519Public, &x)
return true
}
示例3: TestUnmarshalMarshal
func TestUnmarshalMarshal(t *testing.T) {
pk, _, _ := GenerateKey(rand.Reader)
var A edwards25519.ExtendedGroupElement
ret := A.FromBytes(pk)
var pk2 [32]byte
A.ToBytes(&pk2)
if *pk != pk2 {
_ = ret
t.Errorf("FromBytes(%v)->ToBytes not idempotent:\n%x\nbytes:\n\t%x\n\t%x\ndelta: %x\n", ret, A, *pk, pk2, int(pk[31])-int(pk2[31]))
}
}
示例4: TestUnmarshalMarshalNegative
func TestUnmarshalMarshalNegative(t *testing.T) {
pk, _, _ := GenerateKey(rand.Reader)
var A edwards25519.ExtendedGroupElement
ret := A.FromBytes(pk)
var pk2 [32]byte
A.ToBytes(&pk2)
pk2[31] ^= 0x80
if *pk == pk2 {
t.Errorf("FromBytes(%v)->flipping sign did not change public key:\n%x\nbytes:\n\t%x\n\t%x\ndelta: %x\n", ret, A, *pk, pk2, int(pk[31])-int(pk2[31]))
}
}