Annotation of OpenXM_contrib2/asir2000/parse/id.c, Revision 1.3
1.3 ! noro 1: /* $OpenXM: OpenXM_contrib2/asir2000/parse/id.c,v 1.2 2000/01/20 02:29:12 noro Exp $ */
1.1 noro 2: #include <stdio.h>
3:
4: static table1(),namemain(),host(),cgen(),instruction();
5:
6: #define MOD 37
7: #define MU 0xa9
8:
9: static unsigned int table[37] = {
10: 0x951abd73,0x13945025,0x3aade018,0x9eabf429,
11: 0xa93f9dc1,0x0e4250b8,0x7eacdf20,0x5edf4cf1,
12: 0x15ccd258,0xfe254fba,0xce4ab7ec,0x85be6c82,
13: 0x35de8043,0xcafc9597,0x0e6237a8,0x16c00729,
14: 0x1622eb3c,0x16d23b40,0xada88ff1,0xf21647cd,
15: 0xc4ce7500,0xac501ff2,0x9e254cc4,0x1e52f533,
16: 0x1fa449cb,0x309aaa45,0x78ae06e3,0x1f3858b2,
17: 0x781fdb92,0xa79eb329,0x7613effb,0xc01f87d1,
18: 0xad4fc2ec,0x9e60acb4,0xb41fdbb3,0x1facf09d,
19: 0x1fd027a3,
20: };
21:
22: static int p[7] = { 5, 7, 13, 23, 29, 61, 59 };
23: static int m[7] = { 1, 4, 9, 12, 16, 57, 51 };
24: static int s[7] = { 0, 3, 6, 10, 15, 20, 26 };
25:
26: static table1(seed,index,tab,r)
27: unsigned int seed;
28: int index;
29: unsigned int *tab,*r;
30: {
31: unsigned int v0,v1,v2,v3,v;
32:
33: v3 = seed & 0xff;
34: v2 = ((seed & 0xff00) >> 8) ^ v3;
35: v1 = ((seed & 0xff0000) >> 16) ^ v2;
36: v0 = ((seed & 0xff000000) >> 24) ^ v1;
37: v = tab[index];
38: *r = ((((v0&0xff)<<24)|((v1&0xff)<<16)|((v2&0xff)<<8)|(v3&0xff))^v);
39: }
40:
41: static namemain(namebuf,id)
42: char *namebuf;
43: unsigned int *id;
44: {
45: unsigned int v,i,b[4];
46:
47: v = 0;
48: while ( 1 ) {
49: for ( i = 0; i < 4; i++ ) b[i] = 0;
50: for ( i = 0; ( i < 4 ) && *namebuf; namebuf++,i++ )
51: b[i] = (int) *namebuf;
52: v ^= ( ( b[3] & 0xff ) << 24 |
53: ( b[2] & 0xff ) << 16 |
54: ( b[1] & 0xff ) << 8 |
55: ( b[0] & 0xff ) );
56: if ( *namebuf == 0 ) {
57: *id = v; return;
58: }
59: }
60: }
61:
62: static host(id)
63: unsigned int *id;
64: {
65: char name[BUFSIZ];
66:
67: #if !defined(_PA_RISC1_1)
68: if ( !(*id = gethostid()) ) {
69: #endif
70: gethostname(name,BUFSIZ);
71: if ( strlen(name) > 0x40 )
72: name[0x40] = 0;
73: namemain(name,id);
74: #if !defined(_PA_RISC1_1)
75: }
76: #endif
77: }
78:
79: static cgen(m1,m2,m3)
80: unsigned m1,m2,m3;
81: {
82: unsigned int n1,n2,n3,v1;
83: unsigned short xml;
84: unsigned int id;
85: int i;
86:
87: host(&id);
88: table1(id,id % MOD,table,&n1);
89: if ( n1 != m1 )
90: return 0;
91: xml = ((unsigned short)(m2&0xffff))^((unsigned short)(table[id%MOD]&0xffff));
92: if ( ((xml>>8)^(xml&0xff)) != MU )
93: return 0;
94: n3 = 0;
95: for ( i = 0; i < 7; i++ )
96: n3 |= ( ( ( ( m1 % p[i] ) * m[i] + ( m2 % p[i] ) ) % p[i] ) << s[i] );
97: if ( n3 != m3 )
98: return 0;
99: return 1;
100: }
101:
102: check_key()
103: {
104: unsigned int n1,n2,n3;
105: int c;
106: FILE *fp;
107: char key_file[BUFSIZ],buf[BUFSIZ];
108: extern char *asir_libdir;
109: char *asir_key;
110:
111: asir_key = (char *)getenv("ASIR_KEY");
112: if ( asir_key )
113: strcpy(key_file,asir_key);
114: else
115: key_file[0] = 0;
116: if ( !key_file[0] || !(fp = fopen(key_file,"r")) ) {
117: sprintf(key_file,"%s/asir_key",".");
118: if ( !(fp = fopen(key_file,"r")) ) {
119: sprintf(key_file,"%s/asir_key",asir_libdir);
120: if ( !(fp = fopen(key_file,"r")) ) {
121: fprintf(stderr,"asir_key not found.\n");
122: instruction();
123: }
124: }
125: }
126: while ( 1 ) {
127: c = fgetc(fp);
128: if ( c == EOF )
129: break;
130: else
131: ungetc(c,fp);
132: fgets(buf,BUFSIZ,fp);
133: sscanf(buf,"%x %x %x",&n1,&n2,&n3);
134: if ( cgen(n1,n2,n3) ) {
135: fclose(fp);
136: return;
137: }
138: }
1.2 noro 139: fprintf(stderr,"Key for this machine not found in \"%s\".\n",key_file);
1.1 noro 140: instruction();
141: }
142:
143: static instruction()
144: {
145: unsigned int id;
1.2 noro 146: extern char *asir_libdir;
1.1 noro 147:
148: host(&id);
1.2 noro 149: fprintf(stderr,
1.3 ! noro 150: "\nYou need a key for each machine on which you want to run Asir.\n\
! 151: In order to get the key, send an e-mail consisting of the following\n\
! 152: single line to risa@sec.flab.fujitsu.co.jp.\n\n\
! 153: ASIR %08x\n\n\
! 154: After a while, an e-mail will be returned containing only one line like\n\n\
! 155: YYYYYYYY YYYYYYYY YYYYYYYY\n\n\
! 156: Create '%s/asir_key'\n\
1.2 noro 157: if necessary and append the returned string to the file.\n",
158: id,asir_libdir,asir_libdir);
1.1 noro 159: ExitAsir();
160: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>