From a9969b161f7b98eaa5cd984409b1c426a7ca0bf4 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sat, 30 Jun 2018 14:45:44 -0700 Subject: [PATCH] use elliptic curve interface --- src/pake/pake.go | 12 +++++++++--- src/pake/pake_test.go | 9 +++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/pake/pake.go b/src/pake/pake.go index 0cb62b2..daa6801 100644 --- a/src/pake/pake.go +++ b/src/pake/pake.go @@ -1,7 +1,6 @@ package pake import ( - "crypto/elliptic" "crypto/rand" "crypto/sha256" "encoding/json" @@ -20,6 +19,13 @@ import ( // http://www.lothar.com/~warner/MagicWormhole-PyCon2016.pdf // Slide 11 +type EllipticCurve interface { + Add(x1, y1, x2, y2 *big.Int) (*big.Int, *big.Int) + ScalarBaseMult(k []byte) (*big.Int, *big.Int) + ScalarMult(Bx, By *big.Int, k []byte) (*big.Int, *big.Int) + IsOnCurve(x, y *big.Int) bool +} + type Pake struct { // Public variables Role int @@ -30,7 +36,7 @@ type Pake struct { HkA, HkB []byte // Private variables - curve elliptic.Curve + curve EllipticCurve pw []byte vpwᵤ, vpwᵥ *big.Int upwᵤ, upwᵥ *big.Int @@ -42,7 +48,7 @@ type Pake struct { isVerified bool } -func Init(pw []byte, role int, curve elliptic.Curve) (p *Pake, err error) { +func Init(pw []byte, role int, curve EllipticCurve) (p *Pake, err error) { p = new(Pake) if role == 1 { p.Role = 1 diff --git a/src/pake/pake_test.go b/src/pake/pake_test.go index 104b065..a4bd02a 100644 --- a/src/pake/pake_test.go +++ b/src/pake/pake_test.go @@ -8,13 +8,14 @@ import ( ) func TestPake(t *testing.T) { + curve := elliptic.P521() //siec.SIEC255() // successful (both have same k) // initialize A - A, err := Init([]byte{1, 2, 3}, 0, elliptic.P256()) + A, err := Init([]byte{1, 2, 3}, 0, curve) assert.Nil(t, err) assert.False(t, A.IsVerified()) // initialize B - B, err := Init([]byte{1, 2, 3}, 1, elliptic.P256()) + B, err := Init([]byte{1, 2, 3}, 1, curve) assert.Nil(t, err) assert.False(t, B.IsVerified()) // send A's stuff to B @@ -32,11 +33,11 @@ func TestPake(t *testing.T) { // failure (both have different k) // initialize A - A, err = Init([]byte{1, 2, 3}, 0, elliptic.P256()) + A, err = Init([]byte{1, 2, 3}, 0, curve) assert.Nil(t, err) assert.False(t, A.IsVerified()) // initialize B - B, err = Init([]byte{4, 5, 6}, 1, elliptic.P256()) + B, err = Init([]byte{4, 5, 6}, 1, curve) assert.Nil(t, err) assert.False(t, B.IsVerified()) // send A's stuff to B