Python library for code providers using Cosmian Secure Computation
Project description
Cosmian lib SGX
Overview
Python library for code providers using Cosmian Secure Computation.
Example
A simple structure of the code should look like:
$ tree .
.
├── secret_mod.py
└── run.py
where run.py is called the entrypoint and is the only file which can't be encrypted.
The goal of the entrypoint is to manage the I/O of you program whereas other module can hide the Python code you want to keep secret.
Here is an example of a statistical mean code where:
- Code Provider hides the whole module
secret_modwhich is decrypted in the SGX enclave - Data Providers send bytes of an arbitrary long integer in big-endian as data input for the Code Provider
- Result Consumers receive bytes of the statistical mean of all input datas represented as IEEE 754 binary64
"""run module."""
from io import BytesIO
import struct
from typing import Iterator
from cosmian_lib_sgx import Enclave
def convert_input(datas: Iterator[BytesIO]) -> Iterator[int]:
"""Transform input data bytes to integer."""
for data in datas: # type: BytesIO
yield int.from_bytes(data.read(), byteorder="big")
def main() -> int:
"""Entrypoint of your code."""
with Enclave() as enclave:
# import your ciphered module normally
import secret_mod
# convert input data bytes sent by Data Providers
datas: Iterator[int] = convert_input(enclave.read())
# apply function of your module on datas
output: float = secret_mod.custom_mean(datas)
# convert output result
result: bytes = struct.pack("d", output)
# write result for Result Consumers
enclave.write(result)
return 0
if __name__ == "__main__":
main()
"""secret_mod module."""
from typing import Iterator
def custom_mean(input_datas: Iterator[int]) -> float:
"""Statistical mean of input datas."""
n: int = 0
mean: float = 0.0
for x in input_datas: # type: int
n += 1
mean += (x - mean) / n
return mean if n > 0 else float("nan")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cosmian_lib_sgx-0.2.1-py3-none-any.whl.
File metadata
- Download URL: cosmian_lib_sgx-0.2.1-py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c86d35ad6a23456ee0916acd60c5ab7acebeb2c7e83caafcc08f042cb019cc8
|
|
| MD5 |
727332e274326a623ac21cbbded6c186
|
|
| BLAKE2b-256 |
4f5b4496156f3f71dd95c747f18f78a027af94e9cd282932da27529f832048a5
|