Browse Source

Update dependencies

node_auth
codesoap 5 months ago
parent
commit
add87f5807
  1. 5
      account.go
  2. 20
      ed25519.go
  3. 4
      go.mod
  4. 17
      go.sum

5
account.go

@ -46,7 +46,10 @@ func NewAccountFromAddress(address string) (a Account, err error) { @@ -46,7 +46,10 @@ func NewAccountFromAddress(address string) (a Account, err error) {
func derivePublicKey(privateKey *big.Int) *big.Int {
hashBytes := blake2b.Sum512(bigIntToBytes(privateKey, 32))
scalar := edwards25519.NewScalar().SetBytesWithClamping(hashBytes[:32])
scalar, err := edwards25519.NewScalar().SetBytesWithClamping(hashBytes[:32])
if err != nil {
panic(err)
}
publicKeyBytes := edwards25519.NewIdentityPoint().ScalarBaseMult(scalar).Bytes()
return big.NewInt(0).SetBytes(publicKeyBytes)
}

20
ed25519.go

@ -21,14 +21,20 @@ func sign(publicKey, privateKey *big.Int, msg []byte) ([]byte, error) { @@ -21,14 +21,20 @@ func sign(publicKey, privateKey *big.Int, msg []byte) ([]byte, error) {
var digest1, messageDigest, hramDigest [64]byte
h.Sum(digest1[:0])
s := new(edwards25519.Scalar).SetBytesWithClamping(digest1[:32])
s, err := new(edwards25519.Scalar).SetBytesWithClamping(digest1[:32])
if err != nil {
return signature, err
}
h.Reset()
h.Write(digest1[32:])
h.Write(msg)
h.Sum(messageDigest[:0])
rReduced := new(edwards25519.Scalar).SetUniformBytes(messageDigest[:])
rReduced, err := new(edwards25519.Scalar).SetUniformBytes(messageDigest[:])
if err != nil {
return signature, err
}
R := new(edwards25519.Point).ScalarBaseMult(rReduced)
encodedR := R.Bytes()
@ -39,7 +45,10 @@ func sign(publicKey, privateKey *big.Int, msg []byte) ([]byte, error) { @@ -39,7 +45,10 @@ func sign(publicKey, privateKey *big.Int, msg []byte) ([]byte, error) {
h.Write(msg)
h.Sum(hramDigest[:0])
kReduced := new(edwards25519.Scalar).SetUniformBytes(hramDigest[:])
kReduced, err := new(edwards25519.Scalar).SetUniformBytes(hramDigest[:])
if err != nil {
return signature, err
}
S := new(edwards25519.Scalar).MultiplyAdd(kReduced, s, rReduced)
copy(signature[:], encodedR[:])
@ -69,7 +78,10 @@ func isValidSignature(publicKey *big.Int, msg, sig []byte) bool { @@ -69,7 +78,10 @@ func isValidSignature(publicKey *big.Int, msg, sig []byte) bool {
h.Write(msg)
var digest [64]byte
h.Sum(digest[:0])
hReduced := new(edwards25519.Scalar).SetUniformBytes(digest[:])
hReduced, err := new(edwards25519.Scalar).SetUniformBytes(digest[:])
if err != nil {
return false
}
// ZIP215: this works because SetBytes does not check that encodings are canonical
checkR, err := new(edwards25519.Point).SetBytes(sig[:32])

4
go.mod

@ -3,6 +3,6 @@ module github.com/codesoap/atto @@ -3,6 +3,6 @@ module github.com/codesoap/atto
go 1.15
require (
filippo.io/edwards25519 v1.0.0-beta.3
golang.org/x/crypto v0.0.0-20210317152858-513c2a44f670
filippo.io/edwards25519 v1.0.0-rc.1
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce
)

17
go.sum

@ -1,11 +1,12 @@ @@ -1,11 +1,12 @@
filippo.io/edwards25519 v1.0.0-beta.3 h1:WQxB0FH5NzrhciInJ30bgL3soLng3AbdI651yQuVlCs=
filippo.io/edwards25519 v1.0.0-beta.3/go.mod h1:X+pm78QAUPtFLi1z9PYIlS/bdDnvbCOGKtZ+ACWEf7o=
golang.org/x/crypto v0.0.0-20210317152858-513c2a44f670 h1:gzMM0EjIYiRmJI3+jBdFuoynZlpxa2JQZsolKu09BXo=
golang.org/x/crypto v0.0.0-20210317152858-513c2a44f670/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmGfU=
filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce h1:Roh6XWxHFKrPgC/EQhVubSAGQ6Ozk6IdxHSzt1mR0EI=
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

Loading…
Cancel
Save