convA2M.c 501 B

12345678910111213141516171819202122232425
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <authsrv.h>
  4. #define CHAR(x) *p++ = f->x
  5. #define SHORT(x) p[0] = f->x; p[1] = f->x>>8; p += 2
  6. #define VLONG(q) p[0] = (q); p[1] = (q)>>8; p[2] = (q)>>16; p[3] = (q)>>24; p += 4
  7. #define LONG(x) VLONG(f->x)
  8. #define STRING(x,n) memmove(p, f->x, n); p += n
  9. int
  10. convA2M(Authenticator *f, char *ap, char *key)
  11. {
  12. int n;
  13. uchar *p;
  14. p = (uchar*)ap;
  15. CHAR(num);
  16. STRING(chal, CHALLEN);
  17. LONG(id);
  18. n = p - (uchar*)ap;
  19. if(key)
  20. encrypt(key, ap, n);
  21. return n;
  22. }