Source File
ed25519.go
Belonging Package
crypto/ed25519
package ed25519
import (
cryptorand
)
SeedSize = 32
)
type PrivateKey []byte
func ( PrivateKey) () crypto.PublicKey {
:= make([]byte, PublicKeySize)
copy(, [32:])
return PublicKey()
}
func ( PrivateKey) ( crypto.PrivateKey) bool {
, := .(PrivateKey)
if ! {
return false
}
return bytes.Equal(, )
}
:= make([]byte, PrivateKeySize)
newKeyFromSeed(, )
return
}
func (, []byte) {
if := len(); != SeedSize {
panic("ed25519: bad seed length: " + strconv.Itoa())
}
:= sha512.Sum512()
[0] &= 248
[31] &= 127
[31] |= 64
var edwards25519.ExtendedGroupElement
var [32]byte
copy([:], [:])
edwards25519.GeScalarMultBase(&, &)
var [32]byte
.ToBytes(&)
copy(, )
copy([32:], [:])
}
:= make([]byte, SignatureSize)
sign(, , )
return
}
func (, , []byte) {
if := len(); != PrivateKeySize {
panic("ed25519: bad private key length: " + strconv.Itoa())
}
:= sha512.New()
.Write([:32])
var , , [64]byte
var [32]byte
.Sum([:0])
copy([:], [:])
[0] &= 248
[31] &= 63
[31] |= 64
.Reset()
.Write([32:])
.Write()
.Sum([:0])
var [32]byte
edwards25519.ScReduce(&, &)
var edwards25519.ExtendedGroupElement
edwards25519.GeScalarMultBase(&, &)
var [32]byte
.ToBytes(&)
.Reset()
.Write([:])
.Write([32:])
.Write()
.Sum([:0])
var [32]byte
edwards25519.ScReduce(&, &)
var [32]byte
edwards25519.ScMulAdd(&, &, &, &)
copy([:], [:])
copy([32:], [:])
}
func ( PublicKey, , []byte) bool {
if := len(); != PublicKeySize {
panic("ed25519: bad public key length: " + strconv.Itoa())
}
if len() != SignatureSize || [63]&224 != 0 {
return false
}
var edwards25519.ExtendedGroupElement
var [32]byte
copy([:], )
if !.FromBytes(&) {
return false
}
edwards25519.FeNeg(&.X, &.X)
edwards25519.FeNeg(&.T, &.T)
:= sha512.New()
.Write([:32])
.Write([:])
.Write()
var [64]byte
.Sum([:0])
var [32]byte
edwards25519.ScReduce(&, &)
var edwards25519.ProjectiveGroupElement
var [32]byte
copy([:], [32:])
if !edwards25519.ScMinimal(&) {
return false
}
edwards25519.GeDoubleScalarMultVartime(&, &, &, &)
var [32]byte
.ToBytes(&)
return bytes.Equal([:32], [:])
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |