Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple bcrypt library for C [closed]

Tags:

bcrypt

I'm looking for a simple to use cross-platform bcrypt library for C. I've searched around a couple places but nothing seems to compares to the ease of use of:

http://bcrypt.codeplex.com/SourceControl/changeset/view/1eef0262901c#BCrypt.Net.Test%2fTestBCrypt.cs

Why are all the C implementations of this a nightmare compared to this .NET lib? Basically 2 functions is what I'm looking for.

1) Generate salt (return a string)

2) Hash string using a given salt & pw (return a string)

like image 498
user441521 Avatar asked Dec 10 '12 01:12

user441521


People also ask

What is bcrypt genSalt?

The basic idea for using bcrypt.genSalt was generate Salt for my password which need to encrypted.The Syntax for using bcrypt.genSalt is as follows. bcrypt.genSalt(rounds, cb) rounds - [OPTIONAL] - the cost of processing the data. ( default - 10) cb - [REQUIRED] - a callback to be fired once the salt has been generated ...

Does bcrypt store salt?

Bcrypt does not have a database it stores the salt... The salt is added to the hash in base64 format....

Why is bcrypt hash different every time?

A BCrypt hash includes salt and as a result this algorithm returns different hashes for the same input.

What does bcrypt return?

Asynchronous Hashing The bcrypt. hash() function takes in the plain password and a salt as input, and returns a hashed string.


1 Answers

Your C options for bcrypt seem to be:

  • In OpenBSD: https://github.com/openbsd/src/blob/master/lib/libc/crypt/bcrypt.c

  • In OpenWall: http://openwall.com/crypt/

The C implementations seem to be pretty straightforward to use. The OpenBSD version looks like this:

char *bcrypt(const char *key, const char *salt);

char *bcrypt_gensalt(u_int8_t log_rounds);

P.S. Consider scrypt for new code, if you are not restricted to using bcrypt only due to backward compatibility,

like image 109
Alex I Avatar answered Sep 17 '22 13:09

Alex I