crypt.c 894 B

123456789101112131415161718192021222324252627282930313233
  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 "libcrypt.h"
  9. char *crypt(const char *key, const char *salt)
  10. {
  11. const unsigned char *ukey = (const unsigned char *)key;
  12. const unsigned char *usalt = (const unsigned char *)salt;
  13. if (salt[0] == '$') {
  14. if (salt[1] && salt[2] == '$') { /* no blowfish '2X' here ATM */
  15. if (*++salt == '1')
  16. return __md5_crypt(ukey, usalt);
  17. #ifdef __UCLIBC_HAS_SHA256_CRYPT_IMPL__
  18. else if (*salt == '5')
  19. return __sha256_crypt(ukey, usalt);
  20. #endif
  21. #ifdef __UCLIBC_HAS_SHA512_CRYPT_IMPL__
  22. else if (*salt == '6')
  23. return __sha512_crypt(ukey, usalt);
  24. #endif
  25. }
  26. /* __set_errno(EINVAL);*/ /* ENOSYS might be misleading */
  27. return NULL;
  28. }
  29. return __des_crypt(ukey, usalt);
  30. }