Home > OS >  How to use crypt_gensalt() in crypt.h
How to use crypt_gensalt() in crypt.h

Time:01-03

According to crypt.h:

extern char *crypt_gensalt (const char *__prefix, unsigned long __count,
                            const char *__rbytes, int __nrbytes)

I understand that __prefix is encryption type (i.e. $2a$, $5$, $6$,...). My guess is __rbyte is the passphrase and __nrbytes is the size of passphrase. How about __count? What should I pass into it? I'm going to use $6$ prefix.

CodePudding user response:

From the man page: https://manpages.debian.org/experimental/libcrypt1-dev/crypt_gensalt_rn.3.en.html

count controls the CPU time cost of the hash; the valid range for count and the exact meaning of “CPU time cost” depends on the hashing method, but larger numbers correspond to more costly hashes.

See also https://manpages.debian.org/experimental/libcrypt1-dev/crypt.5.en.html

For $6$ (which is sha512crypt)

CPU time cost parameter
1000 to 999,999,999

and

The default CPU time cost parameter is 5000, which is too low for modern hardware.

  • Related