A bilinear pairing library for petlib
Documentation: http://bplib.readthedocs.io/en/latest/
Pypi package: https://pypi.python.org/pypi/bplib
Based on Diego Aranha's OpenPairing: https://github.com/dfaranha/OpenPairing
A bilinear pairing library for petlib
A bilinear pairing library for petlib
Documentation: http://bplib.readthedocs.io/en/latest/
Pypi package: https://pypi.python.org/pypi/bplib
Based on Diego Aranha's OpenPairing: https://github.com/dfaranha/OpenPairing
Ok, so we have now upgraded to support OpenSSL 1.1 API, but in the process the support for OpenSSL 1.0 was broken. Have a look at the failing Travis test, and despair. This is likely to require a conditional compilation directive to hide the bignum_st structure redefinition and also a conditional compilation directive to use old-style locking for the G2_mul pre-computations.
Failing travis tests:
https://travis-ci.org/gdanezis/bplib
Hello. I`am sorry for my probably stupid question.
Why method BpGroup.hashG1 is exist for hashing message but method BpGroup.hashG2 not exist?
What is reason for it?
Thanks!
Looks like the Bilinear Mapping has two different groups G1 and G2 mapping to GT. But I want a mapping from G and G to GT. So, is it possible for me give a different value (curve ID) for nid and get one ? But I don't see curve IDs as integers. I see them as "fp254bnb". And you have provided it as an integer value for default value, which is 1. Does that mean we get something else for value 0 ? A non fp254bnb curve ? what does that mean ?
Would be great to have encode
and decode
functions as in petlib.pack
; even better, pack functions that are compatible across petlib and bplib.
Greetings,
I search for my thesis a lib for the pairing issues of a protocol, which i would to implement in python. Now I found this
project and i ask myself, if this still working and running on newer schemes or curves?
best regards
Following the documentation we have
G = bp.BpGroup()
that gives this output AttributeError: module 'bplib' has no attribute 'BpGroup'
I suggest to update the documentation to fit the lib;
one should go deeper to call methods
import bplib
G = bplib.bp.BpGroup()
print(G.order())
Hi, first thanks for this library. I found it to be very interesting and easy to use (although I'm not full expert in Pairing-based)
I'm implementing the BBS signature and found out that negative ZP elements returns negative number.
This breaks the equality of bilinearity operation, aka e(-k.P,Q) != e(P,Q)**(-k)
If I do, j = -k % o, then e(j.P,Q) == e(P,Q)**j
After calling python3 examples/PSSig.py
, I met the following error:
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/bplib-0.0.6-py3.10-macosx-10.9-universal2.egg/bplib/_bplib.abi3.so, 2): Symbol not found: _ERR_new
Referenced from: /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/bplib-0.0.6-py3.10-macosx-10.9-universal2.egg/bplib/_bplib.abi3.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/bplib-0.0.6-py3.10-macosx-10.9-universal2.egg/bplib/_bplib.abi3.so
May I ask if there are any solutions to this problem? I am using a MacBook Pro (not M1/M2), with BigSur v11.2.2.
Thank you.
Hi, when I try to install bplib on Ubuntu 22.04, I get this error:
bplib/src/bp_fp2.c: In function ‘FP2_zero’:
bplib/src/bp_fp2.c:111:9: error: invalid use of void expression
111 | if (!BN_zero(a->f[0]) || !BN_zero(a->f[1]))
| ^
bplib/src/bp_fp2.c:111:30: error: invalid use of void expression
111 | if (!BN_zero(a->f[0]) || !BN_zero(a->f[1]))
| ^
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
[end of output]
I searched for this problem online and it seems that OpenSSL changed the behavior of BN_zero
which no longer returns a success integer. They essentially changed BN_zero
to do what BN_zero_ex
used to do.
For an ultra quick fix I changed the following and it seems to work:
index 6d7d1c7..062dd32 100644
--- a/bplib/src/bp_fp2.c
+++ b/bplib/src/bp_fp2.c
@@ -108,8 +108,9 @@ void FP2_clear_free(FP2 *a)
int FP2_zero(FP2 *a)
{
- if (!BN_zero(a->f[0]) || !BN_zero(a->f[1]))
- return 0;
+ BN_zero(a->f[0]);
+ BN_zero(a->f[1]);
+
return 1;
}
Is there any way to generate a symmetric pairing function? As in G1=G2?
When I am installing in my pc with win 10 ,it's error :
` Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "d:\python3\lib\site-packages\setuptools\sandbox.py", line 154, in save_modules
yield saved
File "d:\python3\lib\site-packages\setuptools\sandbox.py", line 195, in setup_context
yield
File "d:\python3\lib\site-packages\setuptools\sandbox.py", line 250, in run_setup
_execfile(setup_script, ns)
File "d:\python3\lib\site-packages\setuptools\sandbox.py", line 45, in execfile
exec(code, globals, locals)
File "C:\Users\12711\AppData\Local\Temp\easy_install-lzkw1izd\petlib-0.0.45\setup.py", line 40, in
],
File "d:\python3\lib\site-packages\setuptools_init.py", line 143, in setup
return distutils.core.setup(**attrs)
File "d:\python3\lib\distutils\core.py", line 108, in setup
_setup_distribution = dist = klass(attrs)
File "d:\python3\lib\site-packages\setuptools\dist.py", line 442, in init
k: v for k, v in attrs.items()
File "d:\python3\lib\distutils\dist.py", line 281, in init
self.finalize_options()
File "d:\python3\lib\site-packages\setuptools\dist.py", line 601, in finalize_options
ep.load()(self, ep.name, value)
File "d:\python3\lib\site-packages\cffi\setuptools_ext.py", line 217, in cffi_modules
add_cffi_module(dist, cffi_module)
File "d:\python3\lib\site-packages\cffi\setuptools_ext.py", line 49, in add_cffi_module
execfile(build_file_name, mod_vars)
File "d:\python3\lib\site-packages\cffi\setuptools_ext.py", line 25, in execfile
exec(code, glob, glob)
File "petlib/compile.py", line 34, in
File "d:\python3\lib\os.py", line 669, in getitem
raise KeyError(key) from None
KeyError: 'OPENSSL_CONF'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\12711\AppData\Local\Temp\pip-install-575rjrxd\bplib\setup.py", line 41, in <module>
zip_safe=False,
File "d:\python3\lib\site-packages\setuptools\__init__.py", line 142, in setup
_install_setup_requires(attrs)
File "d:\python3\lib\site-packages\setuptools\__init__.py", line 137, in _install_setup_requires
dist.fetch_build_eggs(dist.setup_requires)
File "d:\python3\lib\site-packages\setuptools\dist.py", line 586, in fetch_build_eggs
replace_conflicting=True,
File "d:\python3\lib\site-packages\pkg_resources\__init__.py", line 780, in resolve
replace_conflicting=replace_conflicting
File "d:\python3\lib\site-packages\pkg_resources\__init__.py", line 1063, in best_match
return self.obtain(req, installer)
File "d:\python3\lib\site-packages\pkg_resources\__init__.py", line 1075, in obtain
return installer(requirement)
File "d:\python3\lib\site-packages\setuptools\dist.py", line 653, in fetch_build_egg
return cmd.easy_install(req)
File "d:\python3\lib\site-packages\setuptools\command\easy_install.py", line 679, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File "d:\python3\lib\site-packages\setuptools\command\easy_install.py", line 705, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "d:\python3\lib\site-packages\setuptools\command\easy_install.py", line 890, in install_eggs
return self.build_and_install(setup_script, setup_base)
File "d:\python3\lib\site-packages\setuptools\command\easy_install.py", line 1158, in build_and_install
self.run_setup(setup_script, setup_base, args)
File "d:\python3\lib\site-packages\setuptools\command\easy_install.py", line 1144, in run_setup
run_setup(setup_script, args)
File "d:\python3\lib\site-packages\setuptools\sandbox.py", line 253, in run_setup
raise
File "d:\python3\lib\contextlib.py", line 99, in __exit__
self.gen.throw(type, value, traceback)
File "d:\python3\lib\site-packages\setuptools\sandbox.py", line 195, in setup_context
yield
File "d:\python3\lib\contextlib.py", line 99, in __exit__
self.gen.throw(type, value, traceback)
File "d:\python3\lib\site-packages\setuptools\sandbox.py", line 166, in save_modules
saved_exc.resume()
File "d:\python3\lib\site-packages\setuptools\sandbox.py", line 141, in resume
six.reraise(type, exc, self._tb)
File "d:\python3\lib\site-packages\setuptools\_vendor\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "d:\python3\lib\site-packages\setuptools\sandbox.py", line 154, in save_modules
yield saved
File "d:\python3\lib\site-packages\setuptools\sandbox.py", line 195, in setup_context
yield
File "d:\python3\lib\site-packages\setuptools\sandbox.py", line 250, in run_setup
_execfile(setup_script, ns)
File "d:\python3\lib\site-packages\setuptools\sandbox.py", line 45, in _execfile
exec(code, globals, locals)
File "C:\Users\12711\AppData\Local\Temp\easy_install-lzkw1izd\petlib-0.0.45\setup.py", line 40, in <module>
],
File "d:\python3\lib\site-packages\setuptools\__init__.py", line 143, in setup
return distutils.core.setup(**attrs)
File "d:\python3\lib\distutils\core.py", line 108, in setup
_setup_distribution = dist = klass(attrs)
File "d:\python3\lib\site-packages\setuptools\dist.py", line 442, in __init__
k: v for k, v in attrs.items()
File "d:\python3\lib\distutils\dist.py", line 281, in __init__
self.finalize_options()
File "d:\python3\lib\site-packages\setuptools\dist.py", line 601, in finalize_options
ep.load()(self, ep.name, value)
File "d:\python3\lib\site-packages\cffi\setuptools_ext.py", line 217, in cffi_modules
add_cffi_module(dist, cffi_module)
File "d:\python3\lib\site-packages\cffi\setuptools_ext.py", line 49, in add_cffi_module
execfile(build_file_name, mod_vars)
File "d:\python3\lib\site-packages\cffi\setuptools_ext.py", line 25, in execfile
exec(code, glob, glob)
File "petlib/compile.py", line 34, in <module>
File "d:\python3\lib\os.py", line 669, in __getitem__
raise KeyError(key) from None
KeyError: 'OPENSSL_CONF'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\12711\AppData\Local\Temp\pip-install-575rjrxd\bplib`
Long error code, the core of it is below:
In file included from bplib/src/bp_fp12.c:66:
include/bp_lcl.h:72:8: error: redefinition of 'bignum_st'
struct bignum_st {
^
/usr/local/opt/openssl/include/openssl/bn.h:313:8: note: previous definition is here
struct bignum_st {
^
1 error generated.
error: command '/usr/bin/gcc' failed with exit status 1
I'm trying to ensure my implementation of Coconut in Go is consistent and fully compatible (if used on BN254 curve) with the one created in Python, however, I've stumbled upon an implementation issue that goes all the way to bplib, such that I can't modify my own code to make it compatible.
Basically the issue comes from the ways openSSL and amcl recover a BigNum from bytes. OpenSSL (and by extension bplib), from what I've figured, allows an arbitrary long array of bytes and creates an equally long Bn, while amcl ignores chunks that are beyond number of bytes used by a particular curve (in the case of BN254, 32bytes). And so it would be ideal if they would always be given such inputs that they would produce same results.
The problematic code in question is the following: https://github.com/gdanezis/bplib/blob/master/bplib/bp.py#L141
while ret == 0:
xhash = sha512(xhash).digest()
x = Bn.from_binary(xhash) % self.p
ret = _C.G1_ELEM_set_compressed_coordinates(self.bpg, pt.elem, x.bn, y, _FFI.NULL)
SHA512 by definition produces a 64byte length result, which when converted into a BigNum produces the described issue as amcl only considers first 32bytes of the resultant hash.
The two solutions that I've tested to be fully working (for both implementations) were to either introduce a flag to set the hash algorithm used or to keep SHA512 but truncate the result to however many bytes particular curve uses before converting it to BigNum.:
Solution 1:
while ret == 0:
if SHA_FLAG == SHA256:
xhash = sha256(xhash).digest()
elif SHA_FLAG == SHA386:
xhash = sha386(xhash).digest()
else:
xhash = sha512(xhash).digest()
x = Bn.from_binary(xhash) % self.p
ret = _C.G1_ELEM_set_compressed_coordinates(self.bpg, pt.elem, x.bn, y, _FFI.NULL)
Solution 2 (with additional C binding):
while ret == 0:
xhash = sha512(xhash).digest()
xhash = xhash[:num_bytes]
x = Bn.from_binary(xhash) % self.p
ret = _C.G1_ELEM_set_compressed_coordinates(self.bpg, pt.elem, x.bn, y, _FFI.NULL)
note that number of bytes used by a curve is stored in BN_BYTES
constant (or via BN_num_bytes()
function), which would probably require an additional C binding to obtain.
Solution 2 (without any more bindings):
while ret == 0:
xhash = sha512(xhash).digest()
if self.nid == NID_fp254bnb: # basically hardcoding the lenghts
xhash_trunc = xhash[:32]
elif:
...
x = Bn.from_binary(xhash_trunc) % self.p
ret = _C.G1_ELEM_set_compressed_coordinates(self.bpg, pt.elem, x.bn, y, _FFI.NULL)
Do you think it would be possible to introduce either of those changes?
I got this error when trying pip install bplib
OS High Sierra 10.13.6...
clang -bundle -undefined dynamic_lookup -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk build/temp.macosx-10.13-x86_64-2.7/build/temp.macosx-10.13-x86_64-2.7/bplib._bplib.o build/temp.macosx-10.13-x86_64-2.7/bplib/src/bp_fp12.o build/temp.macosx-10.13-x86_64-2.7/bplib/src/bp_fp6.o build/temp.macosx-10.13-x86_64-2.7/bplib/src/bp_g2.o build/temp.macosx-10.13-x86_64-2.7/bplib/src/bp_group.o build/temp.macosx-10.13-x86_64-2.7/bplib/src/bp_map.o build/temp.macosx-10.13-x86_64-2.7/bplib/src/bp_fp2.o build/temp.macosx-10.13-x86_64-2.7/bplib/src/bp_g1.o build/temp.macosx-10.13-x86_64-2.7/bplib/src/bp_g2_mult.o build/temp.macosx-10.13-x86_64-2.7/bplib/src/bp_gt.o -lcrypto -o build/lib.macosx-10.13-x86_64-2.7/bplib/_bplib.so ld: library not found for -lcrypto clang: error: linker command failed with exit code 1 (use -v to see invocation) error: command 'clang' failed with exit status 1
I tried several options (below) for linking the headers and libs from openssl but to no avail, will continue to investigate.
https://stackoverflow.com/questions/8829670/openssl-link-options-lssl-and-lcrypto-in-gcc
https://medium.com/@timmykko/using-openssl-library-with-macos-sierra-7807cfd47892
Hello !
I noticed that exponentiating a GT element by 0 gave the same result as exponentiating by 1 (identity). As a consequence, the following code returns False:
G = BpGroup()
g = G.pair(G.gen1(), G.gen2())
g** 0 == g.one(G)
So does this one :
g** (-2) * g** (2) == g** 0
But these all return True:
g** 0 == g
g** 1 == g
g** (-2) * g** (2) == g.one(G)
Installation through pip install bplib
doesn't work on macOS; however cloning the repo and executing python setup.py install
works fine.
Tested with python 2.7 and python 3 on macOS High Sierra. Here is the error:
build/temp.macosx-10.13-x86_64-3.6/bplib._bplib.c:483:10: fatal error: 'openssl/crypto.h' file not found
#include <openssl/crypto.h>
^~~~~~~~~~~~~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1
----------------------------------------
Failed building wheel for bplib
Running setup.py clean for bplib
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.