OSDN Git Service

microblaze: Remove duplicate F_{S,G}ETPIPE_SZ
[uclinux-h8/uClibc.git] / libcrypt / crypt.c
index 57181dc..f79c9fe 100644 (file)
@@ -1,40 +1,30 @@
 /* vi: set sw=4 ts=4: */
 /*
  * crypt() for uClibc
- *
- * Copyright (C) 2000 by Lineo, inc. and Erik Andersen
- * Copyright (C) 2000,2001 by Erik Andersen <andersen@uclibc.org>
- * Written by Erik Andersen <andersen@uclibc.org>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Library General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Copyright (C) 2000-2006 by Erik Andersen <andersen@uclibc.org>
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  */
 
-#define __FORCE_GLIBC
-#include <crypt.h>
 #include <unistd.h>
+#include <crypt.h>
+#include "libcrypt.h"
 
-extern char * __md5_crypt( const char *pw, const char *salt);
-extern char * __des_crypt( const char *pw, const char *salt);
-
-extern char * crypt(const char *key, const char *salt)
+char *crypt(const char *key, const char *salt)
 {
-       /* First, check if we are supposed to be using the MD5 replacement
-        * instead of DES...  */
-       if (salt[0]=='$' && salt[1]=='1' && salt[2]=='$')
-               return __md5_crypt(key, salt);
-       else
-               return __des_crypt(key, salt);
-}
+       const unsigned char *ukey = (const unsigned char *)key;
+       const unsigned char *usalt = (const unsigned char *)salt;
 
+       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
+       }
+       return __des_crypt(ukey, usalt);
+}