summaryrefslogtreecommitdiff
path: root/luascrypt.c
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2015-11-06 16:19:57 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2015-11-06 16:19:57 +0000
commit52e578cc2643cf3a804b2cfddfb6e983cd7cf804 (patch)
tree563ffd006c104d57b00fd72d17c08de5b9297352 /luascrypt.c
parent72abd9a73b13e15e467ad96ec15d8217837b21e4 (diff)
downloadlua-scrypt-git-52e578cc2643cf3a804b2cfddfb6e983cd7cf804.tar.gz
Inline a base64 implementation so that we don't rely on the libscrypt one which is hidden on some platforms
Diffstat (limited to 'luascrypt.c')
-rw-r--r--luascrypt.c13
1 files changed, 7 insertions, 6 deletions
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.");