#include #include #include "servauth.h" short int Year /* 0x2585e */; short int Month /* 0x25892 */; short int Day /* 0x2592c */; short int Hour /* 0x2580c */; char Stim2[64] /* 0x257cc */; short int LoadKeyInfo2(struct packedkey *pk /*0x44*/, caddr_t keyfile /*0x48*/, caddr_t username /*0x4c*/) { /* 0x14ffc */ short int k /* 0xfffffe7e */; char linebuf[256] /* 0xfffffe80 */; FILE *fd_in /* 0xffffff80 */; int found /* 0xffffff84 */; caddr_t root /* 0xffffff88 */; caddr_t tomorrow /* 0xffffff8c */; caddr_t today /* 0xffffff90 */; caddr_t daycut_str /* 0xffffff94 */; caddr_t serialno /* 0xffffff98 */; caddr_t username_in /* 0xffffff9c */; long int loc_dc /* 0xffffffa0 */; long int count /* 0xffffffa4 */; char root_s[20] /* 0xffffffa8 */; char tomorrow_s[20] /* 0xffffffc0 */; char today_s[20] /* 0xffffffd8 */; found = 0; if (!(fd_in = fopen(keyfile, "r"))) { return -1; } while (fgets(linebuf, 255, fd_in)) { /*15070*/ username_in = strtok(linebuf, ","); if (!strcmp(username, username_in)) { /*150a8*/ found = 1; serialno = strtok(NULL, ","); daycut_str = strtok(NULL, ","); today = strtok(NULL, ","); tomorrow = strtok(NULL, ","); root = strtok(NULL, ","); /*15128*/ strncpy(pk->pk_key_serial_number, serialno, 11); sscanf(daycut_str, "%lu" , &loc_dc); pk->pk_daycut = loc_dc; if (HexToVal(today, pk->pk_today, 16) == -1) { /*1518c*/ fclose(fd_in); return -1; } else { /*151a4*/ HexToVal(tomorrow, pk->pk_tomorrow, 8); HexToVal(root, pk->pk_root, 6); } } } /*151dc*/ fclose(fd_in); return found - 1; } void GenerateChallengeBits (short int Randnum /* 0xffffffee */, caddr_t Stim /* 0x48 */){ /* 0x118f0 */ char IStim[70] /* 0xffffffa0 */; short unsigned int StimLen /* 0xffffffea */; short unsigned int i /* 0xffffffec */; StimLen = 18; for(i = 0; i <= 59; i++) /*LOOP1*/ { Stim[i] = 0; Stim2[i] = 0; } /*11978*/ Stim[0] = 1; Stim[1] = 1; Stim[2] = 0; Stim[3] = 1; Stim[4] = 0; Stim[5] = 0; Stim[6] = 1; for(i = 7; i <= 16; i++, Randnum >>= 1) /*LOOP2*/ { Stim[i] = Randnum & 1; } /*11a80*/ for(i = 0; i < StimLen; i++) /*LOOP3*/ { IStim[i] = Stim[i]; } /*11afc*/ for(i = StimLen; i < StimLen + 6; i++) /*LOOP4*/ { IStim[i] = 1; } /*11b68*/ for(i = 6; i < StimLen; i++) /*LOOP5*/ { if (IStim[i] != 0) { /*11bc8*/ IStim[i + 5] = 1 - IStim[i + 5]; // XXX check IStim[i + 6] = 1 - IStim[i + 6]; } } /*11c68*/ for(i = StimLen; i < StimLen + 6; i++) /*LOOP6*/ { Stim[i] = IStim[i]; } } short int VerifyResponse (struct packedkey *PackedKeyInfo /*0x44*/, caddr_t Stim /*0x48*/, caddr_t Answer /*0x4c*/) { short int iok /* 318 fp_13e 0xfffffec2 */; short unsigned int i /* -316 fp_13c 0xfffffec4 */; short unsigned int RolCount /* fp_13a 0xfffffec6 */; char f1[44] /* -312 fp_138 0xfffffec8 */; char Td[66] /* fp_108 0xfffffef8 */; char f[44] /* fp_c0 0xffffff40 */; struct Keyinfo KeyRec[1] /* fp_90 0xffffff70 */; /*346:*/ unpack(PackedKeyInfo, KeyRec); /*347:*/ MapAnswer(Answer, f); /*349:*/ //PrintBitStr(KeyRec->Today, 64, "\n"/*0x0a*/); /*350:*/ //PrintBitStr(KeyRec->Tomorrow, 32, "\n"/*0x0a*/); /*351:*/ //PrintBitStr(KeyRec->Root, 24 /*zou 23 moeten zijn!*/, "\n"/*0x0a*/); /*352:*/ GetDate(); /*353:*/ RolCount = GetChanges(KeyRec->DayCut, f[23]); /*355:*/ ApplyChanges(KeyRec->Today, KeyRec->Tomorrow, RolCount, Td); /*357:*/ InvertAnswer(f, Td, f1); /*1298c*/ PrintBitStr(f1, 23, "\n"); for(i = 0; i <= 22; i++) { f1[i] ^= KeyRec->Root[i]; } /*12a14*/ if (Stim[23] != f1[22]) { for(i = 10; i <= 22; i++) { f1[i] = nnot(f1[i]); } } /*12acc*/ iok = 0; for(i = 5; i <= 22; i++) { if (Stim[i +1] != f1[i]) { iok = -1; break; } } return iok; } void unpack(struct packedkey* packedp /*fp44*/, struct Keyinfo *unpackedp /*fp48*/) { char byte; /*fp_21*/ short bit; /*fp_20*/ unsigned short bitcount; /*fp_18*/ /*871:*/ unpackedp->DayCut = packedp->pk_daycut; bitcount = 1; byte = 2; for(bit = 0x16; bit >= 0; bit--) { if ((bit == 0x0f) || (bit == 0x07)) { bitcount = 0; byte--; } unpackedp->Root[bit] = (packedp->pk_root[byte] & (0x80 >> bitcount)) ? 1 : 0; bitcount++; } bitcount = 0; byte = 3; for(bit = 0x1f; bit >= 0; bit--) { if ((bit == 0x0f) || (bit == 0x07) || (bit == 0x17)) { bitcount = 0; byte--; } unpackedp->Tomorrow[bit] = (packedp->pk_tomorrow[byte] & (0x80 >> bitcount)) ? 1 : 0; bitcount++; } bitcount = 0; byte = 7; for(bit = 0x3f; bit >= 0; bit--) { if (bitcount == 8) { bitcount = 0; byte--; } unpackedp->Today[bit] = (packedp->pk_today[byte] & (0x80 >> bitcount)) ? 1 : 0; bitcount++; } } static void MapAnswer (caddr_t Answer /* 0x44 */, caddr_t f /* 0x48 */) { /* 0x13be0 */ /* file /home/rchen/v/code/libgord.c line 645 addr 0x13be0 */ /* 0x13bec */ short unsigned int PermTab[24] /* -608 0xfffffda0 */; short unsigned int CharTab[256] /* -560 0xfffffdd0 */; short unsigned int val /* -48 0xffffffd0 */; short unsigned int c /* -46 0xffffffd2 */; short unsigned int j /* -44 0xffffffd4 */; short unsigned int i /* -42 0xffffffd6 */; char f1[24] /* -40 0xffffffd8 */; for (c=0; c<=255; c++) CharTab[c] = 0; /* 0x13c48 */ /* 9A7F8LCEP304UH25 * 0123456789ABCDEF */ CharTab[48] = 10; /* 0 */ CharTab[49] = 0; CharTab[50] = 14; /* 2 */ CharTab[51] = 9; /* 3 */ CharTab[52] = 11; /* 4 */ CharTab[53] = 15; /* 5 */ CharTab[54] = 0; CharTab[55] = 2; /* 7 */ CharTab[56] = 4; /* 8 */ CharTab[57] = 0; CharTab[65] = 1; /* A */ CharTab[66] = 4; /* B */ CharTab[67] = 6; /* C */ CharTab[68] = 0; CharTab[69] = 7; /* E */ CharTab[70] = 3; /* F */ CharTab[71] = 0; CharTab[72] = 13; /* H */ CharTab[73] = 0; CharTab[74] = 0; CharTab[75] = 0; CharTab[76] = 5; /* L */ CharTab[77] = 0; CharTab[78] = 0; CharTab[79] = 10; /* O */ CharTab[80] = 8; /* P */ CharTab[81] = 0; CharTab[82] = 1; /* R */ CharTab[83] = 15; /* S */ CharTab[84] = 0; CharTab[85] = 12; /* U */ CharTab[86] = 0; CharTab[87] = 0; CharTab[88] = 0; CharTab[89] = 0; CharTab[90] = 0; /* 'Z' */ /* 0x13d24 */ for (c = 'a'; c <= 'z'; c++) { CharTab[c] = CharTab[ord (c) + ord ('A') - ord ('a')]; } /* 0x13df4 */ PermTab[0] = 0x10; PermTab[1] = 0x0e; PermTab[2] = 0x04; PermTab[3] = 0x0c; PermTab[4] = 0x0a; PermTab[5] = 0x17; PermTab[6] = 0x15; PermTab[7] = 0x03; PermTab[8] = 0x16; PermTab[9] = 0x01; PermTab[10] = 0x13; PermTab[11] = 0x07; PermTab[12] = 0x0d; PermTab[13] = 0x11; PermTab[14] = 0x14; PermTab[15] = 0x09; PermTab[16] = 0x06; PermTab[17] = 0x0f; PermTab[18] = 0x0b; PermTab[19] = 0x00; PermTab[20] = 0x08; PermTab[21] = 0x12; PermTab[22] = 0x02; PermTab[23] = 0x05; for (i=1; i<7; i++) /* 0x13eb0 */ { val = CharTab[Answer[i-1]]; for (j=0; j<4; j++) /* 0x13f10 */ { f1[(24+j)-(4*i)] = val & 1; /* max 27 - 4 = 23, min 24 - 24 = 0, klopt */ val>>=1; } } /* 0x13fb4 */ for (i=0; i<=23; i++) { /* 0x13fd8 */ f[PermTab[i]] = f1[i]; } } char UnCharTab[] = { 0x39,0x41,0x37,0x46, 0x38,0x4c,0x43,0x45, 0x50,0x33,0x30,0x34, 0x55,0x48,0x32,0x35}; char PermTab[] = {0x10, 0xe, 0x4, 0xc, 0xa, 0x17, 0x15, 0x3, 0x16, 0x1, 0x13, 0x7, 0xd, 0x11, 0x14, 0x9, 0x6, 0xf, 0xb, 0x0, 0x8, 0x12, 0x2, 0x5}; static void UnMapAnswer (caddr_t Answer /* 0x44 */, caddr_t f /* 0x48 */) { /* 0x13a38 */ short int val /* -48 0xffffffd0 */; short int c /* -46 0xffffffd2 */; short int j /* -44 0xffffffd4 */; short int i /* -42 0xffffffd6 */; char f1[24] /* -40 0xffffffd8 */; for (i=0; i<=23; i++) f1[i] = f[PermTab[i]]; /* 0x13ac8 */ for (i=1; i<7; i++) /* 0x13ad0 */ { val = 0; for (j=3; j>=0; j++) /* 0x13af8 */ { val <<= 1; val += f1[(24+j)-(4*i)]; } Answer[i-1] = UnCharTab[val]; } } caddr_t PrintBitStr(caddr_t data, int count, caddr_t addendum) { int i; for (i = 0; i < count; i++) printf("%c", data[i] + '0'); printf("%s", addendum); return NULL; } static char nnot (char c) { return (c == 0) ? (char) 1 : (char) 0; } int HexToVal (caddr_t buf /* 0x44 */, caddr_t data /* 0x48 */, int count /* 0x4c */) { /* 0x14cbc */ unsigned char nibble2 /* 0xffffffe6 */; unsigned char nibble1 /* 0xffffffe7 */; caddr_t dp /* 0xffffffe8 */; caddr_t bp /* 0xffffffec */; dp = &data[count / 2]; bp = buf; while(count > 0) { /*14d0c*/ count -= 2; dp--; nibble1 = hch2val(bp[0]); nibble2 = hch2val(bp[1]); if ((nibble1 == 0xff) || (nibble2 == 0xff)) return -1; *dp = (nibble1 << 4) + nibble2; bp += 2; } return 0; } unsigned char hch2val (char a_byte /* 0xffffffef */) { a_byte -= '0'; if (a_byte < 0) return -1; if (a_byte < 10) return a_byte; a_byte -= 17; if (a_byte < 0) return -1; if (a_byte < 6) return a_byte + 10; return -1; } static short unsigned int ord (short unsigned int c /* 0xffffffee */) { return c; } void GetDate() { long int t /* 0xffffffe8 */; struct tm /* id 17 */ *tm1 /* 0xffffffec */; t = time(NULL); tm1 = localtime(&t); /* !!! localtime niet gmtime */ Year = tm1->tm_year + 1900; //year Month = tm1->tm_mon + 1; //month Day = tm1->tm_mday; //mday Hour = tm1->tm_hour; //hour } static short unsigned int GetChanges(short unsigned int DayCut /*0xffffffee*/, char Isodd /*0xffffffed*/) { /* the VASCO folks created a large bug here by using shorts, yuck!*/ short int Changes /* 0xffffffe0 */; /*short*/ int c /* 0xffffffe2 */; long int c1 /* 0xffffffe4 */; /*short*/ int m /* 0xffffffe8 */; /*short*/ int d /* 0xffffffea */; /*812:*/ d = (Year - 1976) * 1461; /*140f8*/ /*813:*/ m = Month - 3; if (m < 0) { /*14120*/ m += 12; d -= 1461; } d = d / 4 + (m * 153) / 5 + Day - DayCut; /*141b8*/ /*821:*/ c1 = d; /*822:*/ c1 = (c1 * 24 + Hour) * 1800; c = c1 / 65536; /*827:*/ //Changes = ((c < 0) ? c + 1 : c) >> 1; Changes = c / 2; /*14254*/ if ((Changes & 1) != Isodd) { /*14284*/ if ((c & 1) == 0) { /*142b4*/ Changes--; } else { /*142a0*/ Changes++; } } return Changes; } void ApplyChanges (caddr_t Td0 /*0x44*/, caddr_t Tm0 /*0x48*/, short unsigned int ChgCount /*0xffffffee*/, caddr_t Td1 /*0x50*/) { char Tm[41] /* 0xfffffeb0 */; char Td[235] /* 0xfffffee0 */; caddr_t PVB /* 0xffffffd0 */; caddr_t PTm /* 0xffffffd4 */; caddr_t PTd /* 0xffffffd8 */; caddr_t PTd1 /* 0xffffffdc */; caddr_t PTm0 /* 0xffffffe0 */; caddr_t PTd0 /* 0xffffffe4 */; short unsigned int j /* 0xffffffe8 */; short unsigned int i /* 0xffffffea */; short unsigned int c /* 0xffffffec */; /*123e8*/ if (ChgCount != 0) { PTd0 = Td0; PTm0 = Tm0; PTd1 = Td1; PTd = Td; PTm = Tm; PVB = Tm0 + 16; for(i = 0; i <= 15; i++) /*LOOP1*/ { PTm[i] = PTm0[i]; } /*124a0*/ for(i = 0; i <= 15; i++) /*LOOP2*/ { PTm[i + 16] = PVB[i]; } /*12510*/ for(i = 0; i <= 63; i++) /*LOOP3*/ { PTd[i] = PTd0[i]; } /*12584*/ for(c = 0; c < ChgCount; c++) /*LOOP4*/ { for(i = 0; i <= 71; i++) /*LOOP41*/ { /*125d8*/ if (PTd[i] != 0) { /*12608*/ for(j = 0; j <= 31; j++) /*LOOP411*/ { if (PTm[j] == 0) { /*126c8*/ PTd[i + j + 33] = nnot(PTd[i + j + 33]); } else { /*1265c*/ PTd[i + j + 1] = nnot(PTd[i + j + 1]); } } } /*12744*/ PTd[i + 64] = PTd[i]; } /*12790*/ for(i = 0; i <= 63; i++) /*LOOP42*/ { PTd[i] = PTd[i + 72]; } } /*12818*/ for(i = 0; i <= 63; i++) /*LOOP5*/ { PTd1[i] = PTd[i]; } } } static void InvertAnswer(caddr_t f0 /*0x44*/, caddr_t Td /*0x48*/, caddr_t f1 /*0x4c*/) { char b /* 0xffffff1f */; char f[64] /* 0xffffff20 */; char poly[24] /* 0xffffff60 */; char nlb[54] /* 0xffffff78 */; char nla[50] /* 0xffffffb0 */; short unsigned int c /* 0xffffffe8 */; short unsigned int i /* 0xffffffea */; short int ib /* 0xffffffec */; short int ia /* 0xffffffee */; /*413:*/ for(i = 0; i <= 23; i++) { /*414:*/ f[i] = f0[i]; } /*12c0c*/ /*416:*/ for(i = 0; i <= 11; i++) { /*418:*/ poly[i] = Td[i]; /*419:*/ poly[i + 12] = nnot(Td[i]); } /*12cc4*/ /*422:*/ for(i = 0; i <= 24; i++) { /*424:*/ nla[i] = Td[i + 12]; /*425:*/ nla[i + 25] = nnot(Td[i + 12]); } /*12d74*/ /*428:*/ for(i = 0; i <= 26; i++) { /*430:*/ nlb[i] = Td[i + 37]; /*431:*/ nlb[i + 27 ] = nnot(Td[i + 37]); } /*12e24*/ /*434:*/ ia = 51; /*435:*/ ib = 28; /*437:*/ for(c = 1; c <= 225; c++) /*LOOP5*/ { /*439:*/ for(i = 0; i <= 21; i++) /*LOOP51*/ { /*440:*/ f[i + 24] = f[i]; } /*12ec8*/ f[0] = f[22]; f[23] = nnot(f[0]); ia -= 2; ib -= 2; /*12f04*/ for(i = 22; i != 0; i--) /*LOOP52*/{ /*12f2c*/ ia--; if (ia < 0) { ia += 50; } /*12f5c*/ ib--; if (ib < 0) { ib += 54; } /*12f8c*/ if (nlb[ib] == 0) { /*13024*/ b = nnot(f[i + 6]) & f[i + 21]; } else { /*12fb8*/ b = nnot(f[i + 19]) & nnot(f[i + 22]); } /*13070*/ if (nla[ia] == 0) { /*13108*/ b |= nnot(f[i + 14]) & f[i + 1]; } else { /*1309c*/ b |= f[i + 3] & f[i + 8] & f[i + 12]; } /*13160*/ f[i + 23] = 1 - (f[i + 23] ^ b); /*XXX check to be sure*/ /*131b0*/ f[i] = (f[0] & poly[i]) ^ f[i + 23]; } } /*13240*/ for(i = 0; i <= 23; i++) /*LOOP6*/ { f1[i] = f[i]; } } static void DeriveAnswer(caddr_t f0 /*0x44*/, caddr_t Td /*0x48*/, caddr_t f1 /*0x4c*/) { char b /* 0xffffff1f */; char f[64] /* 0xffffff20 */; char poly[24] /* 0xffffff60 */; char nlb[54] /* 0xffffff78 */; char nla[50] /* 0xffffffb0 */; short unsigned int c /* 0xffffffe8 */; short unsigned int i /* 0xffffffea */; short /*unsigned, moet signed zijn*/ int ib /* 0xffffffec */; short /*unsigned, moet signed zijn*/ int ia /* 0xffffffee */; for(i = 0; i <= 22/*niet 23*/; i++) /*LOOP1*/ { /*132ec*/ f[i] = f1[i]; } for(i = 0; i <= 11; i++) /*LOOP2*/ { poly[i] = Td[i]; poly[i + 12] = nnot(Td[i]); } /*133f0*/ for(i = 0; i <= 24; i++) /*LOOP3*/ { nla[i] = Td[i + 12]; nla[i + 25] = nnot(Td[i + 12]); } /*134a0*/ for(i = 0; i <= 26; i++) /*LOOP4*/ { nlb[i] = Td[i + 37]; nlb[i + 27] = nnot(Td[i + 37]); } /*13550*/ ia = 1; ib = 28; for(c = 225; c != 0; c--) /*LOOP5*/ { f[23] = nnot(f[0]); /*135a4*/ for(i = 1; i <= 22; i++) /*LOOP51*/ { /*135cc*/ if (nlb[ib] == 0) { /*13664*/ b = nnot(f[i + 6]) & f[i + 21]; } else { /*135f8*/ b = nnot(f[i + 19]) & nnot(f[i + 22]); } /*136b0*/ if (nla[i] == 0) { /*13748*/ b |= nnot(f[i + 14]) & f[i + 1]; } else { /*136dc*/ b |= f[i + 3] & f[i + 8] & f[i + 12]; } /*137a0*/ f[i + 23] = (f[0] & poly[i]) ^ f[i]; /*137f8*/ f[i + 23] = (1 - f[i + 23]) ^ b;; /*XXX check*/ /*13848*/ if (ib > 52) { ib += 0xffca; /* ib -= 54 */ } /*13874*/ ib++; if ((ia > 48) | (ia == 48) && (i == 22)) { /* 138c0 */ ia += 0xffce; /* ia -= 50 */ } /*138d4*/ ia++; } /*138f8*/ ia += 2; ib += 2; f[0] = nnot(f[23]); f[22] = f[0]; /*13934*/ for(i = 0; i <= 21; i++) { f[i] = f[i + 24]; } } /*139c0*/ for(i = 0; i <=23; i++) /*LOOP6*/ { f0[i] = f[i]; } }