jpake

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2020 License: MIT Imports: 10 Imported by: 1

README

JPAKE

This library allows 2 parties to generate a mutual secret key using a weak key that is known to each other beforehand. This provides a simple API over an implementation of Password Authenticated Key Exchange by Juggling (J-PAKE) based on elliptic curves (currently secp2561k).

This protocol is derived from the J-PAKE paper and relevant RFC. This is a companion project to the javascript version, and all messages are interchangeable between the 2 libraries.

Install

go get github.com/choonkiatlee/jpake-go

Quick Start

func main() {

	// initialise a curve to use.
	secret := "weaksecret"

	jpA, err := jpake.Init(secret)
	panicOnErr(err)
	jpB, err := jpake.Init(secret)
	panicOnErr(err)

	msgA1, err := jpA.GetRound1Message()
	panicOnErr(err)
	msgB1, err := jpB.GetRound1Message()
	panicOnErr(err)

	msgA2, err := jpA.GetRound2Message(msgB1)
	panicOnErr(err)
	msgB2, err := jpB.GetRound2Message(msgA1)
	panicOnErr(err)

	sharedKeyA, err := jpA.ComputeSharedKey(msgB2)
	panicOnErr(err)
	sharedKeyB, err := jpB.ComputeSharedKey(msgA2)
	panicOnErr(err)

	fmt.Println("\nShared Keys Generated: ")
	fmt.Println("\nAlice key: ", sharedKeyA)
	fmt.Println("Bob key: ", sharedKeyB)
}

func panicOnErr(err){
    if err != nil {
        panic(err)
    }
}

JPAKE theory

  • Explanation to come

Implementation Notes:

  • This currently uses Javascript BigInts.

Documentation

Index

Constants

View Source
const (
	JPAKESTATE_INITIALISED = iota
	JPAKESTATE_WAITFORROUND1MSG
	JPAKESTATE_WAITFORROUND2MSG
	JPAKESTATE_KEYCOMPUTED
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckSessionKeyMessage

type CheckSessionKeyMessage struct {
	SessionKey string `json:"SessionKey"`
}

type EllipticCurve

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
	Params() *elliptic.CurveParams
}

EllipticCurve is a general curve which allows other elliptic curves to be used with PAKE.

type HashFnType

type HashFnType func(string) []byte

type JPake

type JPake struct {
	// contains filtered or unexported fields
}

func Init

func Init(pw string) (*JPake, error)

func InitWithCurve

func InitWithCurve(pw string, curve EllipticCurve) (*JPake, error)

func InitWithCurveAndHashFns

func InitWithCurveAndHashFns(pw string, curve EllipticCurve, hashFn HashFnType, kdf KDFType) (*JPake, error)

func (*JPake) CheckReceivedSessionKeyMsg

func (jp *JPake) CheckReceivedSessionKeyMsg(jsonMsgfromB []byte) bool

func (*JPake) ComputeCheckSessionKeyMsg

func (jp *JPake) ComputeCheckSessionKeyMsg() ([]byte, error)

func (*JPake) ComputeSharedKey

func (jp *JPake) ComputeSharedKey(jsonMsgfromB []byte) ([]byte, error)

func (*JPake) GetRound1Message

func (jp *JPake) GetRound1Message() ([]byte, error)

func (*JPake) GetRound2Message

func (jp *JPake) GetRound2Message(jsonMsgfromB []byte) ([]byte, error)

func (*JPake) SessionKey

func (jp *JPake) SessionKey() ([]byte, error)

func (*JPake) SetRandomState

func (jp *JPake) SetRandomState(x1 *big.Int, x2 *big.Int)

type KDFType

type KDFType func([]byte) []byte

type Round1Message

type Round1Message struct {
	X1Gx  string `json:"x1Gx"`
	X1Gy  string `json:"x1Gy"`
	X2Gx  string `json:"x2Gx"`
	X2Gy  string `json:"x2Gy"`
	X1ZKP ZKPMsg `json:"x1ZKP"`
	X2ZKP ZKPMsg `json:"x2ZKP"`
}

type Round2Message

type Round2Message struct {
	Ax    string `json:"Ax"`
	Ay    string `json:"Ay"`
	XsZKP ZKPMsg `json:"xsZKP"`
}

type ZKPMsg

type ZKPMsg struct {
	Tx string `json:"tx"`
	Ty string `json:"ty"`
	R  string `json:"r"`
	C  string `json:"c"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL