Skip to content

Commit

Permalink
fix: fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
donutnomad committed Oct 16, 2024
1 parent f3d2c54 commit 555ec4a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.3
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
github.com/samber/lo v1.47.0
golang.org/x/crypto v0.28.0
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnN
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
26 changes: 26 additions & 0 deletions xasn1/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import (
"crypto/x509/pkix"
"encoding/asn1"
"errors"
"golang.org/x/crypto/cryptobyte"
asn11 "golang.org/x/crypto/cryptobyte/asn1"
"math"
"math/big"
)

// ParseBase128Int parses a base-128 encoded int from the given offset in the
Expand Down Expand Up @@ -96,3 +99,26 @@ func ParsePKIXPublicKey(bs []byte) ([]byte, error) {
}
return pki.PublicKey.Bytes, nil
}

func ParseSignatureRS(bs []byte) (r *big.Int, s *big.Int, _ error) {
var inner cryptobyte.String
input := cryptobyte.String(bs)
if !input.ReadASN1(&inner, asn11.SEQUENCE) ||
!input.Empty() ||
!inner.ReadASN1Integer(&r) ||
!inner.ReadASN1Integer(&s) ||
!inner.Empty() {
return nil, nil, errors.New("invalid ASN.1")
}
return r, s, nil
}

func ParseSignatureRSSlice(bs []byte) (out [64]byte, _ error) {
r, s, err := ParseSignatureRS(bs)
if err != nil {
return [64]byte{}, err
}
r.FillBytes(out[0:32])
s.FillBytes(out[32:64])
return out, nil
}
8 changes: 6 additions & 2 deletions xcurve25519/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ func UniformSignature(pubEndByte byte, signature [64]byte) Signature {
return signature
}

func ConvertEd25519PubKeyAndSig(pub xed25519.PublicKey, sig [64]byte) (pubCurve25519 PublicKey, _ Signature) {
return pub.ToEd25519(), UniformSignature(pub[len(pub)-1], sig)
func ConvertEd25519PubKeyAndSig(pub xed25519.PublicKey, sig [64]byte) (pubCurve25519 PublicKey, _ Signature, _ error) {
out, err := pub.ToCurve25519()
if err != nil {
return [32]byte{}, [64]byte{}, err
}
return out, UniformSignature(pub[len(pub)-1], sig), nil
}

0 comments on commit 555ec4a

Please sign in to comment.