1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
12 #if ENABLE_USE_BB_CRYPT
15 * DES and MD5 crypt implementations are taken from uclibc.
16 * They were modified to not use static buffers.
19 static const uint8_t ascii64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
20 #include "pw_encrypt_des.c"
21 #include "pw_encrypt_md5.c"
23 /* Other advanced crypt ids: */
24 /* $2$ or $2a$: Blowfish */
27 /* TODO: implement SHA - http://people.redhat.com/drepper/SHA-crypt.txt */
29 static struct const_des_ctx *des_cctx;
30 static struct des_ctx *des_ctx;
32 /* my_crypt returns malloc'ed data */
33 static char *my_crypt(const char *key, const char *salt)
35 /* First, check if we are supposed to be using the MD5 replacement
36 * instead of DES... */
37 if (salt[0] == '$' && salt[1] == '1' && salt[2] == '$') {
38 return md5_crypt(xzalloc(MD5_OUT_BUFSIZE), (unsigned char*)key, (unsigned char*)salt);
43 des_cctx = const_des_init();
44 des_ctx = des_init(des_ctx, des_cctx);
45 return des_crypt(des_ctx, xzalloc(DES_OUT_BUFSIZE), (unsigned char*)key, (unsigned char*)salt);
49 /* So far nobody wants to have it public */
50 static void my_crypt_cleanup(void)
58 char* FAST_FUNC pw_encrypt(const char *clear, const char *salt, int cleanup)
62 encrypted = my_crypt(clear, salt);
70 #else /* if !ENABLE_USE_BB_CRYPT */
72 char* FAST_FUNC pw_encrypt(const char *clear, const char *salt, int cleanup)
74 return xstrdup(crypt(clear, salt));