Giter Club home page Giter Club logo

htlp-rs's Introduction

htlp-rs

This repository contains an implementation of Homomorphic Timelock Puzzles (see section 4.1). A timelock puzzle is a cryptographic primitive that encloses a secret value within a puzzle (ie. encrypts it). The puzzle can be quickly generated, but can only be solved (decrypted) over a period of time by repeated squarings, which cannot be parallelized. It's the opposite of a VDF in a sense, which takes a long time to generate but can be quickly verified.

The timelock puzzles are linearly homomorphic in that multiple puzzles can be combined and when solved, their output is the summation of their individual secrets.

Note that the time it takes to solve a puzzle is machine-dependent. If one machine can square faster than another, it'll solve the puzzle quicker. If you want to timelock something for definitely at least a certain amount of time, try to benchmark solving on the fastest machine you anticipate could try to solve the puzzle. The time parameter passed into Parameters::new isn't tied to any real-life measure of time, apart from that a higher value will take longer to solve.

Usage

use htlp::setup::Parameters;

use num_bigint_dig::{RandBigInt, ToBigUint};
use rand;

fn generate_and_solve() {
    let security = 32;
    let time = 100.to_biguint().unwrap();
    let params = Parameters::new(security, time);

    let one = 1.to_biguint().unwrap();
    let mut rng = rand::thread_rng();
    let secret = rng.gen_biguint_range(&one, &(&params.n - &one));
    let puzzle = &params.generate(&secret);

    let res = puzzle.solve();
    debug_assert!(secret == res);
}

fn generate_and_solve_homomorphic() {
    let security = 32;
    let time = 100.to_biguint().unwrap();
    let params = Parameters::new(security, time);

    let one = 1.to_biguint().unwrap();
    let mut rng = rand::thread_rng();
    let secret0 = rng.gen_biguint_range(&one, &(&params.n - &one));
    let puzzle0 = &params.generate(&secret0);
    let secret1 = rng.gen_biguint_range(&one, &(&params.n - &one));
    let puzzle1 = &params.generate(&secret1);

    let puzzle = puzzle0.add(puzzle1);
    let secret = &secret0 + &secret1;

    let res = puzzle.solve();
    debug_assert!(secret == res);
}

htlp-rs's People

Contributors

noot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.