libm: fix nexttoward failures, fixed by sorear
[uclibc-ng.git] / libcrypt / crypt.c
blobcfcd11f91237ea62cab2021e13976a7a7b0db190
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 */
7 #include <unistd.h>
8 #include <crypt.h>
9 #include <errno.h>
10 #include "libcrypt.h"
12 char *crypt(const char *key, const char *salt)
14 const unsigned char *ukey = (const unsigned char *)key;
15 const unsigned char *usalt = (const unsigned char *)salt;
17 if (salt[0] == '$') {
18 if (salt[1] && salt[2] == '$') { /* no blowfish '2X' here ATM */
19 if (*++salt == '1')
20 return __md5_crypt(ukey, usalt);
21 #ifdef __UCLIBC_HAS_SHA256_CRYPT_IMPL__
22 else if (*salt == '5')
23 return __sha256_crypt(ukey, usalt);
24 #endif
25 #ifdef __UCLIBC_HAS_SHA512_CRYPT_IMPL__
26 else if (*salt == '6')
27 return __sha512_crypt(ukey, usalt);
28 #endif
30 __set_errno(EINVAL);
31 return NULL;
33 return __des_crypt(ukey, usalt);