Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Er25519 #140

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added crypto/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion crypto/binaryfield/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crypto/binaryquadraticform/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions crypto/bip32/child/0_initial_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"errors"
"math/big"

"github.com/btcsuite/btcd/btcec"
"github.com/getamis/alice/crypto/bip32"
"github.com/getamis/alice/crypto/birkhoffinterpolation"
"github.com/getamis/alice/crypto/circuit"
ecpointgrouplaw "github.com/getamis/alice/crypto/ecpointgrouplaw"
"github.com/getamis/alice/crypto/elliptic"
"github.com/getamis/alice/crypto/homo/paillier"
"github.com/getamis/alice/crypto/ot"
"github.com/getamis/alice/crypto/zkproof"
Expand Down Expand Up @@ -60,8 +60,8 @@ type initial struct {
}

var (
curve = btcec.S256()
secp256k1N = curve.N
curve = elliptic.NewSecp256k1()
secp256k1N = curve.Params().N

// alice
aliceParseFunc = func(initialBody *BodyInitial, ownResult [][]byte) [][]byte {
Expand Down
10 changes: 5 additions & 5 deletions crypto/bip32/child/child_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ var _ = Describe("Child test", func() {
pubKey := ecpointgrouplaw.ScalarBaseMult(curve, privateKey)
// share1: x = 1 rank and share2: x = 2 rank 0
share1 := new(big.Int).Add(privateKey, big.NewInt(1))
share1.Mod(share1, curve.N)
share1.Mod(share1, secp256k1N)
share2 := new(big.Int).Add(privateKey, big.NewInt(2))
share2.Mod(share2, curve.N)
share2.Mod(share2, secp256k1N)
// curve := btcec.S256()
childIndex := uint32(2147483648)

Expand Down Expand Up @@ -101,9 +101,9 @@ var _ = Describe("Child test", func() {
}

childPrivateKey := new(big.Int).Add(childShares[0].share, childShares[1].share)
childPrivateKey.Mod(childPrivateKey, curve.N)
childPrivateKey.Mod(childPrivateKey, secp256k1N)
anotherMethodChildParivateKey := new(big.Int).Add(privateKey, childTranslate)
anotherMethodChildParivateKey.Mod(anotherMethodChildParivateKey, curve.N)
anotherMethodChildParivateKey.Mod(anotherMethodChildParivateKey, secp256k1N)
Expect(anotherMethodChildParivateKey).Should(Equal(anotherMethodChildParivateKey))
Expect(hex.EncodeToString(childPrivateKey.Bytes())).Should(Equal(expectedPrivate1))
Expect(hex.EncodeToString(childPrivateKey.Bytes())).Should(Equal(expectedPrivate1))
Expand All @@ -113,7 +113,7 @@ var _ = Describe("Child test", func() {
grandChildManager, err := childShares[0].ComputeNonHardenedChildShare(1)
Expect(err).Should(BeNil())
grandChildPrivateKey := new(big.Int).Add(grandChildManager.share, childShares[1].share)
grandChildPrivateKey.Mod(grandChildPrivateKey, curve.N)
grandChildPrivateKey.Mod(grandChildPrivateKey, secp256k1N)
Expect(hex.EncodeToString(grandChildPrivateKey.Bytes())).Should(Equal(expectedPrivate2))
Expect(hex.EncodeToString(grandChildManager.chainCode)).Should(Equal(expectedChaincode2))
},
Expand Down
2 changes: 1 addition & 1 deletion crypto/bip32/child/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions crypto/bip32/master/0_initial_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
"errors"
"math/big"

"github.com/btcsuite/btcd/btcec"
"github.com/getamis/alice/crypto/bip32"
"github.com/getamis/alice/crypto/birkhoffinterpolation"
"github.com/getamis/alice/crypto/circuit"
"github.com/getamis/alice/crypto/elliptic"
"github.com/getamis/alice/crypto/ot"
"github.com/getamis/alice/crypto/utils"
"github.com/getamis/alice/internal/message/types"
Expand Down Expand Up @@ -63,8 +63,8 @@ type initial struct {

var (
otherInfoBit, _ = hex.DecodeString(otherInfoBitStr)
curve = btcec.S256()
secp256k1N = curve.N
curve = elliptic.NewSecp256k1()
secp256k1N = curve.Params().N
big2Inver, _ = new(big.Int).SetString("57896044618658097711785492504343953926418782139537452191302581570759080747169", 10)

// alice
Expand Down
2 changes: 1 addition & 1 deletion crypto/bip32/master/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions crypto/birkhoffinterpolation/birkhoffinterpolation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
package birkhoffinterpolation

import (
"crypto/elliptic"
"math/big"
"testing"

"github.com/btcsuite/btcd/btcec"
"github.com/getamis/alice/crypto/ecpointgrouplaw"
pt "github.com/getamis/alice/crypto/ecpointgrouplaw"
"github.com/getamis/alice/crypto/elliptic"
"github.com/getamis/alice/crypto/matrix"
"github.com/getamis/alice/crypto/polynomial"
"github.com/getamis/alice/crypto/utils"
Expand All @@ -29,6 +28,10 @@ import (
. "github.com/onsi/gomega"
)

var (
secp256k1 = elliptic.NewSecp256k1()
)

func TestBirkhoffinterpolation(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Birkhoffinterpolation Suite")
Expand Down Expand Up @@ -274,7 +277,7 @@ var _ = Describe("Birkhoff Interpolation", func() {
)

BeforeEach(func() {
curve = btcec.S256()
curve = secp256k1
fieldOrder := curve.Params().N
threshold = uint32(3)
poly, err = polynomial.RandomPolynomial(fieldOrder, threshold-1)
Expand Down
2 changes: 1 addition & 1 deletion crypto/birkhoffinterpolation/bk.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crypto/circuit/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crypto/commitment/feldman.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
package commitment

import (
"crypto/elliptic"
"errors"
"math/big"

bkhoff "github.com/getamis/alice/crypto/birkhoffinterpolation"
"github.com/getamis/alice/crypto/ecpointgrouplaw"
pt "github.com/getamis/alice/crypto/ecpointgrouplaw"
"github.com/getamis/alice/crypto/elliptic"
"github.com/getamis/alice/crypto/polynomial"
)

Expand Down Expand Up @@ -59,8 +59,8 @@ func buildFeldmanCommitMessage(curve elliptic.Curve, secrets *polynomial.Polynom
Points: make([]*ecpointgrouplaw.EcPointMessage, lens),
}
for i := 0; i < lens; i++ {
var err error
pt := ecpointgrouplaw.ScalarBaseMult(curve, secrets.Get(i))
var err error
msg.Points[i], err = pt.ToEcPointMessage()
if err != nil {
return nil, err
Expand Down
48 changes: 24 additions & 24 deletions crypto/commitment/feldman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package commitment

import (
"crypto/elliptic"
"math/big"

"github.com/btcsuite/btcd/btcec"
"github.com/getamis/alice/crypto/elliptic"

bkhoff "github.com/getamis/alice/crypto/birkhoffinterpolation"
pt "github.com/getamis/alice/crypto/ecpointgrouplaw"
"github.com/getamis/alice/crypto/polynomial"
Expand All @@ -42,10 +42,10 @@ var _ = Describe("Feldman commitment test", func() {
expected.Points[2], _ = pt.ScalarBaseMult(curve, big.NewInt(100)).ToEcPointMessage()
Expect(got).Should(Equal(expected))
},
Entry("P224", elliptic.P224()),
Entry("P256", elliptic.P256()),
Entry("P384", elliptic.P384()),
Entry("S256", btcec.S256()),
// Entry("P224", elliptic.P224()),
// Entry("P256", elliptic.P256()),
// Entry("P384", elliptic.P384()),
Entry("S256", secp256k1),
)

DescribeTable("should be ok", func(x *big.Int, rank, threshold uint32, curve elliptic.Curve) {
Expand All @@ -65,13 +65,13 @@ var _ = Describe("Feldman commitment test", func() {
Expect(err).Should(BeNil())
},
Entry("should be OK",
big.NewInt(225), uint32(1), uint32(3), elliptic.P224()),
big.NewInt(225), uint32(1), uint32(3), secp256k1),
Entry("should be OK",
big.NewInt(2290), uint32(0), uint32(2), elliptic.P256()),
big.NewInt(2290), uint32(0), uint32(2), secp256k1),
Entry("zero point case",
big.NewInt(2290), uint32(2), uint32(2), elliptic.P224()),
big.NewInt(2290), uint32(2), uint32(2), secp256k1),
Entry("should be OK",
big.NewInt(2291), uint32(2), uint32(5), elliptic.P256()),
big.NewInt(2291), uint32(2), uint32(5), secp256k1),
)

DescribeTable("failed to verify due to wrong rank", func(x *big.Int, rank, threshold uint32, curve elliptic.Curve) {
Expand All @@ -92,11 +92,11 @@ var _ = Describe("Feldman commitment test", func() {
Expect(err).Should(Equal(ErrFailedVerify))
},
Entry("case #0",
big.NewInt(225), uint32(1), uint32(3), elliptic.P224()),
big.NewInt(225), uint32(1), uint32(3), secp256k1),
Entry("case #1",
big.NewInt(2290), uint32(0), uint32(2), elliptic.P256()),
big.NewInt(2290), uint32(0), uint32(2), secp256k1),
Entry("case #2",
big.NewInt(2291), uint32(2), uint32(5), elliptic.P256()),
big.NewInt(2291), uint32(2), uint32(5), secp256k1),
)

DescribeTable("failed to verify due to wrong x", func(x *big.Int, rank, threshold uint32, curve elliptic.Curve) {
Expand All @@ -117,11 +117,11 @@ var _ = Describe("Feldman commitment test", func() {
Expect(err).Should(Equal(ErrFailedVerify))
},
Entry("case #0",
big.NewInt(225), uint32(1), uint32(3), elliptic.P224()),
big.NewInt(225), uint32(1), uint32(3), secp256k1),
Entry("case #1",
big.NewInt(2290), uint32(0), uint32(2), elliptic.P256()),
big.NewInt(2290), uint32(0), uint32(2), secp256k1),
Entry("case #2",
big.NewInt(2291), uint32(2), uint32(5), elliptic.P256()),
big.NewInt(2291), uint32(2), uint32(5), secp256k1),
)

DescribeTable("invalid commitment message", func(x *big.Int, rank, threshold uint32, curve elliptic.Curve) {
Expand All @@ -147,13 +147,13 @@ var _ = Describe("Feldman commitment test", func() {
Expect(err).Should(Equal(pt.ErrDifferentLength))
},
Entry("should be OK",
big.NewInt(225), uint32(1), uint32(3), elliptic.P224()),
big.NewInt(225), uint32(1), uint32(3), secp256k1),
Entry("should be OK",
big.NewInt(2290), uint32(0), uint32(2), elliptic.P256()),
big.NewInt(2290), uint32(0), uint32(2), secp256k1),
Entry("zero point case",
big.NewInt(2290), uint32(2), uint32(2), elliptic.P224()),
big.NewInt(2290), uint32(2), uint32(2), secp256k1),
Entry("should be OK",
big.NewInt(2291), uint32(2), uint32(5), elliptic.P256()),
big.NewInt(2291), uint32(2), uint32(5), secp256k1),
)

DescribeTable("empty points in commitment message", func(x *big.Int, rank, threshold uint32, curve elliptic.Curve) {
Expand All @@ -175,12 +175,12 @@ var _ = Describe("Feldman commitment test", func() {
Expect(err).Should(Equal(pt.ErrDifferentLength))
},
Entry("should be OK",
big.NewInt(225), uint32(1), uint32(3), elliptic.P224()),
big.NewInt(225), uint32(1), uint32(3), secp256k1),
Entry("should be OK",
big.NewInt(2290), uint32(0), uint32(2), elliptic.P256()),
big.NewInt(2290), uint32(0), uint32(2), secp256k1),
Entry("zero point case",
big.NewInt(2290), uint32(2), uint32(2), elliptic.P224()),
big.NewInt(2290), uint32(2), uint32(2), secp256k1),
Entry("should be OK",
big.NewInt(2291), uint32(2), uint32(5), elliptic.P256()),
big.NewInt(2291), uint32(2), uint32(5), secp256k1),
)
})
3 changes: 1 addition & 2 deletions crypto/commitment/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"bytes"
"testing"

"github.com/btcsuite/btcd/btcec"
pt "github.com/getamis/alice/crypto/ecpointgrouplaw"
"github.com/getamis/alice/crypto/utils"
. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -147,7 +146,7 @@ var _ = Describe("hash", func() {

Context("NewCommitterByPoint/GetPointFromHashCommitment", func() {
It("should be ok", func() {
p := pt.NewIdentity(btcec.S256())
p := pt.NewIdentity(secp256k1)
c, err := NewCommitterByPoint(p)
Expect(err).Should(BeNil())
Expect(c).ShouldNot(BeNil())
Expand Down
2 changes: 1 addition & 1 deletion crypto/commitment/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions crypto/commitment/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@
package commitment

import (
"crypto/elliptic"
"math/big"

"github.com/btcsuite/btcd/btcec"
"github.com/getamis/alice/crypto/elliptic"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"

pt "github.com/getamis/alice/crypto/ecpointgrouplaw"
)

var(
secp256k1 = elliptic.NewSecp256k1()
)

var _ = Describe("message test", func() {
DescribeTable("EcPoints()", func(curveType pt.EcPointMessage_Curve, curve elliptic.Curve) {
var err error
Expand All @@ -45,10 +48,10 @@ var _ = Describe("message test", func() {
Expect(p).Should(Equal(expected[i]))
}
},
Entry("P224", pt.EcPointMessage_P224, elliptic.P224()),
Entry("P256", pt.EcPointMessage_P256, elliptic.P256()),
Entry("P384", pt.EcPointMessage_P384, elliptic.P384()),
Entry("S256", pt.EcPointMessage_S256, btcec.S256()),
// Entry("P224", pt.EcPointMessage_P224, elliptic.P224()),
// Entry("P256", pt.EcPointMessage_P256, elliptic.P256()),
// Entry("P384", pt.EcPointMessage_P384, elliptic.P384()),
Entry("S256", pt.EcPointMessage_S256, secp256k1),
)

It("invalid point", func() {
Expand Down
Loading