2 ** Copyright 1998 - 1999 Double Precision, Inc.
3 ** See COPYING for distribution information.
12 "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
14 char *md5_crypt_redhat(const char *pw
, const char *salt
)
16 struct MD5_CONTEXT outer_context
, inner_context
;
18 unsigned pwl
=strlen(pw
);
22 static char buffer
[100];
24 if (*salt
== '$' && salt
[1] == '1' && salt
[2] == '$')
27 for (l
=0; l
<8 && salt
[l
] && salt
[l
] != '$'; l
++)
30 md5_context_init(&inner_context
);
31 md5_context_hashstream(&inner_context
, pw
, pwl
);
32 md5_context_hashstream(&inner_context
, salt
, l
);
33 md5_context_hashstream(&inner_context
, pw
, pwl
);
34 md5_context_endstream(&inner_context
, pwl
*2+l
);
35 md5_context_digest(&inner_context
, digest
);
37 md5_context_init(&outer_context
);
38 md5_context_hashstream(&outer_context
, pw
, pwl
);
39 md5_context_hashstream(&outer_context
, "$1$", 3);
40 md5_context_hashstream(&outer_context
, salt
, l
);
46 md5_context_hashstream(&outer_context
, digest
, j
);
52 for (i
=pwl
; i
; i
>>= 1)
54 md5_context_hashstream(&outer_context
, (i
& 1) ? "": pw
, 1);
59 md5_context_endstream(&outer_context
, j
);
60 md5_context_digest(&outer_context
, digest
);
62 for (i
=0; i
<1000; i
++)
66 md5_context_init(&outer_context
);
69 md5_context_hashstream(&outer_context
, pw
, pwl
);
74 md5_context_hashstream(&outer_context
, digest
, 16);
80 md5_context_hashstream(&outer_context
, salt
, l
);
86 md5_context_hashstream(&outer_context
, pw
, pwl
);
92 md5_context_hashstream(&outer_context
, digest
, 16);
97 md5_context_hashstream(&outer_context
, pw
, pwl
);
101 md5_context_endstream(&outer_context
, j
);
102 md5_context_digest(&outer_context
, digest
);
105 strcpy(buffer
, "$1$");
106 strncat(buffer
, salt
, l
);
109 p
=buffer
+strlen(buffer
);
112 unsigned char *d
=digest
;
114 j
= (d
[i
] << 16) | (d
[i
+6] << 8) | d
[i
== 4 ? 5:12+i
];
115 *p
++= base64
[j
& 63] ; j
=j
>> 6;
116 *p
++= base64
[j
& 63] ; j
=j
>> 6;
117 *p
++= base64
[j
& 63] ; j
=j
>> 6;
118 *p
++= base64
[j
& 63];
121 *p
++ = base64
[j
& 63]; j
=j
>> 6;
122 *p
++ = base64
[j
& 63];