bungle / lua-resty-nettle

LuaJIT FFI bindings for Nettle (a low-level cryptographic library)
BSD 2-Clause "Simplified" License
182 stars 45 forks source link

RSA lib cannot find libgmp.so #10

Closed hcaihao closed 7 years ago

hcaihao commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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: https://github.com/bungle/lua-resty-nettle/commit/15ed9f5c4af6dfd5063c7c9bff31a921ed0c21bf

Let me know if that helps.

bungle commented 7 years ago

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

hcaihao commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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