passtokey.c 902 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <authsrv.h>
  12. int
  13. passtokey(char *key, char *p)
  14. {
  15. uint8_t buf[ANAMELEN], *t;
  16. int i, n;
  17. n = strlen(p);
  18. if(n >= ANAMELEN)
  19. n = ANAMELEN-1;
  20. memset(buf, ' ', 8);
  21. t = buf;
  22. strncpy((char*)t, p, n);
  23. t[n] = 0;
  24. memset(key, 0, DESKEYLEN);
  25. for(;;){
  26. for(i = 0; i < DESKEYLEN; i++)
  27. key[i] = (t[i] >> i) + (t[i+1] << (8 - (i+1)));
  28. if(n <= 8)
  29. return 1;
  30. n -= 8;
  31. t += 8;
  32. if(n < 8){
  33. t -= 8 - n;
  34. n = 8;
  35. }
  36. encrypt(key, t, 8);
  37. }
  38. }