Python bindings for the BN254/256 pairing-friendly curve supported by the MCl library.
Project description
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-0.8.0-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d02f5327529ffc7a70ada8a48cd896841d13b88013844e54c7caa5a0090f690f |
|
MD5 | 7a04c849227cc762af46d45238703b42 |
|
BLAKE2b-256 | 71605c95f48a23ec41af9f629ea57775be0fae72d9a7c7b2b4b57a69c4f352bc |
Hashes for mclbn256-0.8.0-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 233a2fb43b5804f786b1f3880519baf4d3a0ca297e25c2f687835add834a7f92 |
|
MD5 | a71dd0f50317e8376bbc3efad1b9f128 |
|
BLAKE2b-256 | 7fd71c769067c395c2b7b4ef271620272fd58f3357c6b22ebb2a52a1709288eb |
Hashes for mclbn256-0.8.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6d9a9c11ce3f0f743e17c6bad82ab73bb3b5fb297504c15364b86b296289e87 |
|
MD5 | bea8fb83abb3cd29b37d462ee921e79d |
|
BLAKE2b-256 | 3c1124a529b5b117a139a1f9afaabd5323d4ebf4650d9ffb16b183802c2b5853 |
Hashes for mclbn256-0.8.0-py3-none-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f8e4e991ffc7d0d98dad83400705c608e7cc6683e727ad523ca47825e48a334 |
|
MD5 | 9a890b495b8951ccd6991ef2a7d6a5fc |
|
BLAKE2b-256 | 06cff9cca372a66caacf0596488e9f6e3453c623f3f06b371b128a0ab0afb74c |
Hashes for mclbn256-0.8.0-py3-none-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad3dc36c22c18234b615d6b8d55d42aceac924235a6b37302838b6b478bcb6e9 |
|
MD5 | 2fad8fcbc62c4353cab89fd1f7e2fe60 |
|
BLAKE2b-256 | f7f9b435f97ac3591c3ee4a41fc60a7f6de84bb6cae851fcb900d2a9909e765e |
Hashes for mclbn256-0.8.0-py3-none-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e447cafcec4b5bfb0312b1a5deeaba1dcea52c32bd86dd3bc758b49ec5b42f4c |
|
MD5 | 6bbbd6ce625313fd933b0bed31735bb9 |
|
BLAKE2b-256 | 8f7263608d529db1dd6e0f6501f432d8764ccecf76ba5ecb9b18770fe4c32599 |