opasstokey.c 862 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. opasstokey(char *key, char *p)
  14. {
  15. uint8_t t[10];
  16. int c, n;
  17. n = strlen(p);
  18. memset(t, ' ', sizeof t);
  19. if(n < 5)
  20. return 0;
  21. if(n > 10)
  22. n = 10;
  23. strncpy((char*)t, p, n);
  24. if(n >= 9){
  25. c = p[8] & 0xf;
  26. if(n == 10)
  27. c += p[9] << 4;
  28. for(n = 0; n < 8; n++)
  29. if(c & (1 << n))
  30. t[n] -= ' ';
  31. }
  32. for(n = 0; n < 7; n++)
  33. key[n] = (t[n] >> n) + (t[n+1] << (8 - (n+1)));
  34. return 1;
  35. }