Git Product home page Git Product logo

pygamehop's Introduction

pygamehop

pygamehop is a work-in-progress tool aimed to support cryptographers writing game hopping proofs. The main goal of pygamehop is to allow a cryptographer to specify a cryptographic scheme and security property in a pseudocode-like subset of Python, encode the steps of a game-hopping proof (including reductions), and have the tool partially or fully check the sequence of games.

Created by Matthew McKague (Queensland University of Technology) and Douglas Stebila (University of Waterloo).

Current status

This repository is very much a work-in-progress, and is not intended for general use, but may be of interest to people wondering about the project.

Getting started

pygamehop requires Python 3.9 or higher. Clone the repository, install the requirements, and set an environment variable for the working directory:

git clone [email protected]:dstebila/pygamehop
cd pygamehop
python3 --version
# should be 3.9 or higher
pip3 install -r requirements.txt
PYTHONPATH=`pwd`; export PYTHONPATH

Now you can run an example. There are 5 working examples at the moment:

  • examples/KEMfromPKE: A key encapsulation mechanism (KEM) built from a public key encryption scheme; including a proof that, if the PKE is IND-CPA-secure, then the KEM is IND-CPA-secure.
  • examples/PKEfromKEM: A public key encryption scheme built from a KEM; including a proof that, if the KEM is IND-CPA-secure, then the PKE is IND-CPA-secure.
  • examples/parallelPKE: A public key encryption scheme built by running two PKEs in parallel; including a proof that the parallel PKE is IND-CPA-secure if both contributing PKEs are IND-CPA-secure.
  • examples/nestedPKE: A public key encryption scheme built by running two PKEs one after the other; including two proofs that the nested PKE is IND-CPA-secure if either contributing PKE is IND-CPA-secure.
  • examples/SymEnc_CPADollar: A proof that a symmetric encryption scheme that is indistinguishable from random under chosen plaintext attacks (IND$-CPA) is IND-CPA-secure.

A good starting example is examples/KEMfromPKE/KEMfromPKE_is_INDCPA.py.

  • First, take a look (in an editor) at gamehop/primitives/KEM.py and gamehop/primitives/PKE.py, which show the API definition and IND-CPA security properties for KEMs and PKEs.
  • Next, look (in an editor) at examples/KEMfromPKE/KEMfromPKE.py, which is a generic construction of a KEM from a PKE scheme.
  • Finally, we move on to the proof in examples/KEMfromPKE/KEMfromPKE_is_INDCPA.py.
    • Open up the file in an editor and you'll see a 3-step game hopping proof.
      • The central hop of the proof involves a reduction to the IND-CPA security property of the PKE; the reduction is explicitly given in the file.
      • There are also two rewriting hops that encode a fact about length that is not known to the proof engine, and must be checked manually.
    • You can run the proof by typing python3 examples/KEMfromPKE/KEMfromPKE_is_INDCPA.py. How much detail is printed can be configured in the proof.check line inside the file, but the default at the moment prints out every game hop, along with the canonicalization of every game, and the diffs between the games.
    • A visualization of the game hops is auto-generated and can be found in docs/images/KEMfromPKE_is_INDCPA.png, also shown below:

Documentation

You can see more explanation of the examples in docs/examples.md. Also in the docs folder are notes about the primitives available so far, and the inlining and canonicalization procedures. Unfortunately this documentation is somewhat out-of-date at the moment; the main ideas are still there, but some of the details have changed.

Limitations

This is highly incomplete work and has many flaws. At this point it's trying to be a proof of concept.

Contact us

If you're interested in this project, email us at [email protected] and [email protected] to discuss next steps. There's a lot of work to be done before this is ready for widespread use, but we'd love some help!

pygamehop's People

Contributors

dstebila avatar mckaguem avatar thirteenchars avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pygamehop's Issues

Typechecking of inlined code

  • When the inliner tries to inline something, it should check that the type of the thing being inlined satisfies any type constraints.
  • In the proof engine, once inlining has happened, the type checker should be run.
    • This might be related to how I want to use the UniformlyRandom type in game hops to ensure e.g. arguments to a PRF/KDF are uniformly random when applying the hop.

Handle guessing games in proofs engine

Will want to re-do PKE from KEM using this. At the end will need to check that output is independent of input bit. Have to figure out how to handle proofs that mix guessing games and distinguishing games.

Be able to parse functions that aren't at top level

ast.parse(inspect.getsource(f)) chokes on functions that aren't defined at the top level of a module, since the source code for f is indented. (This affects pulling functions from inside classes, for example.) We should be able to change gamehop.inlining.internal.get_function_def to count how much whitespace is as the start of the first line, and then remove that much space from the start of every line.

if expression bug

I think the logic for if expressions incorrectly handles the following case:

x = 1
if condition:
    x = 2
    y = 2
else:
    y = 3

Generate LaTeX from Python

Would be cool to be able to output LaTeX source code of a crypto function written in Python. We can recognize the type of statement (assign, function call, if, return), but the user would have to provide mapping of what they want individual variables to be rendered as (e.g., {'kem': '\mathsf{KEM}', 'pk': '\pk', ...}).

Reduction guesses

Eg. multi-party PKE. Reduction guesses a particular key. Fails if adversary selects a different key.

  • Calculation of overall advantage when a step has a multiplicative advantage
  • Examples of how to step from a game with a random guesses to games without a guess

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.