lua-bcrypt

Secure password hashing for Lua
Log | Files | Refs

commit 682fd7d15874acef8332598ebd16005f02a29404
parent 3ef36e04def8cdab9070b6f48f8cb460505322f1
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Tue, 10 Dec 2013 10:36:24 +0000

Don't ignore read errors

Diffstat:
src/main.c | 13++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -35,10 +35,6 @@ static int luabcrypt_digest( lua_State* L ) { return 1; } -void randomBytes( char* output, size_t bytes ) { - read( urandom, output, bytes ); -} - // bcrypt.salt( logRounds ) static int luabcrypt_salt( lua_State* L ) { unsigned long logRounds = luaL_checkinteger( L, 1 ); @@ -46,7 +42,14 @@ static int luabcrypt_salt( lua_State* L ) { char entropy[ ENTROPY_SIZE ]; char salt[ SALT_SIZE ]; - randomBytes( entropy, sizeof( entropy ) ); + ssize_t bytes = read( urandom, entropy, sizeof( entropy ) ); + + if( bytes != sizeof( entropy ) ) { + lua_pushstring( L, strerror( errno ) ); + + return lua_error( L ); + } + crypt_gensalt_rn( "$2y$", logRounds, entropy, sizeof( entropy ), salt, sizeof( salt ) ); lua_pushstring( L, salt );