GithubHelp home page GithubHelp logo

szampardi / pake Goto Github PK

View Code? Open in Web Editor NEW

This project forked from schollz/pake

0.0 0.0 0.0 17 KB

PAKE library for generating a strong secret between parties over an insecure channel

License: MIT License

Go 100.00%

pake's Introduction

pake

travis go report card Coverage Status godocs

Overview

This library will help you allow two parties to generate a mutual secret key by using a weak key that is known to both beforehand (e.g. via some other channel of communication). This is a simple API for an implementation of password-authenticated key exchange (PAKE).

I decided to fork [@schollz]'s fork because of some breaking changes:

  • The default hashing function is now sha3.512. This means that SessionKeys are 64b.
  • Functions signatures and names changed.
  • gob encoding is now used instead of JSON.
  • Some Pake{} private variables are now actually private variables.
  • Removed SIEC EC from library, I don't like external imports.

New functionalities:

  • You can set any io.Reader as source of random data.
  • You can change the bcrypt cost.
  • You can provide any curve that implements Add, ScalarBaseMult, ScalarMult, IsOnCurve methods.
  • You can provide any func() hash.Hash that will be used to validate the remote's input.

Defaults: SHA3_512 & CurveP512

algorithm

This protocol is derived from Dan Boneh and Victor Shoup's cryptography book (pg 789, "PAKE2 protocol). The H(k) is a bcrypt hashed session key, which only the keeper of a real session key can verify. Passing this between P and Q allows them to understand that the other party does indeed have the session key derived correctly through the PAKE protocol. The session key can then be used to encrypt a message because it has never passed between parties.

Anytime some part of the algorithm fails verification: i.e. the points are not along the elliptic curve, or if a hash from either party is not identified, a non-nil error is returned. When this happens, you should abort and start a PAKE session as it could have been compromised.

Known working ECs:

Installation

go get -u github.com/nexus166/pake

Usage

package main

import (
	"crypto/elliptic"
	"crypto/sha512"
	"fmt"
	"os"

	"github.com/nexus166/pake"
)

func main() {
	// both parties should have a weak key
	pw := []byte{1, 2, 3}

	// initialize sender P ("0" indicates sender)
	P, err := pake.New(pw, 0, elliptic.P521(), sha512.New)
	check(err)

	// initialize recipient Q ("1" indicates recipient)
	Q, err := pake.New(pw, 1, elliptic.P521(), sha512.New)
	check(err)

	// first, P sends u to Q
	Pe := P.Export()
	fmt.Printf("P public:  %x\n", Pe)

	// Q computes k, sends H(k), v back to P
	err = Q.Import(Pe)
	check(err) // errors will occur when any part of the process fails
	Qe := Q.Export()
	fmt.Printf("Q public:  %x\n", Qe)
	err = P.Import(Qe)
	check(err)

	// P computes k, H(k), sends H(k) to Q
	err = Q.Import(P.Export())
	check(err)

	// both P and Q now have session key
	Pk, err := P.Key()
	check(err)
	fmt.Printf("key P: %x\n", Pk)

	Qk, err := Q.Key()
	check(err)
	fmt.Printf("key Q: %x\n", Qk)
}

func check(err error) {
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(2)
	}
}

Thanks

Thanks @tscholl2 for implementing the first version, and @schollz for implementing the second version.

License

MIT.

pake's People

Contributors

nexus166 avatar schollz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.