puzzle

package
v0.0.0-...-31898ba Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2019 License: ISC Imports: 14 Imported by: 0

Documentation

Overview

The puzzle package implements cryptographic primitives to generate, conceal (blind) and solve puzzles required by the TumbleBit protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlindPuzzle

func BlindPuzzle(pk *PuzzlePubKey, p []byte) ([]byte, []byte, []byte, error)

BlindPuzzle generates a random factor and returns a product of the puzzle p and the factor as well as the multiplicative inverse of the factor suitable for UnblindPuzzle.

func DecodeIndexList

func DecodeIndexList(indexList []byte) ([]int, error)

DecodeIndexList decodes a buffer containing a series of 16 bit little endian values into a slice of integers.

func EncodeIndexList

func EncodeIndexList(indexList []int) ([]byte, error)

EncodeIndexList encodes a slice of integer values that can be represented by a uint16 type in a series of 16 bit little endian values.

func FakeTxFormat

func FakeTxFormat(randomPad []byte) []byte

FakeTxFormat generates a hash value for a transaction dummy with a known structure so that it can be verified given the knowledge of a random pad.

func HashIndexList

func HashIndexList(salt []byte, indexList []int) ([]byte, error)

HashIndexList produces a salted cryptographic hash value of a binary encoded index list.

func MarshalPubKey

func MarshalPubKey(pk *PuzzleKey) ([]byte, error)

func NewPuzzlePromise

func NewPuzzlePromise(pk *PuzzleKey, sig []byte) ([]byte, []byte, []byte, error)

func NewSolutionPromise

func NewSolutionPromise(pk *PuzzleKey, p []byte) ([]byte, []byte, []byte, error)

NewSolutionPromise recovers a solution to the puzzle p and generates a promise that puzzle p opens up to this solution.

func Quotients

func Quotients(pk *PuzzlePubKey, secrets [][]byte) ([][]byte, error)

Quotients returns an slice of quotients, where i'th value is calculated as secret[i] divided by secret[i-1], effectively chaining them together.

func RevealSolution

func RevealSolution(promise []byte, secret []byte) ([]byte, error)

func SolvePuzzle

func SolvePuzzle(pk *PuzzleKey, p []byte) ([]byte, error)

SolvePuzzle decrypts the puzzle p using the private key pk.

func UnblindPuzzle

func UnblindPuzzle(pk *PuzzlePubKey, p []byte, r []byte) []byte

UnblindPuzzle recovers the original value of the puzzle by muliplying it with an inverse obtained from BlindedPuzzle.

func ValidateBlindedPuzzle

func ValidateBlindedPuzzle(pk *PuzzlePubKey, blinding, puzzle []byte, secret []byte) bool

ValidateBlindedPuzzle makes sure that the encrypted secret is a correct blinding factor for the puzzle with the provided public key pk. Essentially this checks that blinding = puzzle * secret^e.

func ValidatePuzzle

func ValidatePuzzle(pk *PuzzlePubKey, puzzle, secret []byte) bool

ValidatePuzzle makes sure that secret encrypts to the same value as the puzzle with the provided public key pk.

func VerifyQuotients

func VerifyQuotients(pk *PuzzlePubKey, qs [][]byte, puzzles [][]byte) bool

VerifyQuotients verifies that quotients are constructed correctly by making sure that i'th puzzle can be recovered as a product of a preceding puzzle and i'th quotient raised to the power of e. In other words, each quotient becomes a blinding factor linking puzzles together.

func VerifyQuotientsWithSecrets

func VerifyQuotientsWithSecrets(pk *PuzzlePubKey, qs [][]byte, secrets [][]byte) bool

VerifyQuotientsWithSecrets verifies that quotients are constructed correctly by making sure that i'th secret can be recovered as a product of preceding quotient values.

Types

type PuzzleKey

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

func GeneratePuzzleKey

func GeneratePuzzleKey(difficulty int) (*PuzzleKey, error)

func (*PuzzleKey) PublicKey

func (pk *PuzzleKey) PublicKey() *PuzzlePubKey

type PuzzlePubKey

type PuzzlePubKey rsa.PublicKey

func ParsePubKey

func ParsePubKey(pub []byte) (PuzzlePubKey, error)

Jump to

Keyboard shortcuts

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