Skip to content
Snippets Groups Projects
Commit c029e63f authored by Vladimir Davydov's avatar Vladimir Davydov Committed by Vladimir Davydov
Browse files

lua/digest: use OpenSSL version of SHA1

Since commit f6ea7180 ("Try to load several variants of libssl.")
the digest module uses an internal version of SHA1. Back then, we didn't
link the OpenSSL library. Instead, we tried to load it dynamically.
Since on some distributions the library could be missing, it was decided
to implement an internal version of SHA1, see #405.

However, since commit 59a55740 ("Link against libssl and libcrypto.
Issue #1382") we link the OpenSSL library unconditionally so there's no
need in having an internal implementation of SHA1. Let's drop it and
switch the digest module to the version of SHA1 implemented by the
crypto module using OpenSSL.

Part of #7987

NO_DOC=code cleanup
NO_TEST=code cleanup
NO_CHANGELOG=code cleanup
parent 2479ce76
No related branches found
No related tags found
No related merge requests found
......@@ -433,7 +433,6 @@ say_logger_initialized
say_logrotate
say_set_log_format
say_set_log_level
SHA1internal
space_bsize
space_by_id
space_run_triggers
......
......@@ -31,7 +31,6 @@
#include <string.h>
#include <lua/digest.h>
#include <sha1.h>
#include <openssl/evp.h>
#include <coio_task.h>
#include <lua.h>
......@@ -41,20 +40,6 @@
#define PBKDF2_MAX_DIGEST_SIZE 128
unsigned char *
SHA1internal(const unsigned char *d, size_t n, unsigned char *md)
{
static __thread unsigned char result[20];
SHA1_CTX ctx;
SHA1Init(&ctx);
SHA1Update(&ctx, d, n);
SHA1Final(result, &ctx);
if (md)
memcpy(md, result, 20);
return result;
}
static ssize_t
digest_pbkdf2_f(va_list ap)
{
......
......@@ -37,9 +37,6 @@
extern "C" {
#endif
unsigned char *
SHA1internal(const unsigned char *d, size_t n, unsigned char *md);
struct lua_State;
void
......
......@@ -8,9 +8,6 @@ local cord_ibuf_take = buffer.internal.cord_ibuf_take
local cord_ibuf_put = buffer.internal.cord_ibuf_put
ffi.cdef[[
/* internal implementation */
unsigned char *SHA1internal(const unsigned char *d, size_t n, unsigned char *md);
/* from libc */
int snprintf(char *str, size_t size, const char *format, ...);
......@@ -85,6 +82,7 @@ local BASE64_NOWRAP = 2
local BASE64_URLSAFE = 7
local digest_shortcuts = {
sha1 = 'SHA1',
sha224 = 'SHA224',
sha256 = 'SHA256',
sha384 = 'SHA384',
......@@ -251,22 +249,6 @@ local m = {
return builtin.crc32_calc(tonumber(crc), str, string.len(str))
end,
sha1 = function(str)
if type(str) ~= 'string' then
error("Usage: digest.sha1(string)")
end
local r = builtin.SHA1internal(str, #str, nil)
return ffi.string(r, 20)
end,
sha1_hex = function(str)
if type(str) ~= 'string' then
error("Usage: digest.sha1_hex(string)")
end
local r = builtin.SHA1internal(str, #str, nil)
return string.hex(ffi.string(r, 20))
end,
guava = function(state, buckets)
return builtin.guava(state, buckets)
end,
......
......@@ -29,7 +29,6 @@ local check_symbols = {
'cord_ibuf_drop',
'cord_ibuf_put',
'cord_ibuf_take',
'SHA1internal',
'random_bytes',
'fiber_time',
'ibuf_create',
......
......@@ -28,7 +28,7 @@ digest.md5()
...
digest.sha1()
---
- error: 'builtin/digest.lua:<line>"]: Usage: digest.sha1(string)'
- error: 'builtin/crypto.lua:<line>"]: Usage: digest.sha1(string)'
...
digest.sha224()
---
......@@ -87,7 +87,7 @@ digest.md5(12345LL)
...
digest.sha1(12345LL)
---
- error: 'builtin/digest.lua:<line>"]: Usage: digest.sha1(string)'
- error: 'builtin/crypto.lua:<line>"]: Usage: digest.sha1(string)'
...
digest.sha224(12345LL)
---
......
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