update from main archive 970209
[glibc.git] / sysdeps / generic / crypt-entry.c
blobba23d1f3d44a825245eca8584ec12b3fce8281c9
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, sizeof (struct crypt_data));
50 /* We don't have DES encryption. */
51 __set_errno (EOPNOTSUPP);
52 return NULL;
56 /* The same here, only we call the non-reentrant version. */
57 char *
58 crypt (key, salt)
59 const char *key;
60 const char *salt;
62 if (strncmp (md5_salt_prefix, salt, sizeof (md5_salt_prefix) - 1) == 0)
63 return md5_crypt (key, salt);
65 /* We don't have DES encryption. */
66 __set_errno (EOPNOTSUPP);
67 return NULL;