summaryrefslogtreecommitdiff
path: root/libcrypt/crypt.c
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2012-01-18 08:41:18 +0100
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2012-01-18 08:41:18 +0100
commitde5964178b62d4c98d43307f7d2ee5b6e0729483 (patch)
treec2f85b30f309080671c447a361f135a3c0bd0559 /libcrypt/crypt.c
parent7d7b96a3928dffdfb61ad96b7b765072a98aa988 (diff)
libcrypt: shrink crypt() again - unmodularise
modularisation added too much bloat for no benefit, undo. $ ../busybox/scripts/bloat-o-meter .lib.05/libcrypt-0.9.33-rc1-git.so lib/libcrypt-0.9.33-rc1-git.so function old new delta crypt 130 46 -84 .rodata 2704 - -2704 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-2788) Total: -2788 bytes Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'libcrypt/crypt.c')
-rw-r--r--libcrypt/crypt.c43
1 files changed, 13 insertions, 30 deletions
diff --git a/libcrypt/crypt.c b/libcrypt/crypt.c
index 188a6a081..e5274a589 100644
--- a/libcrypt/crypt.c
+++ b/libcrypt/crypt.c
@@ -6,43 +6,26 @@
*/
#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 },
-#ifdef __UCLIBC_HAS_SHA256_CRYPT_IMPL__
- { "$5$", __sha256_crypt },
-#endif
-#ifdef __UCLIBC_HAS_SHA512_CRYPT_IMPL__
- { "$6$", __sha512_crypt },
-#endif
- { 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);
}