Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load shared library by using module ctypes of python #51

Open
knotgrass opened this issue Mar 20, 2023 · 1 comment
Open

Load shared library by using module ctypes of python #51

knotgrass opened this issue Mar 20, 2023 · 1 comment

Comments

@knotgrass
Copy link

I build shared library by using command cd ref && make shared.
The outputs file is

ref/libpqcrystals_aes256ctr_ref.so
ref/libpqcrystals_fips202_ref.so
ref/libpqcrystals_sha2_ref.so
ref/libpqcrystals_kyber512-90s_ref.so
ref/libpqcrystals_kyber512_ref.so
ref/libpqcrystals_kyber768-90s_ref.so
ref/libpqcrystals_kyber768_ref.so
ref/libpqcrystals_kyber1024-90s_ref.so
ref/libpqcrystals_kyber1024_ref.so

After that, I using python try to open these .so file

import os
from ctypes import cdll

shared_lib    = os.path.abspath(os.path.join(__file__, '..', 'ref'))
aes256ctr     = cdll.LoadLibrary(os.path.join(shared_lib, 'libpqcrystals_aes256ctr_ref.so'    ))
fips202       = cdll.LoadLibrary(os.path.join(shared_lib, 'libpqcrystals_fips202_ref.so'      ))
sha2          = cdll.LoadLibrary(os.path.join(shared_lib, 'libpqcrystals_sha2_ref.so'         ))


try: kyber512 = cdll.LoadLibrary(os.path.join(shared_lib, 'libpqcrystals_kyber512_ref.so'))
except Exception as ex: print(ex)


try: kyber512_90s = cdll.LoadLibrary(os.path.join(shared_lib, 'libpqcrystals_kyber512-90s_ref.so'))
except Exception as ex: print(ex)


try: kyber768 = cdll.LoadLibrary(os.path.join(shared_lib, 'libpqcrystals_kyber768_ref.so'))
except Exception as ex: print(ex)


try: kyber768_90s = cdll.LoadLibrary(os.path.join(shared_lib, 'libpqcrystals_kyber768-90s_ref.so'))
except Exception as ex: print(ex)


try: kyber1024 = cdll.LoadLibrary(os.path.join(shared_lib, 'libpqcrystals_kyber1024_ref.so'))
except Exception as ex: print(ex)


try: kyber1024_90s = cdll.LoadLibrary(os.path.join(shared_lib, 'libpqcrystals_kyber1024-90s_ref.so'))
except Exception as ex: print(ex)

And i have a problem

Traceback (most recent call last):
/home/tz/Documents/KYBER/kyber_python/ref/libpqcrystals_kyber512_ref.so: undefined symbol: pqcrystals_kyber_fips202_ref_shake256
/home/tz/Documents/KYBER/kyber_python/ref/libpqcrystals_kyber512-90s_ref.so: undefined symbol: pqcrystals_kyber_aes256ctr_ref_init
/home/tz/Documents/KYBER/kyber_python/ref/libpqcrystals_kyber768_ref.so: undefined symbol: pqcrystals_kyber_fips202_ref_shake256
/home/tz/Documents/KYBER/kyber_python/ref/libpqcrystals_kyber768-90s_ref.so: undefined symbol: pqcrystals_kyber_aes256ctr_ref_init
/home/tz/Documents/KYBER/kyber_python/ref/libpqcrystals_kyber1024_ref.so: undefined symbol: pqcrystals_kyber_fips202_ref_shake256
/home/tz/Documents/KYBER/kyber_python/ref/libpqcrystals_kyber1024-90s_ref.so: undefined symbol: pqcrystals_kyber_aes256ctr_ref_init

I am new in C/C++. Please help me fix these thing.

@knotgrass
Copy link
Author

I edited the Makefile, and It worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant