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