tpec

package module
v0.0.0-...-f6210e3 Latest Latest
Warning

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

Go to latest
Published: May 3, 2019 License: MIT Imports: 13 Imported by: 0

README

tpec: 2P-ECDSA Signatures

This package contains:

Prerequisites

go1.11 or higher

Installation

GO111MODULE=on go install github.com/cfromknecht/tpec

Running Demo

2P-ECDSA signature for a given message:

tpec -message="hello 2p-ecdsa"

2P-ECDSA signature for a message digest:

tpec -digest=f25b10e68539ba917b2ae2028326ee5ce46c386746b15ae5585813b08f5aceae

To reveal a secret from party 2 to party1, use the -secret flag:

tpec -message="who are you" -secret=20a5beef

For help, run tpec -h.

Warning

THIS IS A PROOF OF CONCEPT IMPLEMENTATION BEING USED FOR RESEARCH. USE AT YOUR OWN RISK.

Benchmarks

go test -v -bench=. -benchtime=30s
Latency Memory Allocations
BenchmarkKeyGen 599ms 6.46MB 12176
BenchmarkSign 17.8ms 122KB 717
BenchmarkScriptlessSign 18.8ms 142KB 1074

Results computed on 2.8 GHz Intel Core i7 16 GB 2133 MHz LPDDR3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidOTMac = errors.New("invalid one-time MAC")

	ErrFinalKeyMismatch = errors.New("final OT key doesn't match")

	ErrKeyNotGenerated = errors.New("private key has not been generated")
)
View Source
var (
	ErrInvalidRangeProof = errors.New("invalid range proof")

	ErrInvalidProofPair = errors.New("cannot prove for invalid proof pair")
)
View Source
var ErrInvalidCommitment = errors.New("invalid commitment")
View Source
var ErrInvalidPoK = errors.New("invalid proof of knowledge")
View Source
var ErrInvalidPreSignature = errors.New("invalid pre-signature")
View Source
var (
	ErrInvalidPrimalityProof = errors.New(
		"invalid paillier public key primality proof",
	)
)
View Source
var ErrInvalidSignature = errors.New("invalid presignature created")

Functions

func Commit

func Commit(data []byte) (Comm, Nonce, error)

func NewPrivKey

func NewPrivKey(modulus *big.Int) (*eckey.SecretKey, error)

Types

type BitSlice

type BitSlice []byte

func (BitSlice) Bit

func (b BitSlice) Bit(i int) byte

type CiphertextPair

type CiphertextPair struct {
	C1 *big.Int
	C2 *big.Int
}

func NewCiphertextPairs

func NewCiphertextPairs(size int) []CiphertextPair

type Comm

type Comm = Uint256

func (*Comm) Verify

func (c *Comm) Verify(data []byte, nonce *Nonce) error

type Config

type Config struct {
	Q        *big.Int
	Q3       *big.Int
	QSquared *big.Int

	NPaillierBits  int
	NthRootSecBits int
	RangeSecBits   int
}

type DLogPoK

type DLogPoK struct {
	PK  eckey.CompressedPublicKey
	Sig schnorr.Signature
}

func NewDLogPK

func NewDLogPK(plaintext []byte, sk *eckey.SecretKey) (*DLogPoK, error)

func (*DLogPoK) Bytes

func (p *DLogPoK) Bytes() []byte

func (*DLogPoK) Verify

func (p *DLogPoK) Verify(plaintext []byte) error

type KeyGenMsg1

type KeyGenMsg1 struct {
	X1PoKComm Comm
}

type KeyGenMsg2

type KeyGenMsg2 struct {
	X2PoK      *DLogPoK
	RPChalComm Comm
}

type KeyGenMsg3

type KeyGenMsg3 struct {
	X1PoK      *DLogPoK
	X1PoKNonce Nonce
	PProof     *PaillierNthRootProof

	RPCtxtPairs []CiphertextPair
	// contains filtered or unexported fields
}

type KeyGenMsg4

type KeyGenMsg4 struct {
	RPChallenge BitSlice
	RPChalNonce Nonce
	CPrime      *big.Int
	ABComm      Comm
}

type KeyGenMsg5

type KeyGenMsg5 struct {
	RPProofPairs []ProofPair
	AlphaComm    Comm
}

type KeyGenMsg6

type KeyGenMsg6 struct {
	A       *big.Int
	B       *big.Int
	ABNonce Nonce
}

type KeyGenMsg7

type KeyGenMsg7 struct {
	AlphaPK    *eckey.CompressedPublicKey
	AlphaNonce Nonce
}

type Nonce

type Nonce = Uint256

type PaillierNthRootProof

type PaillierNthRootProof struct {
	PK      *paillier.PublicKey
	U       *big.Int
	A       *big.Int
	Z       *big.Int
	SecBits int
}

func ProvePaillierNthRoot

func ProvePaillierNthRoot(
	pk *paillier.PublicKey,
	secbits int) (*PaillierNthRootProof, error)

func (*PaillierNthRootProof) Verify

func (p *PaillierNthRootProof) Verify() error

type Party1

type Party1 struct {
	X1      *eckey.PublicKey
	X1PoK   *DLogPoK
	X1Nonce Nonce

	// Keygen phase 3
	X2        *eckey.PublicKey
	PSK       *paillier.PrivateKey
	CKey      *big.Int
	CKeyNonce *big.Int
	RPProver  *RangeProofProver

	// Keygen phase 5
	ABComm     Comm
	Alpha      *big.Int
	AlphaPK    *eckey.CompressedPublicKey
	AlphaNonce Nonce

	//Keygen phase 7
	Q *eckey.PublicKey
	// contains filtered or unexported fields
}

func NewParty1

func NewParty1(cfg *Config) *Party1

func (*Party1) GenKey

func (p *Party1) GenKey(
	p2 *Party2,
	x1, x2 *eckey.SecretKey) (*Party1PrivateKey, error)

func (*Party1) KeyGenPhase1

func (p *Party1) KeyGenPhase1(
	sid uint64) (*KeyGenMsg1, error)

func (*Party1) KeyGenPhase3

func (p *Party1) KeyGenPhase3(
	sid uint64,
	m2 *KeyGenMsg2) (*KeyGenMsg3, error)

func (*Party1) KeyGenPhase5

func (p *Party1) KeyGenPhase5(
	sid uint64,
	m4 *KeyGenMsg4) (*KeyGenMsg5, error)

func (*Party1) KeyGenPhase7

func (p *Party1) KeyGenPhase7(
	sid uint64,
	m6 *KeyGenMsg6) (*KeyGenMsg7, error)

type Party1PrivateKey

type Party1PrivateKey struct {
	PSK       *paillier.PrivateKey
	X1SK      *eckey.SecretKey
	PublicKey *btcec.PublicKey
	// contains filtered or unexported fields
}

func (*Party1PrivateKey) NewSSSignCtx

func (sk *Party1PrivateKey) NewSSSignCtx(
	msg []byte,
	T *eckey.CompressedPublicKey) *Party1SSSignCtx

func (*Party1PrivateKey) NewSignCtx

func (sk *Party1PrivateKey) NewSignCtx(msg []byte) *Party1SignCtx

func (*Party1PrivateKey) ScriptlessSign

func (sk1 *Party1PrivateKey) ScriptlessSign(
	msg []byte,
	t *eckey.SecretKey,
	sk2 *Party2PrivateKey) (*btcec.Signature, *eckey.SecretKey, error)

func (*Party1PrivateKey) Sign

func (sk1 *Party1PrivateKey) Sign(
	msg []byte,
	sk2 *Party2PrivateKey) (*btcec.Signature, error)

type Party1SSSignCtx

type Party1SSSignCtx struct {
	T *eckey.CompressedPublicKey

	R1         *eckey.PublicKey
	R1PoK      *DLogPoK
	R1PoKNonce Nonce

	// Sign phase 3
	R2 *eckey.PublicKey
	R3 *eckey.PublicKey

	// Sign phase 5
	SDPrime *big.Int
	// contains filtered or unexported fields
}

func (*Party1SSSignCtx) Extract

func (p *Party1SSSignCtx) Extract(
	sig *btcec.Signature) (*eckey.SecretKey, error)

func (*Party1SSSignCtx) SSSignMsgPhase1

func (p *Party1SSSignCtx) SSSignMsgPhase1(sid uint64) (*SSSignMsg1, error)

func (*Party1SSSignCtx) SSSignMsgPhase3

func (p *Party1SSSignCtx) SSSignMsgPhase3(
	sid uint64,
	m2 *SSSignMsg2) (*SSSignMsg3, error)

func (*Party1SSSignCtx) SSSignMsgPhase5

func (p *Party1SSSignCtx) SSSignMsgPhase5(
	sid uint64,
	m4 *SSSignMsg4) (*SSSignMsg5, error)

func (*Party1SSSignCtx) Zero

func (c *Party1SSSignCtx) Zero()

type Party1SignCtx

type Party1SignCtx struct {
	R1         *eckey.PublicKey
	R1PoK      *DLogPoK
	R1PoKNonce Nonce

	// Sign phase 3
	R2 *eckey.PublicKey
	// contains filtered or unexported fields
}

func (*Party1SignCtx) SignMsgPhase1

func (p *Party1SignCtx) SignMsgPhase1(sid uint64) (*SignMsg1, error)

func (*Party1SignCtx) SignMsgPhase3

func (p *Party1SignCtx) SignMsgPhase3(
	sid uint64,
	m2 *SignMsg2) (*SignMsg3, error)

func (*Party1SignCtx) SignMsgPhase5

func (p *Party1SignCtx) SignMsgPhase5(
	sid uint64,
	m4 *SignMsg4) (*btcec.Signature, error)

func (*Party1SignCtx) Zero

func (c *Party1SignCtx) Zero()

type Party2

type Party2 struct {

	// Keygen phase 2
	X1PoKComm Comm

	X2         *eckey.PublicKey
	X2PoK      *DLogPoK
	RPVerifier *RangeProofVerifier

	// Keygen phase 4
	X1      *eckey.PublicKey
	PPK     *paillier.PublicKey
	CKey    *big.Int
	CPrime  *big.Int
	A       *big.Int
	B       *big.Int
	ABNonce Nonce

	// Keygen phase 6
	AlphaComm Comm

	// Keygen phase 8
	Q *eckey.PublicKey
	// contains filtered or unexported fields
}

func NewParty2

func NewParty2(cfg *Config) *Party2

func (*Party2) KeyGenPhase2

func (p *Party2) KeyGenPhase2(
	sid uint64,
	m1 *KeyGenMsg1) (*KeyGenMsg2, error)

func (*Party2) KeyGenPhase4

func (p *Party2) KeyGenPhase4(
	sid uint64,
	m3 *KeyGenMsg3) (*KeyGenMsg4, error)

func (*Party2) KeyGenPhase6

func (p *Party2) KeyGenPhase6(
	sid uint64,
	m5 *KeyGenMsg5) (*KeyGenMsg6, error)

func (*Party2) KeyGenPhase8

func (p *Party2) KeyGenPhase8(
	sid uint64,
	m7 *KeyGenMsg7) error

func (*Party2) PrivateKey

func (p *Party2) PrivateKey() (*Party2PrivateKey, error)

type Party2PrivateKey

type Party2PrivateKey struct {
	PPK       *paillier.PublicKey
	CKey      *big.Int
	X2SK      *eckey.SecretKey
	PublicKey *btcec.PublicKey
	// contains filtered or unexported fields
}

func (*Party2PrivateKey) NewSSSignCtx

func (sk *Party2PrivateKey) NewSSSignCtx(
	msg []byte,
	t *eckey.SecretKey,
	T *eckey.CompressedPublicKey) *Party2SSSignCtx

func (*Party2PrivateKey) NewSignCtx

func (sk *Party2PrivateKey) NewSignCtx(msg []byte) *Party2SignCtx

type Party2SSSignCtx

type Party2SSSignCtx struct {
	T *eckey.CompressedPublicKey

	// Sign phase 2
	R1PoKComm Comm

	R2    *eckey.PublicKey
	R2PoK *DLogPoK

	R3PoK *DLogPoK

	// Sign phase 4
	R1 *eckey.PublicKey
	// contains filtered or unexported fields
}

func (*Party2SSSignCtx) SSSignMsgPhase2

func (p *Party2SSSignCtx) SSSignMsgPhase2(
	sid uint64,
	m1 *SSSignMsg1) (*SSSignMsg2, error)

func (*Party2SSSignCtx) SSSignMsgPhase4

func (p *Party2SSSignCtx) SSSignMsgPhase4(
	sid uint64,
	m3 *SSSignMsg3) (*SSSignMsg4, error)

func (*Party2SSSignCtx) SSSignMsgPhase6

func (p *Party2SSSignCtx) SSSignMsgPhase6(
	sid uint64,
	m5 *SSSignMsg5) (*btcec.Signature, error)

func (*Party2SSSignCtx) Zero

func (c *Party2SSSignCtx) Zero()

type Party2SignCtx

type Party2SignCtx struct {

	// Sign phase 2
	R1PoKComm Comm

	R2    *eckey.PublicKey
	R2PoK *DLogPoK

	// Sign phase 4
	R1 *eckey.PublicKey
	// contains filtered or unexported fields
}

func (*Party2SignCtx) SignMsgPhase2

func (p *Party2SignCtx) SignMsgPhase2(
	sid uint64,
	m1 *SignMsg1) (*SignMsg2, error)

func (*Party2SignCtx) SignMsgPhase4

func (p *Party2SignCtx) SignMsgPhase4(
	sid uint64,
	m3 *SignMsg3) (*SignMsg4, error)

func (*Party2SignCtx) Zero

func (c *Party2SignCtx) Zero()

type ProofPair

type ProofPair struct {
	J  byte
	W1 *big.Int
	R1 *big.Int
	W2 *big.Int
	R2 *big.Int
}

func NewProofPairs

func NewProofPairs(size int) []ProofPair

type RangeProof

type RangeProof struct {
	CtxtPairs  []CiphertextPair
	ProofPairs []ProofPair
}

type RangeProofProver

type RangeProofProver struct {
	X   *big.Int
	R   *big.Int
	PSK *paillier.PrivateKey
	Q   *big.Int
	Q3  *big.Int

	ChallengeComm Comm
	Accuracy      int

	SecPairs  []SecretPair
	CtxtPairs []CiphertextPair
}

func NewRangeProofProver

func NewRangeProofProver(
	x *big.Int,
	r *big.Int,
	q *big.Int,
	q3 *big.Int,
	psk *paillier.PrivateKey,
	comm Comm,
	accuracy int) (*RangeProofProver, error)

func (*RangeProofProver) Prove

func (p *RangeProofProver) Prove(challenge BitSlice, nonce *Nonce) ([]ProofPair, error)

type RangeProofVerifier

type RangeProofVerifier struct {
	C         *big.Int
	PPK       *paillier.PublicKey
	Q3        *big.Int
	Challenge BitSlice
	Comm      Comm
	Nonce     Nonce
	Accuracy  int

	CtxtPairs []CiphertextPair
}

func NewRangeProofVerifier

func NewRangeProofVerifier(
	q3 *big.Int,
	accuracy int) (*RangeProofVerifier, error)

func (*RangeProofVerifier) ReceiveCtxt

func (p *RangeProofVerifier) ReceiveCtxt(
	c *big.Int,
	ppk *paillier.PublicKey,
	ctxtPairs []CiphertextPair)

func (*RangeProofVerifier) Verify

func (p *RangeProofVerifier) Verify(proofPairs []ProofPair) error

type SSSignMsg1

type SSSignMsg1 struct {
	R1PoKComm Comm
}

type SSSignMsg2

type SSSignMsg2 struct {
	R2PoK *DLogPoK
	R3PoK *DLogPoK
}

type SSSignMsg3

type SSSignMsg3 struct {
	R1PoK      *DLogPoK
	R1PoKNonce Nonce
}

type SSSignMsg4

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

type SSSignMsg5

type SSSignMsg5 struct {
	SDPrime *big.Int
}

type SecretPair

type SecretPair struct {
	W1 *big.Int
	R1 *big.Int
	W2 *big.Int
	R2 *big.Int
}

func NewSecretPairs

func NewSecretPairs(size int) []SecretPair

type SignMsg1

type SignMsg1 struct {
	R1PoKComm Comm
}

type SignMsg2

type SignMsg2 struct {
	R2PoK *DLogPoK
}

type SignMsg3

type SignMsg3 struct {
	R1PoK      *DLogPoK
	R1PoKNonce Nonce
}

type SignMsg4

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

type Uint256

type Uint256 [32]byte

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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