crypt.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * crypt() for uClibc
  4. *
  5. * Copyright (C) 2000 by Lineo, inc. and Erik Andersen
  6. * Copyright (C) 2000,2001 by Erik Andersen <andersen@uclibc.org>
  7. * Written by Erik Andersen <andersen@uclibc.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU Library General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  17. * for more details.
  18. *
  19. * You should have received a copy of the GNU Library General Public License
  20. * along with this program; if not, write to the Free Software Foundation,
  21. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #define __FORCE_GLIBC
  24. #include <crypt.h>
  25. #include <unistd.h>
  26. /* For use by the old, non-reentrant routines (crypt/encrypt/setkey) */
  27. static struct crypt_data __crypt_data;
  28. extern char * __md5_crypt_r( const char *pw, const char *salt, struct crypt_data * data);
  29. extern char * __des_crypt_r( const char *pw, const char *salt, struct crypt_data * data);
  30. extern char * crypt(const char *key, const char *salt)
  31. {
  32. return crypt_r (key, salt, &__crypt_data);
  33. }
  34. extern void setkey(const char *key)
  35. {
  36. setkey_r(key, &__crypt_data);
  37. }
  38. extern void encrypt(char *block, int edflag)
  39. {
  40. encrypt_r(block, edflag, &__crypt_data);
  41. }
  42. extern char *crypt_r(const char *pw, const char *salt, struct crypt_data *data)
  43. {
  44. /* First, check if we are supposed to be using the MD5 replacement
  45. * instead of DES... */
  46. if (salt[0]=='$' && salt[1]=='1' && salt[2]=='$')
  47. return __md5_crypt_r(pw, salt, data);
  48. else
  49. return __des_crypt_r(pw, salt, data);
  50. }