From 52e578cc2643cf3a804b2cfddfb6e983cd7cf804 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Fri, 6 Nov 2015 16:19:57 +0000 Subject: Inline a base64 implementation so that we don't rely on the libscrypt one which is hidden on some platforms --- luascrypt.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'luascrypt.c') diff --git a/luascrypt.c b/luascrypt.c index f9dce0a..181f1e8 100644 --- a/luascrypt.c +++ b/luascrypt.c @@ -20,6 +20,8 @@ #include "libscrypt.h" +#include "base64.h" + static void luascrypt_salt_gen(char *salt, int saltlen) { @@ -51,6 +53,7 @@ luascrypt_hash_password(lua_State *L) uint8_t hashbuf[64]; /* numbers, these are taken from the */ char saltbuf[256]; /* libscrypt_hash() source. */ char outbuf[256]; /* Icky, I know, but what can I do? */ + size_t bufused; uint32_t N = SCRYPT_N; uint32_t r = SCRYPT_r; uint32_t p = SCRYPT_p; @@ -81,13 +84,11 @@ luascrypt_hash_password(lua_State *L) "Unknown error"); } - if (libscrypt_b64_encode(outbuf, (char *)hashbuf, sizeof(hashbuf)) < 0) { - return luaL_error(L, "Unable to encode password hash."); - } + bufused = base64_encode(outbuf, (char *)hashbuf, sizeof(hashbuf)); + outbuf[bufused] = '\0'; - if (libscrypt_b64_encode(saltbuf, salt, sizeof(salt)) < 0) { - return luaL_error(L, "Unable to encode salt."); - } + bufused = base64_encode(saltbuf, salt, sizeof(salt)); + saltbuf[bufused] = '\0'; if (libscrypt_mcf(N, r, p, saltbuf, outbuf, buffer) < 1) { return luaL_error(L, "Unable to mcf encode password."); -- cgit v1.2.1