Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
谁能告诉我 Dovecot 管理工具 (doveadm pw) 在使用 SHA-512 时如何对密码进行哈希处理。$6$ 表示 SHA-512,后跟盐,然后是哈希。Dovecot 究竟是如何产生盐分的?它使用自己的算法吗?据我所知,它使用 /dev/random 或 /dev/urandom,但它如何处理非 ASCII 字符?
没关系,在 password-scheme.c 中找到。
它从 /dev/urandom 读取数据并有一个包含允许字符的数组(静态 const char salt_chars[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";)。
盐是通过使用该数组中的一个字符生成的;准确地说,它从 /dev/urandom 中获取字节,以 salt_chars - 1 的长度为模,并使用它作为索引从 salt_chars 中选择一个字符。