tno.mpc.encryption-schemes.templates

TNO PET Lab - secure Multi-Party Computation (MPC) - Encryption Schemes - Templates

https://github.com/tno-mpc/encryption_schemes.templates

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.8%) to scientific vocabulary

Keywords

mpc mpc-lab multi-party-computation tno
Last synced: 6 months ago · JSON representation ·

Repository

TNO PET Lab - secure Multi-Party Computation (MPC) - Encryption Schemes - Templates

Basic Info
Statistics
  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
mpc mpc-lab multi-party-computation tno
Created almost 5 years ago · Last pushed over 1 year ago
Metadata Files
Readme License Citation

README.md

TNO PET Lab - secure Multi-Party Computation (MPC) - Encryption Schemes - Templates

Generic frameworks for encryption schemes. Currently includes support for:

  • Generic encryption scheme (encryption_scheme.py);
  • Asymmetric encryption scheme (asymmetricencryptionscheme.py);
  • Symmetric encryption scheme (symmetricencryptionscheme.py);
  • Support for precomputation of randomness (randomizedencryptionscheme.py).

PET Lab

The TNO PET Lab consists of generic software components, procedures, and functionalities developed and maintained on a regular basis to facilitate and aid in the development of PET solutions. The lab is a cross-project initiative allowing us to integrate and reuse previously developed PET functionalities to boost the development of new protocols and solutions.

The package tno.mpc.encryption_schemes.templates is part of the TNO Python Toolbox.

Limitations in (end-)use: the content of this software package may solely be used for applications that comply with international export control laws.
This implementation of cryptographic software has not been audited. Use at your own risk.

Documentation

Documentation of the tno.mpc.encryption_schemes.templates package can be found here.

Install

Easily install the tno.mpc.encryption_schemes.templates package using pip:

console $ python -m pip install tno.mpc.encryption_schemes.templates

Note: If you are cloning the repository and wish to edit the source code, be sure to install the package in editable mode:

console $ python -m pip install -e 'tno.mpc.encryption_schemes.templates'

If you wish to run the tests you can use:

console $ python -m pip install 'tno.mpc.encryption_schemes.templates[tests]'

Generating prepared randomness for RandomizedEncryptionSchemes

In the encryption process, RandomizedEncryptionSchemes require a random number. A typical encryption process generates a large random number, processes it in a way that is specific for (the private key of) the encryption scheme, and used the prepared random value to encrypt a plaintext message. A similarly prepared random value is required to rerandomize a ciphertext. This process of generating and preparing randomness consumes a lot of time and processing power.

Fortunately, the randomness depends only on the encryption scheme and not on the message that is to be encrypted. This makes it possible to prepare randomness a priori. Our library facilitates this process by the concept of "randomness sources". Three specific sources are shipped with the library, but you may define your own RandomnessSource by implementing the tno.mpc.encryption_schemes.templates._randomness_manager.RandomnessSource protocol. The default sources are:

  • ContextlessSource, which yields randomness from a source that does not need to be opened or closed (e.g. a list, tuple, function-call, ...).
  • FileSource, which creates a thread to read a file, store the values in RAM and yield values on request.
  • ProcessSource, which creates one or more processes that all perform function calls to store a predefined number of return values in RAM and yield on request.

A RandomizedEncryptionScheme is configured with a ContextlessSource that calls its generating function. However, it is often more efficient to start generating a known amount of randomness earlier in the program execution. For this, one may call RandomizedEncryptionScheme.boot_generation which internally initializes and starts a ProcessSource, or requests an existing source to generate more randomness (see also below). Other sources can be configured through RandomizedEncryptionScheme.register_randomness_source.

Storing randomness for later use

Naturally, a maximum speed-up during runtime of your main protocol is achieved by generating random values a priori. This looks as follows. First, the key-generating party generates a public-private keypair and shares the public key with the other participants. Now, every player pregenerates the amount of randomness needed for her part of the protocol and stores it in a file. For example, this can be done overnight or during the weekend. When the main protocol is executed, every player uses the same scheme (public key) as communicated before, configures the scheme to use the pregenerated randomness from file, and runs the main protocol without the need to generate randomness for encryption at that time. A minimal example is provided below.

```py from itertools import count from pathlib import Path

from tno.mpc.encryptionschemes.templates.randomsources import FileSource from tno.mpc.encryptionschemes.templates.randomizedencryption_scheme import ( RandomizedEncryptionScheme, )

counter = count()

class MyRandomizedEncryptionScheme(RandomizedEncryptionScheme): @staticmethod def generaterandomness() -> int: """Dummy randomness generator + preprocessing.""" return next(counter)

# --- empty definitions for all abstract methods ---
@classmethod
def from_security_parameter(cls, *args, **kwargs):
    pass

@classmethod
def generate_key_material(cls, *args, **kwargs):
    pass

@classmethod
def id_from_arguments(cls, *args, **kwargs):
    pass

def encode(self, plaintext):
    pass

def decode(self, encoded_plaintext):
    pass

def _unsafe_encrypt_raw(self, plaintext):
    pass

def _decrypt_raw(self, ciphertext):
    pass

def __eq__(self, *args, **kwargs):
    pass

def pregeneraterandomnessinweekend(amount: int, path: Path): # Initialize scheme, usually with parameters generatingscheme = MyRandomizedEncryptionScheme() # Generate randomness with two processes generatingscheme.bootrandomnessgeneration(amount, maxworkers=2) # Save randomness to comma-separated csv with open(path, "w") as file: for _ in range(amount): file.write(f"{generatingscheme.getrandomness()},") # Shut down scheme to gracefully close source generatingscheme.shutdown()

def usepregeneratedrandomness(amount: int, path: Path): # Initialize scheme WITH THE SAME PARAMETERS! consumingscheme = MyRandomizedEncryptionScheme() # Configure file as randomness source consumingscheme.registerrandomnesssource(FileSource(path)) # Consume randomness from file for _ in range(amount): print(consumingscheme.getrandomness()) # Shut down scheme to gracefully close source consumingscheme.shutdown()

if name == "main": AMOUNT = 24 FILE_PATH = Path("randomness.csv")

pregenerate_randomness_in_weekend(AMOUNT, FILE_PATH)
use_pregenerated_randomness(AMOUNT, FILE_PATH)
# result (possibly not in this order): 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11

```

Owner

  • Name: TNO - MPC Lab
  • Login: TNO-MPC
  • Kind: organization
  • Email: mpclab@tno.nl
  • Location: Anna van Buerenplein 1, 2595 DA Den Haag, The Netherlands

TNO - MPC Lab

Citation (CITATION.cff)

cff-version: 1.2.0
license: Apache-2.0
message: If you use this software, please cite it using these metadata.
authors:
  - name: TNO PET Lab
    city: The Hague
    country: NL
    email: petlab@tno.nl
    website: https://pet.tno.nl
type: software
url: https://pet.tno.nl
contact:
  - name: TNO PET Lab
    city: The Hague
    country: NL
    email: petlab@tno.nl
    website: https://pet.tno.nl
repository-code: https://github.com/TNO-MPC/encryption_schemes.templates
repository-artifact: https://pypi.org/project/tno.mpc.encryption_schemes.templates
title: TNO PET Lab - secure Multi-Party Computation (MPC) - Encryption Schemes - Templates
version: 4.1.5
date-released: 2024-10-16

GitHub Events

Total
  • Push event: 1
Last Year
  • Push event: 1

Committers

Last synced: almost 3 years ago

All Time
  • Total Commits: 4
  • Total Committers: 1
  • Avg Commits per committer: 4.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Thomas Rooijakkers t****s@t****l 4
Committer Domains (Top 20 + Academic)
tno.nl: 1

Issues and Pull Requests

Last synced: 8 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 129 last-month
  • Total dependent packages: 2
  • Total dependent repositories: 0
  • Total versions: 5
  • Total maintainers: 1
pypi.org: tno.mpc.encryption-schemes.templates

Generic templates for different types of Encryption Schemes

  • Versions: 5
  • Dependent Packages: 2
  • Dependent Repositories: 0
  • Downloads: 129 Last month
Rankings
Dependent packages count: 6.6%
Downloads: 17.2%
Average: 24.8%
Forks count: 30.5%
Dependent repos count: 30.6%
Stargazers count: 39.1%
Maintainers (1)
Last synced: 6 months ago

Dependencies

pyproject.toml pypi
  • tenacity *
  • typing_extensions ~=4.0; python_version<'3.11'