mikejsavage / lua-bcrypt Goto Github PK
View Code? Open in Web Editor NEWA bcrypt library for Lua
License: Other
A bcrypt library for Lua
License: Other
Can I ask you to create a new release that includes my recent changes (ba9c64c)?
I'm not sure if this is a lua-bcrypt issue or is based on a misconfiguration of my system. Has anyone seen this problem?
I installed lua-bcrypt via LuaRocks. This script
local bcrypt = require "bcrypt"
local digest = bcrypt.digest("monkey123", 4)
print(digest)
print(bcrypt.verify("monkey123", digest))
print(bcrypt.verify("chimp456", digest))
Fails for me on Windows with the error
c:\lua\bin\lua.exe: error loading module 'bcrypt' from file 'C:/lua/rocks/lib/lua/5.4/bcrypt.dll':
The specified procedure could not be found.
The same script works fine on MacOS, not tested on Linux.
Dependencies.exe shows bcrypt.dll depending recursively on bcrypt.dll, which made me think it's not finding the Windows native bcrypt.dll.
The following script
-- load the Windows bcrypt.dll first so that Lua's bcrypt.dll dependency is resolved
local windows_bcrypt = package.searchpath("bcrypt", "C:/windows/system32/bcrypt.dll")
if windows_bcrypt then
package.loadlib(windows_bcrypt, "*")
end
local bcrypt = require "bcrypt"
local digest = bcrypt.digest("monkey123", 4)
print(digest)
print(bcrypt.verify("monkey123", digest))
print(bcrypt.verify("chimp456", digest))
works fine, producing
$2b$04$huQDeLD6gd6fEJGTHyXJSuUWnxvMeR7G9PyvlQtaJA2XdbK18/8ki
true
false
as expected.
So...
is this a lua-bcrypt issue or is my system config goobered up somehow?
Ahoy! Thanks for a useful library!
musl based builds break here:
include/pwd.h:93:14: error: expected ';' before 'struct'
__BEGIN_DECLS
^
;
struct passwd *getpwuid(uid_t);
~~~~~~
because of __BEGIN_DECLS
According to the musl c library FAQ this is an issue with lua-bcrypt in this case. Would you be willing to to make the substitutions mentioned here:
https://wiki.musl-libc.org/faq.html
which is to :
replace all occurrences of:
__BEGIN_DECLS
with
#ifdef __cplusplus
extern "C" {
#endif
and all occurrences of
__END_DECLS
with
#ifdef __cplusplus
}
#endif
Thanks!
Before linux kernel 3.17, the syscall getrandom
is not supported.
I noticed that before v2.1, if getrandom
is not supported, it will fallback to use /dev/urandom
, but it's removed from v2.2.
I wonder why this fallback mechanism was removed.
Hello,
this library is really useful. Could you add it to LuaRocks please?
In the library, you open /dev/urandom
and never close it.
This results in a file descriptor leak, e.g.:
nginx 19909 http 783r CHR 1,9 0t0 1033 /dev/urandom
nginx 19909 http 784r CHR 1,9 0t0 1033 /dev/urandom
nginx 19909 http 785r CHR 1,9 0t0 1033 /dev/urandom
nginx 19909 http 786r CHR 1,9 0t0 1033 /dev/urandom
nginx 19909 http 787r CHR 1,9 0t0 1033 /dev/urandom
I think it would be cleaner to open and close it for each bcrypt.salt
call instead of using a global file descriptor.
Warning: variable CFLAGS was not passed in build_variables
gcc -I/usr/local/include/luajit-2.1 -DOPENSSL_cleanse=explicit_bzero -D__BSD_VISIBLE -DHAVE_STRNDUP -Iinclude -Wall -Wno-pointer-sign -O2 -fPIC -DNDEBUG -O0 -c -o compat/safebfuns.o compat/safebfuns.c
gcc -I/usr/local/include/luajit-2.1 -DOPENSSL_cleanse=explicit_bzero -D__BSD_VISIBLE -DHAVE_STRNDUP -Iinclude -Wall -Wno-pointer-sign -O2 -fPIC -DNDEBUG -c -o compat/bcrypt/bcrypt.o compat/bcrypt/bcrypt.c
In file included from compat/bcrypt/bcrypt.c:37:
include/pwd.h:93:14: error: expected ';' before 'struct'
__BEGIN_DECLS
^
;
struct passwd *getpwuid(uid_t);
~~~~~~
include/pwd.h:114:12: error: expected ';' before 'typedef'
__END_DECLS
^
;
make: *** [<builtin>: compat/bcrypt/bcrypt.o] Error 1
Error: Build error: Failed building.
I am trying to install lua-bcrypt using luarocks, but the building process is failing:
installing https://luarocks.org/bcrypt-2.1-3.src.rock... Using https://luarocks.org/bcrypt-2.1-3.src.rock... switching to 'build' mode Warning: variable CFLAGS was not passed in build_variables env MACOSX_DEPLOYMENT_TARGET=10.8 gcc -I/usr/local/include -DOPENSSL_cleanse=explicit_bzero -D__BSD_VISIBLE -DHAVE_STRNDUP -Iinclude -Wall -Wno-pointer-sign -O2 -fPIC -DNDEBUG -O0 -c -o compat/safebfuns.o compat/safebfuns.c env MACOSX_DEPLOYMENT_TARGET=10.8 gcc -I/usr/local/include -DOPENSSL_cleanse=explicit_bzero -D__BSD_VISIBLE -DHAVE_STRNDUP -Iinclude -Wall -Wno-pointer-sign -O2 -fPIC -DNDEBUG -c -o compat/bcrypt/bcrypt.o compat/bcrypt/bcrypt.c env MACOSX_DEPLOYMENT_TARGET=10.8 gcc -I/usr/local/include -DOPENSSL_cleanse=explicit_bzero -D__BSD_VISIBLE -DHAVE_STRNDUP -Iinclude -Wall -Wno-pointer-sign -O2 -fPIC -DNDEBUG -c -o compat/bcrypt/blowfish.o compat/bcrypt/blowfish.c env MACOSX_DEPLOYMENT_TARGET=10.8 gcc -I/usr/local/include -DOPENSSL_cleanse=explicit_bzero -D__BSD_VISIBLE -DHAVE_STRNDUP -Iinclude -Wall -Wno-pointer-sign -O2 -fPIC -DNDEBUG -c -o compat/arc4random/arc4random.o compat/arc4random/arc4random.c env MACOSX_DEPLOYMENT_TARGET=10.8 gcc -I/usr/local/include -DOPENSSL_cleanse=explicit_bzero -D__BSD_VISIBLE -DHAVE_STRNDUP -Iinclude -Wall -Wno-pointer-sign -O2 -fPIC -DNDEBUG -c -o compat/strlcpy.o compat/strlcpy.c env MACOSX_DEPLOYMENT_TARGET=10.8 gcc -I/usr/local/include -DOPENSSL_cleanse=explicit_bzero -D__BSD_VISIBLE -DHAVE_STRNDUP -Iinclude -Wall -Wno-pointer-sign -O2 -fPIC -DNDEBUG -c -o compat/sha/sha512.o compat/sha/sha512.c compat/sha/sha512.c:13:10: fatal error: 'openssl/opensslconf.h' file not found
I have openssl (installed via homebrew) but it is not located under /usr/local/ (it is instead at /usr/local/opt/). From what I understand, you are not exposing the OPENSSL_DIR in your rockspec file, so I cannot do something like:
luarocks install bcrypt OPENSSL_DIR=/usr/local/opt/
as other luarocks module allow (luasec module is an example that allows us to do that).
Error from luarocks install bcrypt on OS X:
Installing https://rocks.moonscript.org/bcrypt-1.5-1.src.rock...
Using https://rocks.moonscript.org/bcrypt-1.5-1.src.rock... switching to 'build' mode
Warning: variable CFLAGS was not passed in build_variables
export MACOSX_DEPLOYMENT_TARGET=10.5; gcc -O2 -shared -fPIC -std=c99 -D_GNU_SOURCE -Wall -Wextra -Wno-nonnull -Wwrite-strings -Wformat=2 -DNDEBUG -Ilib/bcrypt -I/usr/local/opt/lua/include -c -o src/main.o src/main.c
clang: warning: argument unused during compilation: '-shared'
make -C lib/bcrypt
export MACOSX_DEPLOYMENT_TARGET=10.5; gcc -c -W -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-prototypes -Wstrict-prototypes -Wshadow -Wundef -Wpointer-arith -O2 -fomit-frame-pointer -funroll-loops -fPIC crypt_blowfish.c
crypt_blowfish.c:898:24: warning: cast from 'const char _' to 'const BF_word *' (aka 'const unsigned int *') increases
required alignment from 1 to 4 [-Wcast-align]
BF_encode(&output[7], (const BF_word *)input, 16);
^~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
export MACOSX_DEPLOYMENT_TARGET=10.5; gcc -c x86.S
export MACOSX_DEPLOYMENT_TARGET=10.5; gcc -c -W -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-prototypes -Wstrict-prototypes -Wshadow -Wundef -Wpointer-arith -O2 -fomit-frame-pointer -funroll-loops -fPIC crypt_gensalt.c
export MACOSX_DEPLOYMENT_TARGET=10.5; gcc -c -W -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-prototypes -Wstrict-prototypes -Wshadow -Wundef -Wpointer-arith -O2 -fomit-frame-pointer -funroll-loops -fPIC wrapper.c
export MACOSX_DEPLOYMENT_TARGET=10.5; gcc -o bcrypt.so src/main.o lib/bcrypt/crypt_blowfish.o lib/bcrypt/x86.o lib/bcrypt/crypt_gensalt.o lib/bcrypt/wrapper.o -O2 -shared -fPIC -std=c99 -D_GNU_SOURCE -Wall -Wextra -Wno-nonnull -Wwrite-strings -Wformat=2 -DNDEBUG -Ilib/bcrypt -I/usr/local/opt/lua/include
Undefined symbols for architecture x86_64:
"_luaL_checkinteger", referenced from:
_luabcrypt_salt in main.o
"_luaL_checklstring", referenced from:
_luabcrypt_digest in main.o
_luabcrypt_verify in main.o
_luabcrypt_random in main.o
"_luaL_setfuncs", referenced from:
_luaopen_bcrypt in main.o
"_lua_createtable", referenced from:
_luaopen_bcrypt in main.o
"_lua_error", referenced from:
_luaopen_bcrypt in main.o
_luabcrypt_digest in main.o
_luabcrypt_salt in main.o
_luabcrypt_random in main.o
"_lua_pushboolean", referenced from:
_luabcrypt_verify in main.o
"_lua_pushstring", referenced from:
_luaopen_bcrypt in main.o
_luabcrypt_digest in main.o
_luabcrypt_salt in main.o
_luabcrypt_random in main.o
"_lua_tointegerx", referenced from:
luabcrypt_digest in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: ** [bcrypt.so] Error 1
Error: Build error: Failed building.
Removing '-static' from Makefile and adding '-bundle -undefined dynamic_lookup' fixes problem.
I really need to use bcrypt without using a salt. I have a particular project that needs hashes without a salt. Is that possible?
When luarocks is locally installed and pointing at luajit the lua.h file is not found. Setting the path there manually in C_INCLUDE_PATH is a workaround.
But the compile still fails on:
gcc -o bcrypt.so src/main.c lib/bcrypt/crypt_blowfish.o lib/bcrypt/x86.o lib/bcrypt/crypt_gensalt.o lib/bcrypt/wrapper.o -O2 -shared -fPIC -fomit-frame-pointer -funroll-loops -lcrypto -Ilib/bcrypt -Wall -Wextra -Werror -Wbad-function-cast -Wcast-align -Wcast-qual -Wstrict-prototypes -Wshadow -Wundef -Wpointer-arith src/main.c: In function ‘randomBytes’: src/main.c:39:6: error: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Werror=unused-result] cc1: all warnings being treated as errors make: *** [bcrypt] Error 1
Is there a special reason to ignore the return value here?
Thanks for the helpful bcrypt binding work by-the-way!
Hello! I need some help getting bcrypt to work :)
It works fine on my machine (osx), but not on Travis CI precise environment (ubuntu 12.04):
error loading module 'bcrypt' from file '/home/travis/build/sailorproject/sailor/install/luarocks/lib/lua/5.1/bcrypt.so':
/home/travis/build/sailorproject/sailor/install/luarocks/lib/lua/5.1/bcrypt.so: undefined symbol: clock_gettime
https://travis-ci.org/sailorproject/sailor/jobs/109013322
Line 165 shows gcc version is 4.6.3
Line 306 shows libc6 version is 2.15
Updating gcc did not solve the problem
I tried many things but I did not succeed in updating libc6
I noticed you do add -lrt flag on compiling, I thought it should be enough, but well, I dont know what's going on then...
This is the luarocks output when installing bcrypt on travis machine
Using https://luarocks.org/bcrypt-2.1-2.src.rock... switching to 'build' mode
Warning: variable CFLAGS was not passed in build_variables
gcc -I/home/travis/build/sailorproject/sailor/install/lua/include -DOPENSSL_cleanse=explicit_bzero -D__BSD_VISIBLE -DHAVE_STRNDUP -Iinclude -Wall -Wno-pointer-sign -O2 -fPIC -DNDEBUG -O0 -c -o compat/safebfuns.o compat/safebfuns.c
gcc -I/home/travis/build/sailorproject/sailor/install/lua/include -DOPENSSL_cleanse=explicit_bzero -D__BSD_VISIBLE -DHAVE_STRNDUP -Iinclude -Wall -Wno-pointer-sign -O2 -fPIC -DNDEBUG -c -o compat/bcrypt/bcrypt.o compat/bcrypt/bcrypt.c
gcc -I/home/travis/build/sailorproject/sailor/install/lua/include -DOPENSSL_cleanse=explicit_bzero -D__BSD_VISIBLE -DHAVE_STRNDUP -Iinclude -Wall -Wno-pointer-sign -O2 -fPIC -DNDEBUG -c -o compat/bcrypt/blowfish.o compat/bcrypt/blowfish.c
gcc -I/home/travis/build/sailorproject/sailor/install/lua/include -DOPENSSL_cleanse=explicit_bzero -D__BSD_VISIBLE -DHAVE_STRNDUP -Iinclude -Wall -Wno-pointer-sign -O2 -fPIC -DNDEBUG -c -o compat/arc4random/arc4random.o compat/arc4random/arc4random.c
gcc -I/home/travis/build/sailorproject/sailor/install/lua/include -DOPENSSL_cleanse=explicit_bzero -D__BSD_VISIBLE -DHAVE_STRNDUP -Iinclude -Wall -Wno-pointer-sign -O2 -fPIC -DNDEBUG -c -o compat/strlcpy.o compat/strlcpy.c
gcc -I/home/travis/build/sailorproject/sailor/install/lua/include -DOPENSSL_cleanse=explicit_bzero -D__BSD_VISIBLE -DHAVE_STRNDUP -Iinclude -Wall -Wno-pointer-sign -O2 -fPIC -DNDEBUG -c -o compat/sha/sha512.o compat/sha/sha512.c
gcc -I/home/travis/build/sailorproject/sailor/install/lua/include -DOPENSSL_cleanse=explicit_bzero -D__BSD_VISIBLE -DHAVE_STRNDUP -Iinclude -Wall -Wno-pointer-sign -O2 -fPIC -DNDEBUG -c -o compat/getentropy/getentropy_linux.o compat/getentropy/getentropy_linux.c
gcc -I/home/travis/build/sailorproject/sailor/install/lua/include -DOPENSSL_cleanse=explicit_bzero -D__BSD_VISIBLE -DHAVE_STRNDUP -Iinclude -Wall -Wno-pointer-sign -O2 -fPIC -DNDEBUG -c -o src/main.o src/main.c
gcc -o bcrypt.so -shared -lrt compat/safebfuns.o compat/bcrypt/bcrypt.o compat/bcrypt/blowfish.o compat/arc4random/arc4random.o compat/strlcpy.o compat/sha/sha512.o compat/getentropy/getentropy_linux.o src/main.o
Updating manifest for /home/travis/build/sailorproject/sailor/install/luarocks/lib/luarocks/rocks
bcrypt 2.1-2 is now built and installed in /home/travis/build/sailorproject/sailor/install/luarocks (license: ISC)
Thanks for your help :)
Installing bcrypt on Raspbian via # luarocks install bcrypt
will result in the following error when trying to use it in a lua script:
lua: error loading module 'bcrypt' from file '/usr/local/lib/lua/5.1/bcrypt.so':
/usr/local/lib/lua/5.1/bcrypt.so: undefined symbol: clock_gettime
Apparently, Raspbian uses an old glibc version (2.13). Versions older than 2.17 will need an additional -lrt
linker flag for this to work, as far as I can tell from googling this issue.
I downloaded and unpacked the rock and put a LDFLAGS += -lrt
into the Makefile.mess file. After building and installing it through luarocks it seems to run fine on my Raspberry now.
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.