Skip to main content

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.

PyPI version and link.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mclbn256-1.1.0-py3-none-win_amd64.whl (768.3 kB view details)

Uploaded Python 3Windows x86-64

mclbn256-1.1.0-py3-none-win32.whl (768.3 kB view details)

Uploaded Python 3Windows x86

mclbn256-1.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

mclbn256-1.1.0-py3-none-macosx_12_0_arm64.whl (862.8 kB view details)

Uploaded Python 3macOS 12.0+ ARM64

mclbn256-1.1.0-py3-none-macosx_11_0_universal2.whl (1.4 MB view details)

Uploaded Python 3macOS 11.0+ universal2 (ARM64, x86-64)

mclbn256-1.1.0-py3-none-macosx_10_15_x86_64.whl (1.4 MB view details)

Uploaded Python 3macOS 10.15+ x86-64

File details

Details for the file mclbn256-1.1.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: mclbn256-1.1.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 768.3 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for mclbn256-1.1.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 a9ecf81556028d9a502b4720e50352a5c305ae3d463de30d1c78dc7062e4be1a
MD5 65bd3783c3c053242a5119973e0594bc
BLAKE2b-256 e3de43ba6a9b9846e28b63b4331d650ffc711729d33ead9ef92c68996afbb420

See more details on using hashes here.

File details

Details for the file mclbn256-1.1.0-py3-none-win32.whl.

File metadata

  • Download URL: mclbn256-1.1.0-py3-none-win32.whl
  • Upload date:
  • Size: 768.3 kB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for mclbn256-1.1.0-py3-none-win32.whl
Algorithm Hash digest
SHA256 f75b45ea48bfb2611a37b63832a71b1bf8b2aadb75e2e2424872600dd7bca3fe
MD5 c9fb34c013511ff57934a09736e40bdf
BLAKE2b-256 1ffa89d21ed8286d5d8fde5d6e508052bd05adea5adea23062e9e11ee82ce769

See more details on using hashes here.

File details

Details for the file mclbn256-1.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mclbn256-1.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 17a776ac4d7ffa2d31d464d1363ccc9a39836f3688143c02d2b35c5f9f113f21
MD5 13762aa84e8f199c95153f792a78ead8
BLAKE2b-256 b631717c0392fd6a6d2276f02948fdaacbd06c8bd33f17207f47a52161c8880a

See more details on using hashes here.

File details

Details for the file mclbn256-1.1.0-py3-none-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for mclbn256-1.1.0-py3-none-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 6f52a0bb5607840a3671a398632e1434ad1ad753a9b1d556d16ef3ec8bd4634e
MD5 e57fcd851511152f91377fd20070dd30
BLAKE2b-256 0d1fe3acfc839dab0d114d1792a9b5378f98d564c8e96e808dcec801ea7d8e2d

See more details on using hashes here.

File details

Details for the file mclbn256-1.1.0-py3-none-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for mclbn256-1.1.0-py3-none-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 4cf2844d553c1755e9bbdb6f6c2e257dd36a087c0b063362ca5e6b5b9eff4f40
MD5 a9e668841ead6773c604d53318bb3159
BLAKE2b-256 d0d10c621a04d61c763900d192eb5d7913d30cbf334332af19346dc18f569f64

See more details on using hashes here.

File details

Details for the file mclbn256-1.1.0-py3-none-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for mclbn256-1.1.0-py3-none-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 cc9809bf4cabb61198070937a620ee13c3636c5355a7395546d56761c3e770ca
MD5 811db91cce6acae5fc907edc6db3bd8f
BLAKE2b-256 de57831a01b7e09f1593fdfe0f69f66742234dbc51f0ffae8dc249ee30bd5a11

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page