crypt_r.c 833 B

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