2 * UFC-crypt: ultra fast crypt(3) implementation
4 * Copyright (C) 1991, 1992, 1993, 1996, 1997 Free Software Foundation, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; see the file COPYING.LIB. If not,
18 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * @(#)crypt-entry.c 1.2 12/20/96
37 #include "ufc-crypt.h"
40 * Thanks to greg%wind@plains.NoDak.edu (Greg W. Wettstein)
46 #include "crypt-private.h"
48 /* Prototypes for local functions. */
50 #ifndef __GNU_LIBRARY__
51 void _ufc_clearmem (char *start, int cnt);
53 #define _ufc_clearmem(start, cnt) memset(start, 0, cnt)
55 extern char *__md5_crypt_r (const char *key, const char *salt, char *buffer,
57 extern char *__md5_crypt (const char *key, const char *salt);
60 /* Define our magic string to mark salt for MD5 encryption
61 replacement. This is meant to be the same as for other MD5 based
62 encryption implementations. */
63 static const char md5_salt_prefix[] = "$1$";
65 /* For use by the old, non-reentrant routines (crypt/encrypt/setkey) */
66 extern struct crypt_data _ufc_foobar;
73 __crypt_r (key, salt, data)
76 struct crypt_data * __restrict data;
80 ufc_long xx = 25; /* to cope with GCC long long compiler bugs */
83 /* Try to find out whether we have to use MD5 encryption replacement. */
84 if (strncmp (md5_salt_prefix, salt, sizeof (md5_salt_prefix) - 1) == 0)
85 return __md5_crypt_r (key, salt, (char *) data,
86 sizeof (struct crypt_data));
90 * Hack DES tables according to salt
92 _ufc_setup_salt_r (salt, data);
97 _ufc_clearmem (ktab, (int) sizeof (ktab));
98 (void) strncpy (ktab, key, 8);
99 _ufc_mk_keytab_r (ktab, data);
102 * Go for the 25 DES encryptions
104 _ufc_clearmem ((char*) res, (int) sizeof (res));
105 _ufc_doit_r (xx, data, &res[0]);
108 * Do final permutations
110 _ufc_dofinalperm_r (res, data);
113 * And convert back to 6 bit ASCII
115 _ufc_output_conversion_r (res[0], res[1], salt, data);
116 return data->crypt_3_buf;
118 weak_alias (__crypt_r, crypt_r)
126 /* Try to find out whether we have to use MD5 encryption replacement. */
127 if (strncmp (md5_salt_prefix, salt, sizeof (md5_salt_prefix) - 1) == 0)
128 return __md5_crypt (key, salt);
131 return __crypt_r (key, salt, &_ufc_foobar);
136 * To make fcrypt users happy.
137 * They don't need to call init_des.
140 weak_alias (crypt, fcrypt)
147 return crypt (key, salt);