A generic extension to MPyC that allows you to securely compute the inverse of a matrix that may contain SecFxp values
Project description
TNO MPC Lab - MPyC - Matrix Inverse
The TNO MPC lab consists of generic software components, procedures, and functionalities developed and maintained on a regular basis to facilitate and aid in the development of MPC solutions. The lab is a cross-project initiative allowing us to integrate and reuse previously developed MPC functionalities to boost the development of new protocols and solutions.
The package tno.mpc.mpyc.matrix_inverse is part of the TNO Python Toolbox.
This package is based on the demo ridgeregression.py
from the MPyC library on Feb 26th, 2020, as implemented by
Frank Blom. https://github.com/lschoe/mpyc/blob/2de1dd76db632bdc2a48acfbbaab841fa73cf8bd/demos/ridgeregression.py. The
underlying theory is published in the paper 'Efficient Secure Ridge Regression from
Randomized Gaussian Elimination' by Frank Blom, Niek J. Bouman, Berry
Schoenmakers, and Niels de Vreede, presented at TPMPC 2019 by Frank Blom.
See https://eprint.iacr.org/2019/773 (or https://ia.cr/2019/773).
Note: we added support for secure fixed points (SecFxp
).
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.mpyc.matrix_inverse package can be found here.
Install
Easily install the tno.mpc.mpyc.matrix_inverse package using pip:
$ python -m pip install tno.mpc.mpyc.matrix_inverse
Note:
A significant performance improvement can be achieved by installing the GMPY2 library.
$ python -m pip install 'tno.mpc.mpyc.matrix_inverse[gmpy]'
If you wish to run the tests you can use:
$ python -m pip install 'tno.mpc.mpyc.matrix_inverse[tests]'
Usage
Usage
example.py
import numpy as np from mpyc.runtime import mpc from tno.mpc.mpyc.matrix_inverse import matrix_inverse async def main(): X = (np.random.randint(low=-1000, high=1000, size=(5, 5)) / 10).tolist() Xinv = np.linalg.inv(X).tolist() await mpc.start() secfxp = mpc.SecFxp() X_mpc = [[secfxp(x) for x in row] for row in X] X_mpc = [mpc.input(row, 0) for row in X_mpc] inverse = matrix_inverse(X_mpc) Xinv_mpc = [await mpc.output(_) for _ in inverse] Xinv_mpc = [[float(xx) for xx in x] for x in Xinv_mpc] checker = mpc.matrix_prod(X_mpc, inverse) checker = [await mpc.output(_) for _ in checker] diff = np.array(Xinv) - np.array(Xinv_mpc) rel_diff = np.divide( diff, np.array(Xinv), out=np.zeros_like(diff), where=np.array(Xinv) != 0 ) await mpc.shutdown() print(f"X = \n{np.array(X)}\n") print(f"Xinv = \n{np.array(Xinv)}\n") print(f"Xinv_mpc = \n{np.array(Xinv_mpc)}\n") print(f"X * Xinv_mpc = \n{np.array(checker)}\n") print(f"max absolute diff = {np.abs(diff).max()}") print(f"max relative diff (nonzero entries) = {np.abs(rel_diff).max()}") if __name__ == "__main__": mpc.run(main())
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
File details
Details for the file tno.mpc.mpyc.matrix_inverse-0.4.3-py3-none-any.whl
.
File metadata
- Download URL: tno.mpc.mpyc.matrix_inverse-0.4.3-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 042a61e5630ee2f304b01fe820175b48cffb1ed548832aa5de9968e772d0e6bd |
|
MD5 | 8d8d74bc5035776e8bb27b8531448491 |
|
BLAKE2b-256 | b1ca74be3a0eaf40acf5445793435973637c6047a974972bfbbb03da80f56608 |