rsw

package
v0.0.0-...-7ad0b1f Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package rsw is an implementation of Rivest-Shamir-Wagner timelock puzzles, from RSW96. The puzzles are based on modular exponentiation, and this package provides an easy to use API for creating and solving these types of puzzles.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(key []byte, a int64, rsaKeyBits int) (timelock crypto.Timelock, err error)

New creates a new TimelockRSW with p and q generated as per crypto/rsa, and an input a as well as number of bits for the RSA key size. The key is also set here The number of bits is so we can figure out how big we want p and q to be.

func New2048

func New2048(key []byte, a int64) (tl crypto.Timelock, err error)

New2048 creates a new TimelockRSW with p and q generated as per crypto/rsa, and an input a. This generates according to a fixed RSA key size (2048 bits).

func New2048A2

func New2048A2(key []byte) (tl crypto.Timelock, err error)

New2048A2 is the same as New2048 but we use a base of 2. It's called A2 because A=2 I guess

func NewTimelockWithPrimes

func NewTimelockWithPrimes(key []byte, a uint64, p *big.Int, q *big.Int) (timelock crypto.Timelock, err error)

NewTimelockWithPrimes creates a new timelock puzzle with primes p and q.

func VerifyPuzzleOutput

func VerifyPuzzleOutput(p *big.Int, q *big.Int, pz *PuzzleRSW, claimedKey []byte) (valid bool, err error)

VerifyPuzzleOutput verifies that the timelock puzzle PuzzleRSW

Types

type PuzzleRSW

type PuzzleRSW struct {
	N *big.Int
	A *big.Int
	T *big.Int
	// We use C_k = b xor k
	CK *big.Int
}

PuzzleRSW is the puzzle that can be then solved by repeated modular squaring

func (*PuzzleRSW) Deserialize

func (pz *PuzzleRSW) Deserialize(raw []byte) (err error)

Deserialize turns a gob-encoded puzzle into a go struct we can use.

func (*PuzzleRSW) Serialize

func (pz *PuzzleRSW) Serialize() (raw []byte, err error)

Serialize turns the RSW puzzle into something that can be sent over the wire

func (*PuzzleRSW) Solve

func (pz *PuzzleRSW) Solve() (answer []byte, err error)

Solve solves the puzzle by repeated squarings

func (*PuzzleRSW) SolveCkADD

func (pz *PuzzleRSW) SolveCkADD() (answer []byte, err error)

SolveCkADD solves the puzzle by repeated squarings and subtracting b from ck

func (*PuzzleRSW) SolveCkXOR

func (pz *PuzzleRSW) SolveCkXOR() (answer []byte, err error)

SolveCkXOR solves the puzzle by repeated squarings and xor b with ck

func (*PuzzleRSW) SolveGMPCkADD

func (pz *PuzzleRSW) SolveGMPCkADD() (answer []byte, err error)

SolveGMPCkADD solves the puzzle by repeated squarings and xor b with ck using the GMP library

func (*PuzzleRSW) SolveGMPCkXOR

func (pz *PuzzleRSW) SolveGMPCkXOR() (answer []byte, err error)

SolveGMPCkXOR solves the puzzle by repeated squarings and xor b with ck using the GMP library

type TimelockRSW

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

TimelockRSW generates the puzzle that can then only be solved with repeated squarings

func (*TimelockRSW) SetupTimelockPuzzle

func (tl *TimelockRSW) SetupTimelockPuzzle(t uint64) (puzzle crypto.Puzzle, answer []byte, err error)

SetupTimelockPuzzle sets up the time lock puzzle for the scheme described in RSW96. This uses the normal crypto/rsa way of selecting primes p and q. You should throw away the answer but some puzzles like the hash puzzle make sense to have the answer as an output of the setup, since that's the decryption key and you don't know beforehand how to encrypt.

Example

This is how you create a solvable RSW timelock puzzle.

// Allocate memory for key
key := make([]byte, 32)
// set key to be some bytes that we want to be the solution to the puzzle
copy(key[:], []byte(fmt.Sprint("!!! secret < 32 bytes !!!")))
// Create a new timelock. A timelock can be used to create puzzles for a key with a certain time.
rswTimelock, err := New2048A2(key)
if err != nil {
	log.Fatalf("Error creating a new timelock puzzle: %s", err)
}

// set the time to be some big number
t := uint64(1000000)

// Create the puzzle. Puzzles can be solved.
puzzle, expectedAns, err := rswTimelock.SetupTimelockPuzzle(t)
if err != nil {
	log.Fatalf("Error creating puzzle: %s", err)
}

fmt.Printf("Puzzle nil? %t. Expected Answer: %s", puzzle == nil, string(expectedAns))
// Puzzle nil? false. Expected Answer: !!! secret < 32 bytes !!!
Output:

Jump to

Keyboard shortcuts

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