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 ¶
- func New(key []byte, a int64, rsaKeyBits int) (timelock crypto.Timelock, err error)
- func New2048(key []byte, a int64) (tl crypto.Timelock, err error)
- func New2048A2(key []byte) (tl crypto.Timelock, err error)
- func NewTimelockWithPrimes(key []byte, a uint64, p *big.Int, q *big.Int) (timelock crypto.Timelock, err error)
- func VerifyPuzzleOutput(p *big.Int, q *big.Int, pz *PuzzleRSW, claimedKey []byte) (valid bool, err error)
- type PuzzleRSW
- func (pz *PuzzleRSW) Deserialize(raw []byte) (err error)
- func (pz *PuzzleRSW) Serialize() (raw []byte, err error)
- func (pz *PuzzleRSW) Solve() (answer []byte, err error)
- func (pz *PuzzleRSW) SolveCkADD() (answer []byte, err error)
- func (pz *PuzzleRSW) SolveCkXOR() (answer []byte, err error)
- func (pz *PuzzleRSW) SolveGMPCkADD() (answer []byte, err error)
- func (pz *PuzzleRSW) SolveGMPCkXOR() (answer []byte, err error)
- type TimelockRSW
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
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 ¶
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 ¶
New2048A2 is the same as New2048 but we use a base of 2. It's called A2 because A=2 I guess
Types ¶
type PuzzleRSW ¶
PuzzleRSW is the puzzle that can be then solved by repeated modular squaring
func (*PuzzleRSW) Deserialize ¶
Deserialize turns a gob-encoded puzzle into a go struct we can use.
func (*PuzzleRSW) Serialize ¶
Serialize turns the RSW puzzle into something that can be sent over the wire
func (*PuzzleRSW) SolveCkADD ¶
SolveCkADD solves the puzzle by repeated squarings and subtracting b from ck
func (*PuzzleRSW) SolveCkXOR ¶
SolveCkXOR solves the puzzle by repeated squarings and xor b with ck
func (*PuzzleRSW) SolveGMPCkADD ¶
SolveGMPCkADD solves the puzzle by repeated squarings and xor b with ck using the GMP library
func (*PuzzleRSW) SolveGMPCkXOR ¶
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: