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

Defined functions

comminit defined in line 81; used 2 times
mka defined in line 45; used 1 times
mkb defined in line 67; used 2 times
mkx defined in line 30; used 2 times
nin defined in line 101; never used
nout defined in line 96; never used
setup defined in line 8; used 2 times
xfatal defined in line 109; used 6 times

Defined variables

sccsid defined in line 2; never used
Last modified: 1983-06-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1187
Valid CSS Valid XHTML 1.0 Strict