OSDN Git Service

microblaze: Remove duplicate F_{S,G}ETPIPE_SZ
[uclinux-h8/uClibc.git] / libcrypt / crypt.c
index 33f98b6..f79c9fe 100644 (file)
@@ -5,38 +5,26 @@
  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  */
 
-#define __FORCE_GLIBC
-#include <crypt.h>
 #include <unistd.h>
-#include <string.h>
-#include <errno.h>
+#include <crypt.h>
 #include "libcrypt.h"
 
-typedef char *(*crypt_impl_f)(const unsigned char *pw, const unsigned char *salt);
-
-static const struct {
-       const char *salt_pfx;
-       const crypt_impl_f crypt_impl;
-} crypt_impl_tab[] = {
-       { "$1$",        __md5_crypt },
-       { NULL,         __des_crypt },
-};
-
 char *crypt(const char *key, const char *salt)
 {
        const unsigned char *ukey = (const unsigned char *)key;
        const unsigned char *usalt = (const unsigned char *)salt;
-       size_t i;
-
-       for (i = 0; i < ARRAY_SIZE(crypt_impl_tab); i++) {
-               if (crypt_impl_tab[i].salt_pfx != NULL &&
-                   strncmp(crypt_impl_tab[i].salt_pfx, salt, strlen(crypt_impl_tab[i].salt_pfx)))
-                       continue;
 
-               return crypt_impl_tab[i].crypt_impl(ukey, usalt);
+       if (salt[0] == '$' && salt[2] == '$') {
+               if (*++salt == '1')
+                       return __md5_crypt(ukey, usalt);
+#ifdef __UCLIBC_HAS_SHA256_CRYPT_IMPL__
+               else if (*salt == '5')
+                       return __sha256_crypt(ukey, usalt);
+#endif
+#ifdef __UCLIBC_HAS_SHA512_CRYPT_IMPL__
+               else if (*salt == '6')
+                       return __sha512_crypt(ukey, usalt);
+#endif
        }
-
-       /* no crypt implementation was found, set errno to ENOSYS and return NULL */
-       __set_errno(ENOSYS);
-       return NULL;
+       return __des_crypt(ukey, usalt);
 }