Skip to content

Commit

Permalink
Merge pull request #300 from getamis/fixCompressInput
Browse files Browse the repository at this point in the history
change the format of input for compressionPoint
  • Loading branch information
cychuang0924 authored Nov 29, 2024
2 parents a5674a1 + c1a8b42 commit 7bfdde6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions crypto/elliptic/ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ func (ed *ed25519) Slip10SeedList() []byte {
return []byte("ed25519 seed")
}

func (ed *ed25519) CompressedPoint(s *big.Int, isHash bool) []byte {
func (ed *ed25519) CompressedPoint(s []byte, isHash bool) []byte {
if isHash {
sha512 := sha512.New()
sha512.Write(s.Bytes()[:32])
sha512.Write(s)
h := sha512.Sum(nil)
return pubKeyRFC8032Compression(h[:32])
}
return pubKeyRFC8032Compression(s.Bytes()[:32])
return pubKeyRFC8032Compression(s)
}

func pubKeyRFC8032Compression(secret []byte) []byte {
Expand Down
2 changes: 1 addition & 1 deletion crypto/elliptic/ed25519_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var _ = Describe("ed25519", func() {
// Test vectors : https://asecuritysite.com/ecc/eddsa4
DescribeTable("Compressed Point", func(secrethex string, expected string, isHash bool) {
secret, _ := new(big.Int).SetString(secrethex, 16)
pubKey := Ed25519().CompressedPoint(secret, isHash)
pubKey := Ed25519().CompressedPoint(secret.Bytes(), isHash)
Expect(hex.EncodeToString(pubKey) == expected).Should(BeTrue())
},
Entry("case1:", "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60", "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a", true),
Expand Down
4 changes: 2 additions & 2 deletions crypto/elliptic/elliptic_curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (c *ellipticCurve) Neg(x, y *big.Int) (*big.Int, *big.Int) {
}

// WARN: Only support P256 and Secp256k1
func (c *ellipticCurve) CompressedPoint(s *big.Int, isHash bool) []byte {
func (c *ellipticCurve) CompressedPoint(s []byte, isHash bool) []byte {
if isHash {
panic("Not implemented")
}
Expand All @@ -40,7 +40,7 @@ func (c *ellipticCurve) CompressedPoint(s *big.Int, isHash bool) []byte {
Returns:
bytes: Compressed byte representation.
*/
x, y := c.ScalarBaseMult(s.Bytes())
x, y := c.ScalarBaseMult(s)
xBytePadding := x.Bytes()
if len(x.Bytes()) < 32 {
padding := make([]byte, 32-len(x.Bytes()))
Expand Down
2 changes: 1 addition & 1 deletion crypto/elliptic/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ type Curve interface {
Neg(x1, y1 *big.Int) (x, y *big.Int)
Type() CurveType
Slip10SeedList() []byte
CompressedPoint(s *big.Int, isHash bool) []byte
CompressedPoint(s []byte, isHash bool) []byte
}
2 changes: 1 addition & 1 deletion crypto/elliptic/secp256k1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var _ = Describe("secp256k1", func() {

DescribeTable("Compressed Point", func(secrethex string, expected string) {
secret, _ := new(big.Int).SetString(secrethex, 16)
pubKey := Secp256k1().CompressedPoint(secret, false)
pubKey := Secp256k1().CompressedPoint(secret.Bytes(), false)
Expect(hex.EncodeToString(pubKey) == expected).Should(BeTrue())
},
Entry("case1:", "f91d8f3a49805fff9289769247e984b355939679f3080156fe295229e00f25af", "0252972572d465d016d4c501887b8df303eee3ed602c056b1eb09260dfa0da0ab2"),
Expand Down

0 comments on commit 7bfdde6

Please sign in to comment.