crypt.c 875 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * crypt() for uClibc
  3. * Copyright (C) 2000-2006 by Erik Andersen <andersen@uclibc.org>
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <unistd.h>
  7. #include <crypt.h>
  8. #include <errno.h>
  9. #include "libcrypt.h"
  10. char *crypt(const char *key, const char *salt)
  11. {
  12. const unsigned char *ukey = (const unsigned char *)key;
  13. const unsigned char *usalt = (const unsigned char *)salt;
  14. if (salt[0] == '$') {
  15. if (salt[1] && salt[2] == '$') { /* no blowfish '2X' here ATM */
  16. if (*++salt == '1')
  17. return __md5_crypt(ukey, usalt);
  18. #ifdef __UCLIBC_HAS_SHA256_CRYPT_IMPL__
  19. else if (*salt == '5')
  20. return __sha256_crypt(ukey, usalt);
  21. #endif
  22. #ifdef __UCLIBC_HAS_SHA512_CRYPT_IMPL__
  23. else if (*salt == '6')
  24. return __sha512_crypt(ukey, usalt);
  25. #endif
  26. }
  27. __set_errno(EINVAL);
  28. return NULL;
  29. }
  30. return __des_crypt(ukey, usalt);
  31. }