1570af302Sopenharmony_ci#include <crypt.h>
2570af302Sopenharmony_ci
3570af302Sopenharmony_cichar *__crypt_r(const char *key, const char *salt, struct crypt_data *data)
4570af302Sopenharmony_ci{
5570af302Sopenharmony_ci	/* Per the crypt_r API, the caller has provided a pointer to
6570af302Sopenharmony_ci	 * struct crypt_data; however, this implementation does not
7570af302Sopenharmony_ci	 * use the structure to store any internal state, and treats
8570af302Sopenharmony_ci	 * it purely as a char buffer for storing the result. */
9570af302Sopenharmony_ci	char *output = (char *)data;
10570af302Sopenharmony_ci	if (salt[0] == '$' && salt[1] && salt[2]) {
11570af302Sopenharmony_ci		if (salt[1] == '1' && salt[2] == '$')
12570af302Sopenharmony_ci			return __crypt_md5(key, salt, output);
13570af302Sopenharmony_ci		if (salt[1] == '2' && salt[3] == '$')
14570af302Sopenharmony_ci			return __crypt_blowfish(key, salt, output);
15570af302Sopenharmony_ci		if (salt[1] == '5' && salt[2] == '$')
16570af302Sopenharmony_ci			return __crypt_sha256(key, salt, output);
17570af302Sopenharmony_ci		if (salt[1] == '6' && salt[2] == '$')
18570af302Sopenharmony_ci			return __crypt_sha512(key, salt, output);
19570af302Sopenharmony_ci	}
20570af302Sopenharmony_ci	return __crypt_des(key, salt, output);
21570af302Sopenharmony_ci}
22570af302Sopenharmony_ci
23570af302Sopenharmony_ciweak_alias(__crypt_r, crypt_r);
24