JHUISI / charm

Charm: A Framework for Rapidly Prototyping Cryptosystems
http://charm-crypto.io
GNU Lesser General Public License v3.0
542 stars 166 forks source link

Runtime error : pairing.cpython-35m-x86_64-linux-gnu.so: undefined symbol: _Z9zzn4_ssubP4zzn4P4zzn2S0_ #230

Closed greatdreams closed 4 years ago

greatdreams commented 4 years ago

When I use charm framework with MIRACL, runtime error happened, the detail was

/usr/local/lib/python3.5/dist-packages/Charm_Crypto-0.50-py3.5-linux-x86_64.egg/charm/core/math/pairing.cpython-35m-x86_64-linux-gnu.so: undefined symbol: _Z9zzn4_ssubP4zzn4P4zzn2S0_

The step is the following:

  1. copy all source code files from MIRACL-master.zip, downloaded from https://github.com/miracl/MIRACL to the directory charm-dev/charm/core/math/pairing/miracl
  2. compile the MIRACL source code
$ sudo sh compile_miracl.sh bn

this will generate .a file in /usr/lib/local/miracl-bn.a

  1. compile the charm source code and install
    cd charm-dev
    ./configure.sh --enable-pairing-miracl=bn
    make 
    sudo make install
  2. When I tested the installation using the following code, the error happened as the title.
    
    from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair

from charm.config import libs, pairing_lib

if pairing_lib == libs.miracl: params = {'MNT160':80, 'BN256':128, 'SS512':80, 'SS1536':128} print(params)

count = 10

group = PairingGroup("BN256") g = group.random(GT) print(g)


Finally, I find the reason. In the file `compile_miracl.sh`,  `mrzzn4.c` is forgotten to compile.
So the correct script  should be the following

```sh
...
g++ -c -fPIC  -m64 -O2 mrzzn3.c
g++ -c -fPIC  -m64 -O2 mrzzn4.c
g++ -c -fPIC  -m64 -O2 mrecn2.c
...
ar rc miracl.a mrcore.o mrarth0.o mrarth1.o mrarth2.o mralloc.o mrsmall.o mrzzn2.o mrzzn3.o mrzzn4.o
ar r miracl.a mrio1.o mrio2.o mrjack.o mrgcd.o mrxgcd.o mrarth3.o mrbits.o mrecn2.o
....

Test passed, when using the correct script to recompile the MIRACL and reinstall charm.

{'MNT160': 80, 'SS512': 80, 'SS1536': 128, 'BN256': 128}
[[[4561405682220397930295135470714621744140553548382339948396140923205874607457,6147181711063288741160245574953965402199007295443936165645880804469331943741],[3492600582416798826517078933045775955434507152439922502072504270791207884479,11482443920776041334182878901890861490678457198420834281158569875168539951837]],[[12808412157697363729702810084387474646810706050772721494416271324538992737249,16735467784613309274283311146508608853492533244360031295248605231484417916358],[6563136113424435140074056597295590203219952190279619362406319840844907319505,10793248809919934074898766690789537847828640426180763486434642292121807783178]],[[11808293022991017048336321789284959065962558295502866494257561751953372603579,7293147348546447449462883557843345115204634112582930413020910773647984409228],[14851404270283890164720897275195994352490873052726619604629403857041712611525,13775105729246668339947383002182624714470618158866937698407933153305636065519]]]
jakinyele commented 4 years ago

@greatdreams sorry for the delay. thanks!

greatdreams commented 4 years ago

You'are welcome. @jakinyele

alejandro-imt commented 2 years ago

Thank you so much, my friend. Your description solved my problem configuring BN curves of MIRACL for CHARM.

In case this could help others:

In my case, following all the steps in documentation to configure miracl for BN curves, execution of scripts reported problems finding the selected curves. Even though my "configure_miracl.sh" file included the "mrzzn4.c" for compilation, the "-fPIC" g++ parameter was not included. I added it continued the process as indicated in Charm page, and finally worked.

NOTE: Do not forget to run "sudo ldconfig" after all this configuration process to recover the correct system variables for you python version.