1 /* vi: set sw=4 ts=4: */
4 * Copyright (C) 2000-2006 by Erik Andersen <andersen@uclibc.org>
5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
15 typedef char *(*crypt_impl_f)(const unsigned char *pw, const unsigned char *salt);
19 const crypt_impl_f crypt_impl;
20 } crypt_impl_tab[] = {
21 { "$1$", __md5_crypt },
22 #ifdef __UCLIBC_HAS_SHA256_CRYPT_IMPL__
23 { "$5$", __sha256_crypt },
25 #ifdef __UCLIBC_HAS_SHA512_CRYPT_IMPL__
26 { "$6$", __sha512_crypt },
28 { NULL, __des_crypt },
31 char *crypt(const char *key, const char *salt)
33 const unsigned char *ukey = (const unsigned char *)key;
34 const unsigned char *usalt = (const unsigned char *)salt;
37 for (i = 0; i < ARRAY_SIZE(crypt_impl_tab); i++) {
38 if (crypt_impl_tab[i].salt_pfx != NULL &&
39 strncmp(crypt_impl_tab[i].salt_pfx, salt, strlen(crypt_impl_tab[i].salt_pfx)))
42 return crypt_impl_tab[i].crypt_impl(ukey, usalt);
45 /* no crypt implementation was found, set errno to ENOSYS and return NULL */