如何在 crypt.h 中使用 crypt_gensalt()

How to use crypt_gensalt() in crypt.h

根据crypt.h:

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

我知道 __prefix 是加密类型(即 $2a$、$5$、$6$...)。我的猜测是 __rbyte 是密码,__nrbytes 是密码的大小。 __count怎么样?我应该传递什么?我要使用 $ 前缀。

来自手册页: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.

另见 https://manpages.debian.org/experimental/libcrypt1-dev/crypt.5.en.html

对于$(即sha512crypt

CPU time cost parameter
1000 to 999,999,999

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