release 1.2.5
[musl.git] / src / crypt / crypt_r.c
blobdb6015e236f639089cb1b6c4cc65f548b96b56ed
1 #include <crypt.h>
3 char *__crypt_r(const char *key, const char *salt, struct crypt_data *data)
5 /* Per the crypt_r API, the caller has provided a pointer to
6 * struct crypt_data; however, this implementation does not
7 * use the structure to store any internal state, and treats
8 * it purely as a char buffer for storing the result. */
9 char *output = (char *)data;
10 if (salt[0] == '$' && salt[1] && salt[2]) {
11 if (salt[1] == '1' && salt[2] == '$')
12 return __crypt_md5(key, salt, output);
13 if (salt[1] == '2' && salt[3] == '$')
14 return __crypt_blowfish(key, salt, output);
15 if (salt[1] == '5' && salt[2] == '$')
16 return __crypt_sha256(key, salt, output);
17 if (salt[1] == '6' && salt[2] == '$')
18 return __crypt_sha512(key, salt, output);
20 return __crypt_des(key, salt, output);
23 weak_alias(__crypt_r, crypt_r);