-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
donutnomad
committed
Oct 16, 2024
1 parent
8d05387
commit f3d2c54
Showing
9 changed files
with
97 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= | ||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= | ||
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI= | ||
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0= | ||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= | ||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= | ||
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.3 h1:l/lhv2aJCUignzls81+wvga0TFlyoZx8QxRMQgXpZik= | ||
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.3/go.mod h1:AKpV6+wZ2MfPRJnTbQ6NPgWrKzbe9RCIlCF/FKzMtM8= | ||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg= | ||
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/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= | ||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= | ||
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= | ||
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
package xcurve25519 | ||
|
||
import "github.com/donutnomad/blockchain-alg/xed25519" | ||
|
||
func UniformSignature(pubEndByte byte, signature [64]byte) Signature { | ||
signature[63] &= 127 /*bbbbbbbb & 01111111 ==> clear first byte*/ | ||
signature[63] |= pubEndByte & 128 /*endByte & 10000000 ==> keep the first byte when it is 0*/ | ||
return signature | ||
} | ||
|
||
func ConvertEd25519PubKeyAndSig(pub xed25519.PublicKey, sig [64]byte) (pubCurve25519 PublicKey, _ Signature) { | ||
return pub.ToEd25519(), UniformSignature(pub[len(pub)-1], sig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package xed25519 | ||
|
||
import ( | ||
"errors" | ||
"github.com/decred/dcrd/dcrec/edwards/v2" | ||
"github.com/donutnomad/blockchain-alg/xasn1" | ||
) | ||
|
||
var BadFormatPublicKeyErr = errors.New("bad format") | ||
|
||
type PublicKey [32]byte | ||
|
||
// ToCurve25519 Ed25519's PublicKey to Curve25519 | ||
func (pub PublicKey) ToCurve25519() (PublicKey, error) { | ||
return edwardsToMontgomery(pub) | ||
} | ||
|
||
// ToEd25519 Curve25519's PublicKey to Ed25519 | ||
func (pub PublicKey) ToEd25519() (out PublicKey) { | ||
res := montgomeryToEdwards(pub) | ||
copy(out[:], res) | ||
return out | ||
} | ||
|
||
// ToEd25519WithSig Curve25519's PublicKey to Ed25519 with last signature byte | ||
func (pub PublicKey) ToEd25519WithSig(sigEndByte byte) PublicKey { | ||
res := pub.ToEd25519() | ||
res[31] &= 127 | ||
res[31] |= sigEndByte & 128 | ||
return res | ||
} | ||
|
||
func ParsePubKey(serialized [32]byte) (key PublicKey, err error) { | ||
pubKey, err := edwards.ParsePubKey(serialized[:]) | ||
if err != nil { | ||
return PublicKey{}, err | ||
} | ||
return PublicKey(pubKey.Serialize()), nil | ||
} | ||
|
||
func ParsePubKeyASN1(bs []byte) (key PublicKey, err error) { | ||
serialized, err := xasn1.ParsePKIXPublicKey(bs) | ||
if err != nil { | ||
return PublicKey{}, err | ||
} | ||
if len(serialized) != 32 { | ||
return PublicKey{}, BadFormatPublicKeyErr | ||
} | ||
return ParsePubKey([32]byte(serialized)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.