File: convA2M.c

package info (click to toggle)
drawterm-9front 0~git20220608.bee4db6-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,256 kB
  • sloc: ansic: 57,635; makefile: 607; java: 492; objc: 436; xml: 174; asm: 19
file content (36 lines) | stat: -rw-r--r-- 630 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <u.h>
#include <libc.h>
#include <authsrv.h>

extern int form1B2M(char *ap, int n, uchar key[32]);

int
convA2M(Authenticator *f, char *ap, int n, Ticket *t)
{
	uchar *p;

	if(n < 1+CHALLEN)
		return 0;

	p = (uchar*)ap;
	*p++ = f->num;
	memmove(p, f->chal, CHALLEN), p += CHALLEN;
	switch(t->form){
	case 0:
		if(n < 1+CHALLEN+4)
			return 0;

		memset(p, 0, 4), p += 4;	/* unused id field */
		n = p - (uchar*)ap;
		encrypt(t->key, ap, n);
		return n;
	case 1:
		if(n < 12+CHALLEN+NONCELEN+16)
			return 0;

		memmove(p, f->rand, NONCELEN), p += NONCELEN;
		return form1B2M(ap, (char*)p - ap, t->key);
	}

	return 0;
}