void imf2 ( imf2_data_t *y, imf2_data_t x ) { const imf2_coef_t c[12]={ #include "imf2_coef.h" }; /* Transposed form FIR poly branches */ static imf2_acc_t shift_reg_p[13][2]; static imf2_data_t in = 0; imf2_acc_t acc; static uint1 init = 1; static uint2 cnt = 0; static uint1 ch = 0; static uint4 i = 0; L1: //Latch input if (i==0) { in = x; } uint4 inc = i+1; //Calculate tap acc = mac2(c[i], in, (init || i==5 || i==11) ? 0 : shift_reg_p[inc][ch]); //Shift shift_reg_p[i][ch] = acc; if (i==11) { if (cnt == 3) { if (ch) init = 0; ch = !ch; } cnt++; } //Output if ((i==0) || (i==6)) { *y = acc >> 17; }
/* * check: read logfile and check it */ void check(void) { FILE *finput; int i; int input; int mfd; unsigned char key[41]; int keylen; unsigned char lastkey[21]; int lastkeylen; int line; unsigned char mkey1[21]; int mkey1len; unsigned char mkey2[21]; int mkey2len; char msg[MAXLINE]; int msglen; /* open logfile */ if (actionf & ST_IN) input = STDIN_FILENO; else if ( (input = open(logfile, O_RDONLY, 0)) == -1) { perror(logfile); exit(-1); } mfd = 0; /* shutup gcc */ /* open macfile */ if (macfile) if ( (mfd = open(macfile, O_RDONLY, 0)) == -1) { perror(macfile); exit(-1); } /* read initial key (as ascii string) and tranlate it to binary */ if ( (i = open(key0file, O_RDONLY, 0)) == -1) { perror(key0file); exit(-1); } if ( (keylen = read(i, key, 40)) == -1) { perror(key0file); exit(-1); } if (!keylen) { if (actionf & QUIET) eexit(1, "1\n"); else eexit(1, "(1) %s: %s\n", key0file, corrupted); } key[keylen] = 0; asc2bin(key, key); keylen >>= 1; close(i); /* read last key */ if ( (i = open(keyfile, O_RDONLY, 0)) == -1) { perror(keyfile); exit(-1); } if ( (lastkeylen = read(i, lastkey, 20)) == -1) { perror(keyfile); exit(-1); } if (!lastkeylen) { if (actionf & QUIET) eexit(1, "1\n"); else eexit(1, "(1) %s: %s\n", keyfile, corrupted); } close(i); /* test both key lenghts */ if (lastkeylen != keylen) { if (actionf & QUIET) eexit(1, "1\n"); else eexit(1, "(1) %s and/or %s %s\n", key0file, keyfile, corrupted); } /* check it */ line = 1; finput = NULL; while ( (msglen = readline(input, msg, MAXLINE, &finput)) > 0) { if (macfile) { if ( ((mkey1len = mac2(key, keylen, (unsigned char *) msg, msglen, mkey1)) < 0) || ((mkey2len = read(mfd, mkey2, mkey1len)) < 0) ) { perror(macfile); exit(-1); } if ((mkey2len != mkey1len) || memcmp(mkey2, mkey1, mkey1len)) { if (actionf & QUIET) eexit(1, "%i\n", line); else eexit(1, "(%i) %s %s on line %i\n", line, logfile, corrupted, line); } line++; } if ( (keylen = mac(method, key, keylen, (unsigned char *) msg, msglen, key)) == -1) { perror("fatal"); exit(-1); } } if (finput != NULL) fclose(finput); if (macfile != NULL) close(mfd); if (i < 0) { fprintf(stderr, "error reading logs form %s : %s\n", (actionf & ST_IN) ? "standard input" : logfile, strerror(errno)); exit(-1); } if (memcmp(lastkey, key, keylen)) { if (actionf & QUIET) eexit(1, "1\n"); else eexit(1, "(1) %s %s\n", logfile, corrupted); } if (actionf & QUIET) eexit(0, "0\n"); else eexit(0, "(0) %s file is ok\n", logfile); }