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

RSA lib cannot find libgmp.so #10

Closed
hcaihao opened this issue May 22, 2017 · 7 comments
Closed

RSA lib cannot find libgmp.so #10

hcaihao opened this issue May 22, 2017 · 7 comments

Comments

@hcaihao
Copy link

hcaihao commented May 22, 2017

local rsa = require "resty.nettle.rsa"

Cause error:

msg : /usr/local/openresty/lualib/resty/nettle/mpz.lua:11: libgmp.so: cannot open shared object file: No such file or directory

Centos 6.5 + nettle 3.3 + lua-resty-nettle 0.98

@hcaihao
Copy link
Author

hcaihao commented May 22, 2017

After I execute

ln -s /usr/local/lib64/libgmp.so.3 /lib64

New error shows:

msg : libhogweed.so: cannot open shared object file: No such file or directory

I find no libhogweed.so file in my system. After I download libhogweed.so file from Internet to lib64 folder, a new file missing again...

msg : libgmp.so.10: cannot open shared object file: No such file or directory

@hcaihao
Copy link
Author

hcaihao commented May 22, 2017

The cmd to install nettle:

wget https://ftp.gnu.org/gnu/nettle/nettle-3.3.tar.gz
tar zxf nettle-3.3.tar.gz && cd nettle-3.3
./configure
make
make install
ln -s /usr/local/lib64/libnettle.so  /lib64

@bungle
Copy link
Owner

bungle commented May 23, 2017

A little bit about dependencies:

Nettle (https://www.lysator.liu.se/~nisse/nettle/) is divided to two libraries: libnettle and libhogweed. Both come with the same sources (or install). libnettle does not have any external dependencies, but libhogweed does depend on GMP (https://gmplib.org/).

Both Nettle and GMP are usually generally available in your operating system packages, e.g.:

macOS:

brew install gmp
brew install nettle

Ubuntu:

sudo apt install libgmp10
sudo apt install libnettle6
sudo apt install libhogweed4

And you can build it from the sources as well. Please make sure you add the libraries in your system library path (not the package.cpath). But it is your responsibility to make sure that you have the required dependencies (and correct versions of them).

And to let you know, I just released a new version 0.99 that contains a bit more robust library loading: 15ed9f5

Let me know if that helps.

@bungle
Copy link
Owner

bungle commented May 23, 2017

libhogweed comes with Nettle sources. When you build Nettle it will produce two libraries: libnettle and libhogweed.

@hcaihao
Copy link
Author

hcaihao commented May 23, 2017

Thank you! After I install gmp-6.1.2 and update glibc to 2.14, the "resty.nettle.rsa" lib load successfully.

But when I run the sample code, I got a new error:

    local rsa = require "resty.nettle.rsa"
    local hex = require "resty.nettle.base16"
    local kp = rsa.keypair.new()
    ngx.say(hex.encode(kp.sexp))
    kp:clear()

attempt to call method 'clear' (a nil value)

@hcaihao
Copy link
Author

hcaihao commented May 23, 2017

Another question: How to en/decrypt using my given n/p/q/d/e?

--decimal

n("100888004757403126382886865105241158432730176062295033309000746455988298951828966091095481424873115498597115470207409736120641179528187079237478715189605733459515461116155773704429850150652890842508460527885968744169102941134604514003901153455056079756503035208208397983837095373331913496470006600336138889979");

p("10037193205433537850159355577976209042329445854157281393122190492869599322079147267686871580259251400550761763461564161492285436114129538845695257619405147");

q("10051416037581938434241420294098997568255976738842428014184520954485803895241198438012218427444035054914650416633597255584935142918297111815841382589957857");

d("5934588515141360375463933241484774025454716238958531371117690967999311703048762711240910672051359735211595027659259396242390657619305122308086983246447394904170954005922322900214939886790957662181521619304503613968097387395963952568129144374414610380591033517413429577789412832514875357048196768452701736881");

e("17");

@bungle
Copy link
Owner

bungle commented May 23, 2017

@hcaihao yes, no need to call clear (it doesn't exist anymore in API), it was removed as it is called automatically on GC.

@hcaihao hcaihao closed this as completed May 25, 2017
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

2 participants