Update.
[glibc.git] / sysdeps / generic / crypt-entry.c
blobe6c2554019624b9e27ff90c9b87227ed7e1ffa27
1 /* Wrapper around MD5 sum replacement for crypt function.
2 Copyright (C) 1996, 1997 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);
38 /* We recognize an intended call of the MD5 crypt replacement function
39 by the first 3 characters of the salt string. If they match the
40 MD5 magic string we want MD5 encryption replacement. */
41 char *
42 __crypt_r (key, salt, data)
43 const char *key;
44 const char *salt;
45 struct crypt_data *data;
47 if (strncmp (md5_salt_prefix, salt, sizeof (md5_salt_prefix) - 1) == 0)
48 return __md5_crypt_r (key, salt, (char *) data,
49 sizeof (struct crypt_data));
51 /* We don't have DES encryption. */
52 __set_errno (EOPNOTSUPP);
53 return NULL;
55 weak_alias (__crypt_r, crypt_r)
58 /* The same here, only we call the non-reentrant version. */
59 char *
60 crypt (key, salt)
61 const char *key;
62 const char *salt;
64 if (strncmp (md5_salt_prefix, salt, sizeof (md5_salt_prefix) - 1) == 0)
65 return __md5_crypt (key, salt);
67 /* We don't have DES encryption. */
68 __set_errno (EOPNOTSUPP);
69 return NULL;