Skip to content
Snippets Groups Projects
Commit a9c4991d authored by Dmitry E. Oboukhov's avatar Dmitry E. Oboukhov
Browse files

Seek several libSSL varians (backport from master). #405

parent 5374957a
No related branches found
No related tags found
No related merge requests found
-- box.digest.lua (internal file)
-- digest.lua (internal file)
do
......@@ -13,6 +13,7 @@ ffi.cdef[[
unsigned char *SHA384(const unsigned char *d, size_t n,unsigned char *md);
unsigned char *SHA512(const unsigned char *d, size_t n,unsigned char *md);
unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md);
unsigned char *SHA1internal(const unsigned char *d, size_t n, unsigned char *md);
/* from openssl/md5.h */
unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md);
......@@ -28,7 +29,19 @@ ffi.cdef[[
local ssl
if ssl == nil then
pcall(function() ssl = ffi.load('ssl') end)
local variants = {
'libssl.so.1.0.0',
'libssl.so.0.9.8',
'libssl.so',
'ssl',
}
for _, libname in pairs(variants) do
pcall(function() ssl = ffi.load(libname) end)
if ssl ~= nil then
break
end
end
end
......@@ -43,6 +56,16 @@ local def = {
md4 = { 'MD4', 16 }
}
local hexres = ffi.new('char[129]')
local function tohex(r, size)
for i = 0, size - 1 do
ffi.C.snprintf(hexres + i * 2, 3, "%02x",
ffi.cast('unsigned int', r[i]))
end
return ffi.string(hexres, size * 2)
end
local m = {
crc32 = function(str)
if str == nil then
......@@ -60,11 +83,10 @@ local m = {
str = tostring(str)
end
return ffi.C.crc32_calc(tonumber(crc), str, string.len(str))
end
end,
}
if ssl ~= nil then
local hexres = ffi.new('char[129]')
for pname, df in pairs(def) do
local hfunction = df[1]
......@@ -87,12 +109,7 @@ if ssl ~= nil then
str = tostring(str)
end
local r = ssl[hfunction](str, string.len(str), nil)
for i = 0, hsize - 1 do
ffi.C.snprintf(hexres + i * 2, 3, "%02x",
ffi.cast('unsigned int', r[i]))
end
return ffi.string(hexres, hsize * 2)
return tohex(r, hsize)
end
end
else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment