use elliptic curve interface

This commit is contained in:
Zack Scholl 2018-06-30 14:45:44 -07:00
parent d1d5b02f27
commit a9969b161f
2 changed files with 14 additions and 7 deletions

View File

@ -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

View File

@ -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