Research V7 development
[unix-history] / usr / src / cmd / xsend / lib.c
CommitLineData
a24c10d4
KT
1#include "xmail.h"
2MINT *x, *b, *one, *c64, *t45, *z, *q, *r, *two, *t15;
3MINT *a[42];
4setup(s) char *s;
5{ int pf[2];
6 strncpy(buf, s, 10);
7 while(*s) *s++ = 0;
8 pipe(pf);
9 if(fork()==0)
10 {
11 close(0);
12 close(1);
13 dup(pf[0]);
14 dup(pf[1]);
15 execl("/usr/lib/makekey", "-", 0);
16 execl("/lib/makekey", "-", 0);
17 exit(1);
18 }
19 write(pf[1], buf, 10);
20 wait((int *)NULL);
21 if(read(pf[0], buf, 13) != 13)
22 { fprintf(stderr, "enroll: cannot generate key\n");
23 exit(1);
24 }
25}
26mkx()
27{ int i, j;
28 for(i=0; i<4; i++)
29 { mult(x, t15, x);
30 *z->val = (short)(rand() ^ buf[i]);
31 madd(x, z, x);
32 }
33 mdiv(x, b, q, x);
34 for(;;)
35 { gcd(b, x, q);
36 if(q->len == 1 && q->val[0] == 1)
37 return;
38 madd(x, one, x);
39 }
40}
41mka()
42{ int i, j;
43 for(i=0; i<42; i++)
44 a[i] = itom(1);
45 for(i=j=0; i<42; i++, j++)
46 { *z->val = (short)rand()&00;
47 mult(a[i], z, a[i]);
48 mult(a[i], t45, a[i]);
49 rpow(two, j, q);
50 if( i%14 == 6) j++;
51 madd(a[i], q, a[i]);
52 mult(a[i], t15, a[i]);
53 *z->val = (short)rand()&0777;
54 madd(a[i], z, a[i]);
55 mdiv(a[i], b, q, a[i]);
56 }
57 for(i=0; i<42; i++)
58 mult(a[i], x, a[i]);
59 for(i=0; i<42; i++)
60 { mdiv(a[i], b, q, a[i]);
61 }
62}
63mkb()
64{ int i, c;
65 unsigned seed;
66 seed = 123;
67 for(i=0; i<13; i++)
68 seed = seed*buf[i] + i;
69 srand(seed);
70 *b->val = 04 + (rand()&03);
71 for(i=0; i<11; i++)
72 { *z->val = (buf[i+2] + rand()) & 077;
73 mult(b, c64, b);
74 madd(b, z, b);
75 }
76}
77comminit()
78{ int i;
79 x = itom(0);
80 b = itom(1);
81 one = itom(1);
82 two = itom(2);
83 c64 = itom(64);
84 t45 = itom(1);
85 t15 = itom(1);
86 rpow(two, 45, t45);
87 rpow(two, 15, t15);
88 z = itom(1);
89 q = itom(1);
90}
91#ifndef debug
92nout(a, fd) MINT *a; FILE *fd;
93{
94 fwrite(&a->len, sizeof(int), 1, fd);
95 fwrite(a->val, sizeof(short), a->len, fd);
96}
97nin(a, fd) MINT *a; FILE *fd;
98{
99 xfree(a);
100 fread(&a->len, sizeof(int), 1, fd);
101 a->val = xalloc(a->len, "nin");
102 fread(a->val, sizeof(short), a->len, fd);
103}
104#endif
105xfatal(s) char *s;
106{
107 fprintf(stderr, "%s\n", s);
108 exit(1);
109}