summaryrefslogtreecommitdiff
path: root/luascrypt.c
diff options
context:
space:
mode:
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.");