mkottman / luacrypto Goto Github PK
View Code? Open in Web Editor NEWFork of LuaCrypto, which enables encryption and decryption through OpenSSL
Home Page: http://mkottman.github.com/luacrypto/
License: MIT License
Fork of LuaCrypto, which enables encryption and decryption through OpenSSL
Home Page: http://mkottman.github.com/luacrypto/
License: MIT License
The example is too less. I try so many time but failure.
It seems this is no longer maintained.
To prevent confusion, could you officially deprecate the library?
FWIW, I've now switched over to luaossl.
Can you please make this change in the mainline rockspec?
Hi Michal, I'm trying to install luacrypto by using luarocks in Ubuntu 16.10. I first installed luarocks then I tried running
luarocks install lapis
but I got an error message saying that the luacrypto package couldn't be installed because it couldn't find the evp.h file of openssl.
So, as suggested in the error message, I tried with
luarocks install luacrypto OPENSSL_DIR=/usr/local OPENSSL_LIBDIR=/usr/local/ssl/ lib OPENSSL_INCDIR=/usr/local/ssl/ include
This time I got the following output and error message:
Installing https://rocks.moonscript.org/luacrypto-0.3.2-2.src.rock...
Using https://rocks.moonscript.org/luacrypto-0.3.2-2.src.rock... switching to 'build' mode
gcc -O2 -fPIC -I/usr/include/lua5.1 -c src/lcrypto.c -o src/lcrypto.o -I/usr/local/ssl/include
gcc -shared -o crypto.so -L/usr/local/lib src/lcrypto.o -L/usr/local/ssl/lib -Wl,-rpath,/usr/local/ssl/lib: -lcrypto
/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(obj_dat.o): relocation R_X86_64_PC32 against symbol `obj_cleanup_defer' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld final link failed bad value
collect2: error: ld returned 1 exit status
Error: Build error: Failed compiling module crypto.so
I understand that I should recompile luacrypto with the -fPIC flag? Is that correct? If this is the solution, as I'm not expert about libraries and compilation, could you please let me know how I can recompile luacrypto (that I already downloaded) with this flag?
Note: I'm using openssl 1.0.2k.
Thanks in advance
Stefano
luacrypto's sha1WithRSAEncryption is different with java's SHA1WithRSA?
When I try to run cmake .\
on the luacrypto directory I get:
C:\Users\Admin\Desktop\luacrypto-master>cmake .\
-- Building for: Visual Studio 12 2013
-- The C compiler identification is MSVC 18.0.31101.0
-- Check for working C compiler using: Visual Studio 12 2013
-- Check for working C compiler using: Visual Studio 12 2013 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Found Lua51: C:/Program Files (x86)/Lua/5.1/lib/lua51.lib (found version "5.1.4")
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CRYPTO_LIBRARY
linked by target "crypto" in directory C:/Users/Admin/Desktop/luacrypto-master
SSL_LIBRARY
linked by target "crypto" in directory C:/Users/Admin/Desktop/luacrypto-master
-- Configuring incomplete, errors occurred!
See also "C:/Users/Admin/Desktop/luacrypto-master/CMakeFiles/CMakeOutput.log".
If I run:
cmake -D CRYPTO_LIBRARY=C:\OpenSSL-Win32\bin\libeay32.dll -D SSL_LIBRARY=C:\OpenSSL-Win32\bin\ssleay32.dll .\
libeay32.dll being the downloaded crypto lib and ssleay32.dll the sll lib, which I'm not even sure if they are because I really don't know what the cryptlib and ssllib are supposed to be name or how I'm supposed to get them. I installed them from this website. This is the output:
`C:\Users\Admin\Desktop\luacrypto-master>cmake -D CRYPTO_LIBRARY=C:\OpenSSL-Win32\bin\libeay32.dll -D SSL_LIBRARY=C:\OpenSSL-Win32\bin\ssleay32.dll .\
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Admin/Desktop/luacrypto-master
Supposedly it compiled but I can't find luacrypto.dll anywhere in luacrypto-master.
I'm running windows 10 (unfortunatly..) and I'm using the latest installation of cmake.
Debian/ubuntu name the lua package lua5.1, lua5.2, etc... so the ./configure in luacrypto fails to find lua. I modified the configure.ac to look for lua5.1 package, ran autoreconf, and it detected lua5.1.
But, it doesn't build:
make[2]: Entering directory `/home/sroberts/s/luacrypto/luacrypto/src'
/bin/bash ../libtool --tag=CC --mode=link gcc -g -O2 -module -avoid-version -o crypto.la -rpath lcrypto.lo -lssl -lcrypto
libtool: link: only absolute run-paths are allowed
No idea what's going on here, so, I abandoned the directions in INSTALL, and tried cmake. This works better:
cmake CMakeLists.txt
make
make install
But, it doesn't install into a location where lua's package.cpath will search:
/usr/local/lib/lua/crypto.so
is not in package.cpath:
% lua -e "print(package.cpath)"
./?.so;/usr/local/lib/lua/5.1/?.so;/usr/lib/i386-linux-gnu/lua/5.1/?.so;/usr/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so
I know that autodetection of lua is painful and non-standard, but two suggestions:
Modify INSTALL to recommend people use cmake if they have it (and consider removing the auto- cruft from the repo, it should be in released tarballs, if you release, but doesn't have to be checked in).
Train cmake to derive the crypto.so install path from package.cpath (probably most portable), or try to get the path from pkg-config:
pkg-config lua5.1 --define-variable=prefix=/usr/local --variable=INSTALL_CMOD
/usr/local/lib/i386-linux-gnu/lua/5.1
The crypto.so did appear to be built correctly, with cmake, though, once I move once I've moved it into the package.cpath:
% lua -l crypto -e "print(crypto._DESCRIPTION)"
LuaCrypto is a Lua wrapper for OpenSSL
I am trying to install luacrypto and i get this error . My gcc version is 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC). I have Lua 5.1.4 .
An help will be appreciated?
I am using crypto.encrypt("AES128", text, key) API to encrypt our data. But whenever i pass key whose size is more than 32 bytes/char it say invalid key.
Is there anyway i can pass longer keys ? or this is a bug ?
Hi,
Is it possible to change the module so that OpenSSL environment initialization is conditionally disabled in luacrypto so that application which embeds Lua and luacrypto can do OpenSSL environment initialization by itself? By the initialization I mean calls OpenSSL_add_all_digests() and OpenSSL_add_all_ciphers() in luaopen_crypto(). This is necessary in certain use cases; particularly it is more or less required for multi-threaded applications where application creates multiple independent Lua environments in different threads where each Lua environment loads luacrypto library. The problem is that OpenSSL environment initialization should be done only once per-process; if you try to do OpenSSL enviroment initialization in multiple threads at the same time it causes crashes as corresponding API is not supposed to be called in parallel. Also in general for multi thread use case OpenSSL environment needs more complex initialization logic.
Hello,
I am not able to decrypt back what was encrypted using Crypto-JS in browser Javascript:
// Encrypt
var ciphertext = CryptoJS.AES.encrypt('testingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtesting', '&&nH8P3bxk+?C4gR');
// Decrypt
var bytes = CryptoJS.AES.decrypt(ciphertext.toString(), '&&nH8P3bxk+?C4gR');
var plaintext = bytes.toString(CryptoJS.enc.Utf8);
console.log(plaintext);
I can decrypt it in Java using:
Cipher.getInstance("AES/CBC/PKCS5Padding")
But, I get
error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
when I try to do it with LuaCrypto. Here is the code:
local crypto = require("crypto")
local cipherText = 'U2FsdGVkX1859eIyt4M7VHNBl9BGMdsemPYAADKmqs9sltwKINfzVMci0Vw1NLr73Iti67zQ0+JoqVcL59Gcp+4R5NY6wg2n3r0wqLcQRc7PkIGpgup1UJp4DzhXSIGHz08Eu/nEbt3jAh3S4GVUoVFbXLluf/BvedTGdsqcN2EPL9S/WQOc5QDyl9OQjpBl+QS56nWL0DO6iR/6CIoEuQ+zC/7KTpBw2jQf8sxuDNptZzwKLlDi2sWSaeCkvPj+m8zheAlnZzVc+L5JeLdcx7WkIRQImNs9P5bkhXmiK2nZnw4yco3QHbzRkRBJiB3HgdYDauHsuKmR21zv9VLjAcGTrZjiUbtrBfuTRawKOiAFm599Inbq+Ugu9n4RelQ2CTdxwDfe3ZE3kscP3dyAmg=='
ngx.say(crypto.decrypt('aes-256-cbc', cipherText, '&&nH8P3bxk+?C4gR'))
Could someone please help me with server side decryption?
could you please clarify how to proceed with installation?
OR
c:\Program Files (x86)\LuaRocks\luacrypto-0.3.2-2\luacrypto>nmake
Microsoft (R) Program Maintenance Utility Version 14.31.31105.0
Copyright (C) Microsoft Corporation. All rights reserved.
NMAKE : fatal error U1064: MAKEFILE not found and no target specified
Stop.
luarocks install luacrypto OPENSSL_DIR="c:/Program Files (x86)/OpenSSL"
GNU Wget 1.19.4 built on mingw32.
-cares +digest +gpgme +https +ipv6 +iri +large-file +metalink -nls
+ntlm +opie -psl +ssl/openssl
Wgetrc:
/win32dev/misc/wget/out32/etc/wgetrc (system)
Compile:
i586-w64-mingw32-gcc -DHAVE_CONFIG_H
-DSYSTEM_WGETRC="/win32dev/misc/wget/out32/etc/wgetrc"
-DLOCALEDIR="/win32dev/misc/wget/out32/share/locale" -I. -I../lib
-I../lib -I/win32dev/misc/wget/out32/include
-I/win32dev/misc/wget/out32/include
-I/win32dev/misc/wget/out32/include
-I/win32dev/misc/wget/out32/include -DHAVE_LIBSSL
-I/win32dev/misc/wget/out32/include -DNDEBUG
Link:
i586-w64-mingw32-gcc -I/win32dev/misc/wget/out32/include
-I/win32dev/misc/wget/out32/include
-I/win32dev/misc/wget/out32/include -DHAVE_LIBSSL
-I/win32dev/misc/wget/out32/include -DNDEBUG
-L/win32dev/misc/wget/out32/lib -lidn2
-L/win32dev/misc/wget/out32/lib -lgpgme -lassuan -lws2_32
-lgpg-error -L/win32dev/misc/wget/out32/lib -lmetalink -lunistring
-liconv -L/win32dev/misc/wget/out32/lib -lssl -lcrypto
-L/win32dev/misc/wget/out32/lib -lz -lws2_32 -lole32 -lcrypt32
-lexpat ftp-opie.o mswindows.o openssl.o http-ntlm.o
../lib/libgnu.a -lws2_32 -lws2_32 -lws2_32 -lws2_32
/win32dev/misc/wget/out32/lib/libiconv.a
/win32dev/misc/wget/out32/lib/libunistring.a -lws2_32
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
http://www.gnu.org/licenses/gpl.html.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Originally written by Hrvoje Niksic [email protected].
Please send bug reports and questions to [email protected].
Could Not Find C:\Users\Andrew\AppData\Local\LuaRocks\Cache\https___luarocks.org\manifest-5.1.zip.unixtime
7-Zip 18.01 (x86) : Copyright (c) 1999-2018 Igor Pavlov : 2018-01-28
Scanning the drive for archives:
1 file, 52123 bytes (51 KiB)
Path = C:\Users\Andrew\AppData\Local\LuaRocks\Cache\https___luarocks.org\manifest-5.1.zip
Type = zip
Physical Size = 52123
Everything is Ok
Size: 1237488
Compressed: 52123
Installing https://luarocks.org/luacrypto-0.3.2-2.src.rock
Could Not Find C:\Users\Andrew\AppData\Local\LuaRocks\Cache\https___luarocks.org\luacrypto-0.3.2-2.src.rock.unixtime
7-Zip 18.01 (x86) : Copyright (c) 1999-2018 Igor Pavlov : 2018-01-28
Scanning the drive for archives:
1 file, 393601 bytes (385 KiB)
Path = C:\Users\Andrew\AppData\Local\Temp\luarocks_luarocks-rock-luacrypto-0.3.2-2-1087\luacrypto-0.3.2-2.src.rock
Type = zip
Physical Size = 393601
Everything is Ok
Folders: 8
Files: 59
Size: 1440496
Compressed: 393601
luacrypto 0.3.2-2 depends on lua >= 5.1 (5.1-1 provided by VM)
cl /nologo /MD /O2 -c -Fosrc/lcrypto.obj -IC:\Program Files (x86)\Lua\5.1\include src/lcrypto.c -Ic:/Program Files (x86)/OpenSSL/include
lcrypto.c
src/lcrypto.c(81): error C2027: use of undefined type 'evp_md_ctx_st'
c:/Program Files (x86)/OpenSSL/include\openssl/types.h(104): note: see declaration of 'evp_md_ctx_st'
src/lcrypto.c(331): error C2027: use of undefined type 'evp_cipher_ctx_st'
c:/Program Files (x86)/OpenSSL/include\openssl/types.h(102): note: see declaration of 'evp_cipher_ctx_st'
src/lcrypto.c(425): error C2079: 'c' uses undefined struct 'evp_cipher_ctx_st'
src/lcrypto.c(437): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(443): warning C4133: 'function': incompatible types - from 'int *' to 'const EVP_CIPHER_CTX *'
src/lcrypto.c(445): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(447): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(452): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(454): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(462): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(470): error C2027: use of undefined type 'evp_cipher_ctx_st'
c:/Program Files (x86)/OpenSSL/include\openssl/types.h(102): note: see declaration of 'evp_cipher_ctx_st'
src/lcrypto.c(561): error C2079: 'c' uses undefined struct 'evp_cipher_ctx_st'
src/lcrypto.c(573): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(578): warning C4133: 'function': incompatible types - from 'int *' to 'const EVP_CIPHER_CTX *'
src/lcrypto.c(579): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(581): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(586): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(588): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(596): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(604): error C2027: use of undefined type 'hmac_ctx_st'
c:/Program Files (x86)/OpenSSL/include\openssl/types.h(132): note: see declaration of 'hmac_ctx_st'
src/lcrypto.c(711): error C2079: 'c' uses undefined struct 'hmac_ctx_st'
src/lcrypto.c(724): warning C4133: 'function': incompatible types - from 'int *' to 'HMAC_CTX *'
src/lcrypto.c(725): warning C4133: 'function': incompatible types - from 'int *' to 'HMAC_CTX *'
src/lcrypto.c(726): warning C4133: 'function': incompatible types - from 'int *' to 'HMAC_CTX *'
src/lcrypto.c(747): error C2027: use of undefined type 'evp_md_ctx_st'
c:/Program Files (x86)/OpenSSL/include\openssl/types.h(104): note: see declaration of 'evp_md_ctx_st'
src/lcrypto.c(828): error C2079: 'c' uses undefined struct 'evp_md_ctx_st'
src/lcrypto.c(835): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_MD_CTX *'
src/lcrypto.c(836): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_MD_CTX *'
src/lcrypto.c(838): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_MD_CTX *'
src/lcrypto.c(839): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_MD_CTX *'
src/lcrypto.c(857): error C2027: use of undefined type 'evp_md_ctx_st'
c:/Program Files (x86)/OpenSSL/include\openssl/types.h(104): note: see declaration of 'evp_md_ctx_st'
src/lcrypto.c(940): error C2079: 'c' uses undefined struct 'evp_md_ctx_st'
src/lcrypto.c(948): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_MD_CTX *'
src/lcrypto.c(949): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_MD_CTX *'
src/lcrypto.c(952): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_MD_CTX *'
src/lcrypto.c(955): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_MD_CTX *'
src/lcrypto.c(1164): error C2037: left of 'type' specifies undefined struct/union 'evp_pkey_st'
src/lcrypto.c(1165): error C2037: left of 'pkey' specifies undefined struct/union 'evp_pkey_st'
src/lcrypto.c(1165): warning C4047: 'function': 'int' differs in levels of indirection from 'void *'
src/lcrypto.c(1165): warning C4024: 'PEM_write_bio_DSAPrivateKey': different types for formal and actual parameter 5
src/lcrypto.c(1165): error C2198: 'PEM_write_bio_DSAPrivateKey': too few arguments for call
src/lcrypto.c(1166): error C2037: left of 'type' specifies undefined struct/union 'evp_pkey_st'
src/lcrypto.c(1167): error C2037: left of 'pkey' specifies undefined struct/union 'evp_pkey_st'
src/lcrypto.c(1167): warning C4047: 'function': 'int' differs in levels of indirection from 'void *'
src/lcrypto.c(1167): warning C4024: 'PEM_write_bio_RSAPrivateKey': different types for formal and actual parameter 5
src/lcrypto.c(1167): error C2198: 'PEM_write_bio_RSAPrivateKey': too few arguments for call
src/lcrypto.c(1277): error C2037: left of 'type' specifies undefined struct/union 'evp_pkey_st'
src/lcrypto.c(1277): warning C4477: 'sprintf' : format string '%s' requires an argument of type 'char *', but variadic argument 2 has type 'int'
src/lcrypto.c(1277): warning C4477: 'sprintf' : format string '%d' requires an argument of type 'int', but variadic argument 3 has type 'EVP_PKEY **'
src/lcrypto.c(1277): warning C4473: 'sprintf' : not enough arguments passed for format string
src/lcrypto.c(1277): note: placeholders and their parameters expect 4 variadic arguments, but 3 were provided
src/lcrypto.c(1277): note: the missing variadic argument 4 is required by format string '%p'
src/lcrypto.c(1299): error C2027: use of undefined type 'evp_cipher_ctx_st'
c:/Program Files (x86)/OpenSSL/include\openssl/types.h(102): note: see declaration of 'evp_cipher_ctx_st'
src/lcrypto.c(1320): error C2037: left of 'cipher' specifies undefined struct/union 'evp_cipher_ctx_st'
src/lcrypto.c(1320): error C2198: 'EVP_CIPHER_get0_name': too few arguments for call
src/lcrypto.c(1379): error C2037: left of 'cipher' specifies undefined struct/union 'evp_cipher_ctx_st'
src/lcrypto.c(1379): error C2198: 'EVP_CIPHER_get_iv_length': too few arguments for call
src/lcrypto.c(1400): error C2079: 'ctx' uses undefined struct 'evp_cipher_ctx_st'
src/lcrypto.c(1418): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(1420): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(1423): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(1436): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(1439): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(1448): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(1451): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(1461): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(1483): error C2027: use of undefined type 'evp_cipher_ctx_st'
c:/Program Files (x86)/OpenSSL/include\openssl/types.h(102): note: see declaration of 'evp_cipher_ctx_st'
src/lcrypto.c(1509): error C2037: left of 'type' specifies undefined struct/union 'evp_pkey_st'
src/lcrypto.c(1508): warning C4477: 'sprintf' : format string '%s' requires an argument of type 'char *', but variadic argument 4 has type 'int'
src/lcrypto.c(1508): warning C4477: 'sprintf' : format string '%d' requires an argument of type 'int', but variadic argument 5 has type 'EVP_PKEY **'
src/lcrypto.c(1508): warning C4473: 'sprintf' : not enough arguments passed for format string
src/lcrypto.c(1508): note: placeholders and their parameters expect 6 variadic arguments, but 5 were provided
src/lcrypto.c(1508): note: the missing variadic argument 6 is required by format string '%p'
src/lcrypto.c(1602): error C2079: 'ctx' uses undefined struct 'evp_cipher_ctx_st'
src/lcrypto.c(1628): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(1632): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(1634): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(1644): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(1646): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(1656): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(1658): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
src/lcrypto.c(1664): warning C4133: 'function': incompatible types - from 'int *' to 'EVP_CIPHER_CTX *'
Error: Build error: Failed compiling object src/lcrypto.obj
C:\Program Files (x86)\LuaRocks/tools/rmdir.exe: `C:\Program Files (x86)\Lua\5.1\systree\lib\luarocks\rocks-5.1\luacrypto': Directory not empty
It looks like pkey_from_pem and x509__x509_from_string don't BIO_free their memory object when they succeed, only when they fail. Would this result in a memory leak? Or do the pkey and x509 cert objects retain a reference to the allocated memory and free it when they are freed?
/bin/sh ../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT lcrypto.lo -MD -MP -MF .deps/lcrypto.Tpo -c -o lcrypto.lo lcrypto.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT lcrypto.lo -MD -MP -MF .deps/lcrypto.Tpo -c lcrypto.c -fPIC -DPIC -o .libs/lcrypto.o
In file included from lcrypto.c:31:0:
lcrypto.c:38:13: error: expected declaration specifiers or '...' before '(' token
static void luaL_register (lua_State *L, const char *libname, const luaL_Reg *l)
^
lcrypto.c:38:13: error: expected declaration specifiers or '...' before '(' token
static void luaL_register (lua_State *L, const char *libname, const luaL_Reg *l)
^
lcrypto.c:38:13: error: expected declaration specifiers or '...' before numeric constant
static void luaL_register (lua_State *L, const char *libname, const luaL_Reg *l)
^
lcrypto.c:44:0: warning: "lua_objlen" redefined [enabled by default]
#define lua_objlen lua_rawlen
^
In file included from /usr/include/lua.h:16:0,
from lcrypto.c:30:
/usr/include/luaconf.h:301:0: note: this is the location of the previous definition
#define lua_objlen(L,i) lua_rawlen(L, (i))
Now we can not effective implement CTR algorithm with custom counter.
But if we implement resetiv method then we can write:
local aes = crypto.encrypt.new('aes-256-ctr', KEY)
local IV = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
for b, e in ichunks(msg, block_size) do
inc_iv(IV)
aes:resetiv(IV)
local chunk = string.sub(msg, b, e)
chunk = aes:update(chunk) -- or even better aes:update(msg, b, e)
end
I realy do not know is this valid in OpenSSL update iv, but it work.
in my test this method 10 times slower then simple aes-256-crt.
this my implementation moteus-iv
i installed luacrypto, but when i run my program i still get
root@LPG1:~# lua a.lua
lua: a.lua:1: module 'crypto' not found:
no field package.preload['crypto']
no file '/usr/local/share/lua/5.2/crypto.lua'
no file '/usr/local/share/lua/5.2/crypto/init.lua'
no file '/usr/local/lib/lua/5.2/crypto.lua'
no file '/usr/local/lib/lua/5.2/crypto/init.lua'
no file '/usr/share/lua/5.2/crypto.lua'
no file '/usr/share/lua/5.2/crypto/init.lua'
no file './crypto.lua'
no file '/usr/local/lib/lua/5.2/crypto.so'
no file '/usr/lib/x86_64-linux-gnu/lua/5.2/crypto.so'
no file '/usr/lib/lua/5.2/crypto.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './crypto.so'
stack traceback:
[C]: in function 'require'
a.lua:1: in main chunk
[C]: in ?
ideas?
why not support openssl 1.1.0 or higher?
https://github.com/mkottman/luacrypto/blob/master/src/lcrypto.c
When I compile using that library I get:
gcc -O2 -fPIC -I/usr/include -c src/lcrypto.c -o src/lcrypto.o -I/usr/include
In file included from src/lcrypto.c:31:0:
src/lcrypto.c:38:13: error: expected declaration specifiers or ‘...’ before ‘(’ token
static void luaL_register (lua_State *L, const char *libname, const luaL_Reg *l)
$ luarocks install luacrypto
Installing https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/luacrypto-0.3.2-2.src.rock...
Using https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/luacrypto-0.3.2-2.src.rock... switching to 'build' mode
gcc -O2 -fPIC -I/home/lxz/torch/install/include -c src/lcrypto.c -o src/lcrypto.o -I/usr/include
src/lcrypto.c: In function ‘digest_pnew’:
src/lcrypto.c:81:61: error: invalid application of ‘sizeof’ to incomplete type ‘EVP_MD_CTX {aka struct evp_md_ctx_st}’
EVP_MD_CTX *c = (EVP_MD_CTX *)lua_newuserdata(L, sizeof(EVP_MD_CTX));
^~~~~~~~~~
src/lcrypto.c: In function ‘digest_reset’:
src/lcrypto.c:120:10: warning: implicit declaration of function ‘EVP_MD_CTX_cleanup’; did you mean ‘EVP_MD_CTX_create’? [-Wimplicit-function-declaration]
if (!EVP_MD_CTX_cleanup(c))
^~~~~~~~~~~~~~~~~~
EVP_MD_CTX_create
src/lcrypto.c: In function ‘encrypt_pnew’:
src/lcrypto.c:331:69: error: invalid application of ‘sizeof’ to incomplete type ‘EVP_CIPHER_CTX {aka struct evp_cipher_ctx_st}’
EVP_CIPHER_CTX *c = (EVP_CIPHER_CTX *)lua_newuserdata(L, sizeof(EVP_CIPHER_CTX));
^~~~~~~~~~~~~~
src/lcrypto.c: In function ‘encrypt_fencrypt’:
src/lcrypto.c:425:20: error: storage size of ‘c’ isn’t known
EVP_CIPHER_CTX c;
^
src/lcrypto.c: In function ‘decrypt_pnew’:
src/lcrypto.c:470:69: error: invalid application of ‘sizeof’ to incomplete type ‘EVP_CIPHER_CTX {aka struct evp_cipher_ctx_st}’
EVP_CIPHER_CTX *c = (EVP_CIPHER_CTX *)lua_newuserdata(L, sizeof(EVP_CIPHER_CTX));
^~~~~~~~~~~~~~
src/lcrypto.c: In function ‘decrypt_fdecrypt’:
src/lcrypto.c:561:20: error: storage size of ‘c’ isn’t known
EVP_CIPHER_CTX c;
^
src/lcrypto.c: In function ‘hmac_pnew’:
src/lcrypto.c:604:57: error: invalid application of ‘sizeof’ to incomplete type ‘HMAC_CTX {aka struct hmac_ctx_st}’
HMAC_CTX *c = (HMAC_CTX *)lua_newuserdata(L, sizeof(HMAC_CTX));
^~~~~~~~
src/lcrypto.c: In function ‘hmac_fnew’:
src/lcrypto.c:621:5: warning: implicit declaration of function ‘HMAC_CTX_init’; did you mean ‘HMAC_CTX_new’? [-Wimplicit-function-declaration]
HMAC_CTX_init(c);
^~~~~~~~~~~~~
HMAC_CTX_new
src/lcrypto.c: In function ‘hmac_clone’:
src/lcrypto.c:631:5: error: dereferencing pointer to incomplete type ‘HMAC_CTX {aka struct hmac_ctx_st}’
*d = *c;
^~
src/lcrypto.c: In function ‘hmac_gc’:
src/lcrypto.c:697:5: warning: implicit declaration of function ‘HMAC_CTX_cleanup’; did you mean ‘HMAC_CTX_get_md’? [-Wimplicit-function-declaration]
HMAC_CTX_cleanup(c);
^~~~~~~~~~~~~~~~
HMAC_CTX_get_md
src/lcrypto.c: In function ‘hmac_fdigest’:
src/lcrypto.c:711:14: error: storage size of ‘c’ isn’t known
HMAC_CTX c;
^
src/lcrypto.c: In function ‘sign_pnew’:
src/lcrypto.c:747:61: error: invalid application of ‘sizeof’ to incomplete type ‘EVP_MD_CTX {aka struct evp_md_ctx_st}’
EVP_MD_CTX *c = (EVP_MD_CTX *)lua_newuserdata(L, sizeof(EVP_MD_CTX));
^~~~~~~~~~
src/lcrypto.c: In function ‘sign_fsign’:
src/lcrypto.c:828:20: error: storage size of ‘c’ isn’t known
EVP_MD_CTX c;
^
src/lcrypto.c: In function ‘verify_pnew’:
src/lcrypto.c:857:61: error: invalid application of ‘sizeof’ to incomplete type ‘EVP_MD_CTX {aka struct evp_md_ctx_st}’
EVP_MD_CTX *c = (EVP_MD_CTX *)lua_newuserdata(L, sizeof(EVP_MD_CTX));
^~~~~~~~~~
src/lcrypto.c: In function ‘verify_fverify’:
src/lcrypto.c:940:20: error: storage size of ‘c’ isn’t known
EVP_MD_CTX c;
^
src/lcrypto.c: In function ‘rand_pseudo_bytes’:
src/lcrypto.c:992:5: warning: ‘RAND_pseudo_bytes’ is deprecated [-Wdeprecated-declarations]
return rand_do_bytes(L, RAND_pseudo_bytes);
^~~~~~
In file included from /usr/include/openssl/e_os2.h:13:0,
from /usr/include/openssl/err.h:13,
from src/lcrypto.c:7:
/usr/include/openssl/rand.h:44:1: note: declared here
DEPRECATEDIN_1_1_0(int RAND_pseudo_bytes(unsigned char *buf, int num))
^
src/lcrypto.c: In function ‘pkey_generate’:
src/lcrypto.c:1064:9: warning: ‘RSA_generate_key’ is deprecated [-Wdeprecated-declarations]
RSA *rsa = RSA_generate_key(key_len, RSA_F4, NULL, NULL);
^~~
In file included from /usr/include/openssl/e_os2.h:13:0,
from /usr/include/openssl/err.h:13,
from src/lcrypto.c:7:
/usr/include/openssl/rsa.h:234:1: note: declared here
DEPRECATEDIN_0_9_8(RSA *RSA_generate_key(int bits, unsigned long e, void
^
src/lcrypto.c:1074:9: warning: ‘DSA_generate_parameters’ is deprecated [-Wdeprecated-declarations]
DSA *dsa = DSA_generate_parameters(key_len, NULL, 0, NULL, NULL, NULL, NULL);
^~~
In file included from /usr/include/openssl/e_os2.h:13:0,
from /usr/include/openssl/err.h:13,
from src/lcrypto.c:7:
/usr/include/openssl/dsa.h:117:1: note: declared here
DEPRECATEDIN_0_9_8(DSA *DSA_generate_parameters(int bits,
^
src/lcrypto.c: In function ‘pkey_to_pem’:
src/lcrypto.c:1164:27: error: dereferencing pointer to incomplete type ‘struct evp_pkey_st’
if (private && pkey_st->type == EVP_PKEY_DSA)
^~
src/lcrypto.c: In function ‘pkey_tostring’:
src/lcrypto.c:1277:60: error: dereferencing pointer to incomplete type ‘EVP_PKEY {aka struct evp_pkey_st}’
sprintf(buf, "%s %s %d %p", LUACRYPTO_PKEYNAME, (*pkey)->type == EVP_PKEY_DSA ? "DSA" : "RSA", EVP_PKEY_bits(*pkey), pkey);
^~
src/lcrypto.c: In function ‘seal_pnew’:
src/lcrypto.c:1299:46: error: invalid application of ‘sizeof’ to incomplete type ‘EVP_CIPHER_CTX {aka struct evp_cipher_ctx_st}’
c->ctx = (EVP_CIPHER_CTX *)malloc(sizeof(EVP_CIPHER_CTX));
^~~~~~~~~~~~~~
In file included from src/lcrypto.c:8:0:
src/lcrypto.c: In function ‘seal_tostring’:
src/lcrypto.c:1320:81: error: dereferencing pointer to incomplete type ‘EVP_CIPHER_CTX {aka struct evp_cipher_ctx_st}’
s, "%s %p %s", LUACRYPTO_SEALNAME, (void *)c, EVP_CIPHER_name(c->ctx->cipher));
^
src/lcrypto.c: In function ‘seal_fseal’:
src/lcrypto.c:1400:20: error: storage size of ‘ctx’ isn’t known
EVP_CIPHER_CTX ctx;
^~~
src/lcrypto.c: In function ‘open_pnew’:
src/lcrypto.c:1483:46: error: invalid application of ‘sizeof’ to incomplete type ‘EVP_CIPHER_CTX {aka struct evp_cipher_ctx_st}’
c->ctx = (EVP_CIPHER_CTX *)malloc(sizeof(EVP_CIPHER_CTX));
^~~~~~~~~~~~~~
src/lcrypto.c: In function ‘open_fopen’:
src/lcrypto.c:1602:20: error: storage size of ‘ctx’ isn’t known
EVP_CIPHER_CTX ctx;
^~~
Error: Build error: Failed compiling object src/lcrypto.o
please create tag for recent releases (at least 0.3.0, 0.3.1), and push them on github.
you could also upload the tarball of release in https://github.com/mkottman/luacrypto/downloads
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.