Update.
[glibc.git] / sysdeps / generic / crypt-entry.c
blob8248ed9ba397cb25675ce52b78fda86749f089d7
1 /* Wrapper around MD5 sum replacement for crypt function.
2 Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C 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 the GNU C 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. */
21 #include <crypt.h>
22 #include <errno.h>
23 #include <string.h>
26 /* Define our magic string to mark salt for MD5 encryption
27 replacement. This is meant to be the same as for other MD5 based
28 encryption implementations. */
29 static const char md5_salt_prefix[] = "$1$";
32 /* Prototypes for the MD5 encryption replacement functions. */
33 extern char *__md5_crypt_r (const char *key, const char *salt, char *buffer,
34 int buflen);
35 extern char *__md5_crypt (const char *key, const char *salt);
37 extern char *__crypt_r (const char *key, const char *salt,
38 struct crypt_data *__restrict data);
40 /* We recognize an intended call of the MD5 crypt replacement function
41 by the first 3 characters of the salt string. If they match the
42 MD5 magic string we want MD5 encryption replacement. */
43 char *
44 __crypt_r (key, salt, data)
45 const char *key;
46 const char *salt;
47 struct crypt_data *__restrict data;
49 if (strncmp (md5_salt_prefix, salt, sizeof (md5_salt_prefix) - 1) == 0)
50 return __md5_crypt_r (key, salt, (char *) data,
51 sizeof (struct crypt_data));
53 /* We don't have DES encryption. */
54 __set_errno (EOPNOTSUPP);
55 return NULL;
57 weak_alias (__crypt_r, crypt_r)
60 /* The same here, only we call the non-reentrant version. */
61 char *
62 crypt (key, salt)
63 const char *key;
64 const char *salt;
66 if (strncmp (md5_salt_prefix, salt, sizeof (md5_salt_prefix) - 1) == 0)
67 return __md5_crypt (key, salt);
69 /* We don't have DES encryption. */
70 __set_errno (EOPNOTSUPP);
71 return NULL;