shithub: libdp9ik

ref: 7e77582b6904979700dde6b0cba53f2d91e2b28d

View raw version
package libdp9ik

import (
	"crypto/sha1"
	"math/big"

	"golang.org/x/crypto/pbkdf2"
)

func passtoaeskey(passwd string) []byte {
	return pbkdf2.Key([]byte(passwd), []byte("Plan 9 key derivation"), 9001, Aeskeylen, sha1.New)
}

type PAKCurve struct {
	P *big.Int
	A *big.Int
	D *big.Int
	X *big.Int
	Y *big.Int
}

const (
	//see drawterm/libauthsrv/ed448.mpc
	edP0 = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
	edA0 = 1
	edD0 = -39081
	edX0 = "297EA0EA2692FF1B4FAFF46098453A6A26ADF733245F065C3C59D0709CECFA96147EAAF3932D94C63D96C170033F4BA0C7F0DE840AED939F"
	edY0 = 13
)

//GPAKCurve is to be used as readonly
var GPAKCurve PAKCurve = func() PAKCurve {
	c := PAKCurve{
		&big.Int{},
		&big.Int{},
		&big.Int{},
		&big.Int{},
		&big.Int{},
	}
	c.P.SetString(edP0, 16)
	c.A.SetInt64(edA0)
	c.D.SetInt64(edD0)
	c.X.SetString(edX0, 16)
	c.Y.SetInt64(edY0)
	return c
}()