Python bindings for the BN254/256 pairing-friendly curve supported by the MCl library.
Project description
/issues License: None Classifier: Programming Language :: Python :: 3 Classifier: Operating System :: OS Independent Requires-Python: >=3.6 Description-Content-Type: text/x-rst License-File: LICENSE
mclbn256.py
Python library that serves as an API for the BN254/256 pairing-friendly curve implemented in MCl in C.
Package Installation and Usage
The package is available on PyPI:
pip install mclbn256
The library can be imported in the usual ways:
import mclbn256 # Abstracted 'dumb' API over the scalar and point groups from mclbn256 import mclbn256 # Extended attributes, internals, classes, test methods
Examples
This library supports concise construction of elliptic curve points (groups G1 and G2) and scalars (group Fr):
from mclbn256 import G1, G2, Fr >>> p = G1().hash("some row") >>> q = G2().hash("another row") >>> p.valid() True >>> q.valid() True >>> s = Fr(6) >>> t = Fr(857462736753) >>> ((p * s) @ (q * t)) == (p @ (q * s * t)) True >>> ((p * s * ~t) @ (q * t)) == (p @ (q * s)) True >>> ((p * s) @ q) == ((p * ~t) @ (q * s * t)) True
Data structures for the relevant curve subgroups and finite fields are included as well:
>>> len(Fr().randomize().serialize()) 32 >>> len(G1().randomize().serialize()) 32 >>> len(G2().randomize().serialize()) 64 >>> len((G1().randomize() @ G2().randomize()).serialize()) <= 384 True
The representation of BN254 points and scalars in this library is compatible with the pure-Python bn254 implementation thanks to ECp_to_G1
and the other similarly-named helpers. We may also convert points in that library’s representation to the minimal-size MCl serial format using ECp_serialize
.
>>> Q = G1.random(); G1().deserialize(ECp_serialize(G1_to_ECp(Q))) == Q and Q.serialize() == ECp_serialize(G1_to_ECp(Q)) True
Please see the package oblivious (which extends this package) for more examples of how to use the BN254 curve.
Contributions
In order to contribute to the source code, open an issue or submit a pull request on the GitHub page for this library.
Versioning
Beginning with version 0.1.0, the version number format for this library and the changes to the library associated with version number increments conform with Semantic Versioning 2.0.0.
Naming Notes
BN-256 was an old name for the BarretoNaehrig(2,254) Weierstrass curve,
when it was though to have close to 256 bits of security. It has since
been estimated to have at least 90 bits of security (compared to
symmetric ciphers) and is now more commonly refered to by BN254, after
the number of bits in its prime modulus. Specifically, mclbn256
is the
name of the subset of the MCl library containing the support for this
curve.
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 Distributions
Hashes for mclbn256-1.3.2-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 975f49885090ad934a6e270eff87f13ec7c63c3d9fc03f78dc3c6097d98728ef |
|
MD5 | e11891f66685d836e4786e45e98bdccc |
|
BLAKE2b-256 | b1c0e530bad514a3f1686126d17610578a32ce566d9fc93358c483e33878a260 |
Hashes for mclbn256-1.3.2-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 730637bedf46f0468e25d8de7af491e8538850bbf05111a3f95ffb48fe87d7a1 |
|
MD5 | 808356ee3c4e7b15342a07332d677444 |
|
BLAKE2b-256 | 9e7956c20222b580e143b1bc428ff80a34269f6f32dc6e8c1c62f66d9212eeb2 |
Hashes for mclbn256-1.3.2-py3-none-manylinux_2_17_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c83d6b635c875580073f95bc99964980cbcdc8190e3456dab6db586886ff59e1 |
|
MD5 | 00ecc5f2c011c3f795c2e37e585cb437 |
|
BLAKE2b-256 | 9a48a3efd403401fa51a886661178a93fc7210eed77cae92bcd88d076295b257 |
Hashes for mclbn256-1.3.2-py3-none-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d7916ab7d48235741a1e09723f756372e0aca22e10e8580518c5c5a74104a93 |
|
MD5 | 1742a5e1496693e166fbb8904a21969e |
|
BLAKE2b-256 | c31d3cc5fd546b0204059dde564a224e6da1c10f73c33b0216890b1d7f310e69 |
Hashes for mclbn256-1.3.2-py3-none-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9933199d26eb54648f2331c4c1bfe958911bd2f24ba4685109f2c2787259826f |
|
MD5 | 2b6f94fc610ccaa42ce27873a540386e |
|
BLAKE2b-256 | 2e77fbc83a043084cfbecea83e9240ed9ad681f80cbbf21d6a7729fbb3662688 |
Hashes for mclbn256-1.3.2-py3-none-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76721dff6694d669cf8f5a96c658f9ef7fdb247b9735682f6b0155a402c31bb3 |
|
MD5 | 8e9837b3a5943b8c68db0bce20fb7c88 |
|
BLAKE2b-256 | 393cd64d3c41e8c1d67bfdc2f9c6c0175d34ff2d5d878513d049828160278dab |