Skip to main content

Statistical Testing of RAndom Probing Security

Project description

STRAPS

Statistical Testing of RAndom Probing Security

This tool is described in the paper Towards Tight Random Probing Security.

Install

STRAPS is distributed as a python package (with compiled native code in it).

Dependencies:

  • python >= 3.10 (for older python, see version 0.1.2)
  • pip

(On Ubuntu: apt install python3 python3-pip. On Windows, install from https://python.org.)

Install command

pip install straps

or (install for local user only):

pip install --user straps

We do not currently build for Mac OS (working CI configuration contribution is welcome), but you can build it for yourself (see below).

If the installation fails after "Building wheel for straps [...]", it is probably due to the use of an old version of pip. If updating it is not possible, you may also do it in python virtual environment:

python3 -m venv ve_straps
source ve_straps/bin/activate
python3 -m pip install -u pip
python3 -m pip install straps

Usage

Simple demo

python -m straps.secfig isw

Run

python -m straps.secfig --help

to see all options.

Running python -m straps.paper_plots generates all figures of the paper (this might take dozens of hours on a beefy machine).

Cache

If the environment variable STRAPS_CACHE_DIR is defined, it will be used as the path for a cache directory. This cache stores PDT computation resuts across executions, and also during one execution. It is therefore strongly recommended to set this variable, as it might lead to large runtime reductions, even on a single run.

Custom composition

from straps import eval_circs, sh_pdt, pdt_sampling, secfig

def eval_x_cube(p, pdts, d):
    """Composition to compute ISW-mul(x, x**2) (without refreshing)."""
    # Create the Shared PD with one output sharing
    x = sh_pdt.ShPd(['out'], d)
    # We build the circuit from the output: we start from the output sharing,
    # create the gadget that generates it, then work backwards until we reach
    # the intput.
    # ISW multiplication
    x.op('out', ['t0', 't1'], pdts['ISW'])
    x.op('t0', ['t0'], pdts['square'])
    x.split_sharing('in', 't0', 't1')
    return x.security('in')

## Then, either run
# Set the parameters:
k = "ub" # ub (upper bound) or lb (statistical-only lower bound)
e = 1e-6 # statistical confidence level
d = 3 # number of shares
n_s_max = 10**5 # N_max
suff_thresh = 100 # N_t
p = 1e-2 # parameter of the random probing model
pdts = {
    circ: pdt_sampling.gpdt(circ, d, k, e, n_s_max, suff_thresh, True, False).instantiate(p)
    for circ in ["ISW", "square"]
    }
# Get the security level:
security_level = eval_x_cube(p, pdts, d)

## Or, if you want to integrate with provided utils:
# Put in base_circuits your custom function and the list of gadgets you use
eval_circs.base_circuits["custom_cube_implem"] = (eval_x_cube, lambda **kwargs: ['ISW', 'square'])
# Put in specialized_circuits a display name, and the name of your base_circuits entry
# (and a dict of optional parameter to your function).
eval_circs.specialized_circuits["custom_cube"] = ("ISW Cube w/o refresh", "custom_cube_implem", {})
# Then, you can use our top-level functions, e.g.
import numpy as np
from matplotlib import pyplot as plt
ds = [1, 2, 3] # number of shares
ps = np.logspace(-4, 0, 50) # parameter of the random probing model
e = 1e-6 # statistical confidence level
n_s_max = 10**5 # N_max
suff_thresh = 100 # N_t
secfig.plot_fig(**secfig.data_fig("custom_cube", ds, e, ps, n_s_max, suff_thresh))
plt.show()

See straps/eval_circs.py for more examples (such as the AES S-box).

Custom gadget

Your can also design your own gadget.

from straps import circuit_model

# Define the gadget.
def custom_gadget(d):
    """Custom gadget with d shares."""
    if d != 2:
        raise ValueError("This gadget works only with 2 shares.")
    c = circuit_model.Circuit(d)
    # two input sharings: (in00, in01) and (in10, in11)
    in00 = c.var("in00", kind="input", port=(0, 0))
    in01 = c.var("in01", kind="input", port=(0, 1))
    in10 = c.var("in10", kind="input", port=(1, 0))
    in11 = c.var("in11", kind="input", port=(1, 1))
    # one output sharing (out0, out1)
    out0 = c.var("out0", kind="output", port=(0, 0))
    out1 = c.var("out1", kind="output", port=(0, 1))
    # a fresh random
    r = c.var("r", kind="random")
    # intermediate variables
    w = c.var("w")
    x = c.var("x")
    y = c.var("y")
    # circuit gates
    c.l_sum(w, (in00, r)) # XOR gate: x = in00 XOR r
    c.l_sum(x, (w, in01))
    c.l_sum(y, (in10, in11)) # NB: leaks at first-order.
    c.l_prod(out0, (y, x)) # AND gate: out0 = x AND y
    c.l_prod(out1, (y, r))
    return c

# Integrate the gadget in the list of available gadgets:
from straps import simple_circuits
simple_circuits.all_circs["my_custom_gadget"] = custom_gadget

# Then you can use "my_custom_gadget" in any custom composition (see Custom
# composition section). E.g.
from straps import sh_pdt, eval_circs
def eval_custom_gadget(p, pdts, d, sec_input="in0"):
    x = sh_pdt.ShPd(['out'], d)
    x.op('out', ['in0', 'in1'], pdts['my_custom_gadget'])
    return x.security(sec_input)

eval_circs.base_circuits["custom_gadget"] = (
        eval_custom_gadget, lambda **kwargs: ['my_custom_gadget']
)
eval_circs.specialized_circuits["custom_gadget_in0"] = ("Custom Gadget in 0", "custom_gadget", {'sec_input': 'in0'})
eval_circs.specialized_circuits["custom_gadget_in1"] = ("Custom Gadget in 1", "custom_gadget", {'sec_input': 'in1'})
# You can then evaluate the security with straps.secfig (see Custom composition section).

Build

If you want to build STRAPS yourself, you will need the following for all platforms:

  • A stable rust compiler with cargo (install e.g. from https://rustup.rs)
  • Python (>= 3.6)
  • The boost library:
    • On Ubuntu (20.04):
    apt install libboost-all-dev
    
    • On RHEL/CentOS:
    yum install boost-devel
    
    choco install boost-msvc-14.2
    
    (Assuming Visual Studio 2019)
  • A C++ compiler
    • On Ubuntu (20.04):
    apt install gcc g++
    
    • On RHEL/CentOS:
    yum install gcc gcc-g++
    
    • On Windows install Visual Studio 2019 with C++ extensions.

Then, run

python setup.py develop

to install STRAPS in development mode. For Windows, you need to the the environment variable CXXFLAGS=-I C:/Local/boost_1_74_0 (adjust according to your boost version).

License

STRAPS is licensed under the GNU AGPL, version 3 or later. See COPYING for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

straps-0.1.4.tar.gz (63.8 kB view details)

Uploaded Source

Built Distributions

straps-0.1.4-cp313-cp313-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.13 Windows x86-64

straps-0.1.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.5 MB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

straps-0.1.4-cp312-cp312-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.12 Windows x86-64

straps-0.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.5 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

straps-0.1.4-cp311-cp311-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.11 Windows x86-64

straps-0.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.5 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

straps-0.1.4-cp310-cp310-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10 Windows x86-64

straps-0.1.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.5 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

File details

Details for the file straps-0.1.4.tar.gz.

File metadata

  • Download URL: straps-0.1.4.tar.gz
  • Upload date:
  • Size: 63.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for straps-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b28316d9ad66e61d953ef9cdd830091c173f321c10bb9b8ac99f37ad05edabcb
MD5 8ec721869624b005111d2a46876969ee
BLAKE2b-256 5ac72d201a021fa06a53803efcadb157d7ebf995854fa8ca8b32c163ab55bf30

See more details on using hashes here.

File details

Details for the file straps-0.1.4-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: straps-0.1.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for straps-0.1.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 445eb355a0454d160256361ce7acb783f2d4184f088a44012b516b5b68d3a0aa
MD5 3d959f0e168cad2ed329c4340af97a7d
BLAKE2b-256 73440d35836efdf0849484587d0077e1509b7465783310adb6ed00fe0ad25175

See more details on using hashes here.

File details

Details for the file straps-0.1.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for straps-0.1.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c99140dd775f70d6d9b410f77620fcb75c40f6cdac559ac013064b7f46fd9abc
MD5 733f36828876bf2199954e9674412805
BLAKE2b-256 b3670ba3547655b991e9cc5cef7d899f5e96c4fa985c75124be2f7f9c2b7e794

See more details on using hashes here.

File details

Details for the file straps-0.1.4-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: straps-0.1.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for straps-0.1.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7b2f705664b19799a339ee5b3dcbb0130beda33d1a7499203b9ace9229e36184
MD5 a89294ef9d74acb61cbaad2348c34432
BLAKE2b-256 1bd0f60cabf7d3c2f33afdb2b7ae1e71418e1dc01d486311ca8d672499d3721a

See more details on using hashes here.

File details

Details for the file straps-0.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for straps-0.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7d4f92dc4c47e3ab8411519da91b7df6ba8ff9ce734bd18a632945dba73873c0
MD5 e991890daf8a07760b1c1bfa3879b5af
BLAKE2b-256 729fa4e951ac572534fa5411e4dbc66463e1b3391e9a98dabe26fb944947db95

See more details on using hashes here.

File details

Details for the file straps-0.1.4-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: straps-0.1.4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for straps-0.1.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a2dd8ce99d23c69d739c35b85f9d0441dfa8e89dc20b3ab95180fe39f2a20f92
MD5 2489048fda754b40be6c056946179088
BLAKE2b-256 ee5b0736ccdc9f2a1a9a34abc3aaf37de385514dbc3b0f640d1e0e319019365e

See more details on using hashes here.

File details

Details for the file straps-0.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for straps-0.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 abafcd7ca66c61b2a846e46d81ac389e1d65a25c2b7e1867356e5cf09a427dbe
MD5 1b46cb34c57bb9d51e82bc7fe191bfa3
BLAKE2b-256 df3f391d7991d3729a3eeed9cc72a1453a9ea6ce1c800b55ba21c7a13956f6b2

See more details on using hashes here.

File details

Details for the file straps-0.1.4-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: straps-0.1.4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for straps-0.1.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 01b7f6720b072d44ed4e92977d81b95926ed90440d231c8af883662a90753a84
MD5 b98b5d4429d06fed667f3b455ce4e4ce
BLAKE2b-256 652250afdb32857135fed4b768cef91a41c30640571b5e8708589a953f1836ab

See more details on using hashes here.

File details

Details for the file straps-0.1.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for straps-0.1.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 14da640ba19bdb871563d3dbbcd572ddf813c170c5516239a8922166dac67d7c
MD5 7ce1b715a901272b5dbe7b7ba9df649b
BLAKE2b-256 82d67a9518a1f16853c35c352cb4a3da29a6163274791f57b11689932613e157

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page