简体   繁体   English

为什么使用C crypt函数将盐包含在哈希中

[英]Why salt is included in hash with c crypt function

Look at this very basic c program: 看一下这个非常基本的c程序:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <crypt.h>

int main (int argc, char *argv[]) 
{
    char pid[16];
    int id;
    for (id = 0;  id < 100; id++) 
    {
       snprintf(pid, sizeof(pid), "%i", id);
       printf("%s %s\n",pid, crypt(pid, "$1$awesome"));
    }
}

Here is the output on linux system: 这是Linux系统上的输出:

0 $1$awesome$cVjo4Ue9HeJs7sStMTm6v.
1 $1$awesome$6.658tD5uVqwQJ6/S8Mc71
2 $1$awesome$bKavcHTWRGnlTgP.zTZhO.
3 $1$awesome$ZlBH.fgxGrfw/naq38hyv.
4 $1$awesome$aQCliN7gPud1PC07Vri.y1
5 $1$awesome$EewcRVU39I/n0uMGaDxCN0
6 $1$awesome$fKMRDZaa5wra4G8xy9.m0/
7 $1$awesome$AqJ0SmXImg.xcUg/Yh/ov.
8 $1$awesome$bT3Wq9QORw1dnNZFZmVBk.
9 $1$awesome$4uM8mfZGdj2zeZ/CP/GSz1
10 $1$awesome$Gsa/ilcFg1LRl2dqNhgXg0

I do not understand why the salt is visible on the output. 我不明白为什么盐在输出中可见。 I have tried to compile the same program on Mac OS X and I did not see the salt in the hash. 我试图在Mac OS X上编译相同的程序,但没有看到哈希值。 Isn't it a security hole? 这不是安全漏洞吗? We should not see the salt in clear in the hash ? 我们不应该在哈希表中清楚地看到盐吗?

Thanks 谢谢

Read section 3 from the researchers who originally proposed it. 阅读最初提出该建议的研究人员的第3节 It says what @jonrsharpe said in the comment above, but always nice to get the original source (emphasis mine): 它说了@jonrsharpe在上面的评论中说的,但是总是很高兴获得原始信息(强调我的意思):

The key search technique is still likely to turn up a few passwords when it is used on a large collection of passwords, and it seemed wise to make this task as difficult as possible. 当密钥搜索技术用于大量密码时,它仍然可能会出现一些密码,并且使此任务尽可能困难是明智的。 To this end, when a password is first entered, the password program obtains a 12-bit random number (by reading the real-time clock) and appends this to the password typed in by the user. 为此, 当首次输入密码时,密码程序将获得12位随机数 (通过读取实时时钟) ,并将其附加到用户输入的密码上。 The concatenated string is encrypted and both the 12-bit random quantity (called the salt) and the 64-bit result of the encryption are entered into the password file . 串联的字符串被加密,并且12位随机量(称为salt)和64位加密结果都输入到密码文件中

When the user later logs in to the system, the 12-bit quantity is extracted from the password file and appended to the typed password. 当用户以后登录到系统时,将从密码文件中提取12位数量并将其附加到键入的密码上。 The encrypted result is required, as before, to be the same as the remaining 64 bits in the password file . 与以前一样,要求加密的结果与密码文件中其余的64位相同 This modification does not increase the task of finding any individual password, starting from scratch, but now the work of testing a given character string against a large collection of encrypted passwords has been multiplied by 4,096 (2^12). 此修改不会增加从头开始查找任何单个密码的任务,但是现在针对大量加密密码测试给定字符串的工作已乘以4,096(2 ^ 12)。 The reason for this is that there are 4,096 encrypted versions of each password and one of them has been picked more or less at random by the system. 原因是每个密码有4,096个加密版本,并且系统已或多或少地随机选择了其中一个。

With this modification, it is likely that the bad guy can spend days of computer time trying to find a password on a system with hundreds of passwords, and find none at all. 通过此修改,坏蛋很可能会花费数天的计算机时间来尝试在具有数百个密码的系统上查找密码,而根本找不到密码。 More important is the fact that it becomes impractical to prepare an encrypted dictionary in advance. 更重要的是,事先准备加密字典变得不切实际。 Such an encrypted dictionary could be used to crack new passwords in milliseconds when they appear. 这样的加密字典可用于在新密码出现时以毫秒为单位破解新密码。

There is a (not inadvertent) side effect of this modification. 此修改有(并非无意)副作用。 It becomes nearly impossible to find out whether a person with passwords on two or more systems has used the same password on all of them, unless you already know that. 除非您已经知道,否则几乎不可能找出在两个或多个系统上具有密码的人是否在所有系统上都使用了相同的密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM