My Project
bcrypt.h
1 #ifndef _BCRYPT_H_
2 #define _BCRYPT_H_
3 
4 #define BCRYPT_HASHSIZE 64
5 
6 /*
7  * This function expects a work factor between 4 and 31 and a char array to
8  * store the resulting generated salt. The char array should typically have
9  * BCRYPT_HASHSIZE bytes at least. If the provided work factor is not in the
10  * previous range, it will default to 12.
11  *
12  * The return value is zero if the salt could be correctly generated and
13  * nonzero otherwise.
14  */
15 int bcrypt_gensalt(int workfactor, char salt[BCRYPT_HASHSIZE]);
16 
17 /*
18  * This function expects a password to be hashed, a salt to hash the password
19  * with and a char array to leave the result. It can also be used to verify a
20  * hashed password. In that case, provide the expected hash in the salt
21  * parameter and verify the output hash is the same as the input hash. Both the
22  * salt and the hash parameters should have room for BCRYPT_HASHSIZE characters
23  * at least.
24  *
25  * The return value is zero if the password could be hashed and nonzero
26  * otherwise.
27  */
28 int bcrypt_hashpw(const char *passwd, const char salt[BCRYPT_HASHSIZE],
29  char hash[BCRYPT_HASHSIZE]);
30 
31 /*
32  * Brief Example
33  * -------------
34  *
35  * Hashing a password:
36  *
37  * char salt[BCRYPT_HASHSIZE];
38  * char hash[BCRYPT_HASHSIZE];
39  *
40  * assert(bcrypt_gensalt(12, salt) == 0);
41  * assert(bcrypt_hashpw("thepassword", salt, hash) == 0);
42  *
43  *
44  * Verifying a password:
45  *
46  * char outhash[BCRYPT_HASHSIZE];
47  *
48  * assert(bcrypt_hashpw("thepassword", "expectedhash", outhash) == 0);
49  *
50  * if (strcmp("expectedhash", outhash) == 0) {
51  * printf("The password matches\n");
52  * } else {
53  * printf("The password does NOT match\n");
54  * }
55  */
56 
57 #endif