/* * Compute a POSIX 1003.2 checksum. This routine has been broken out so that * other programs can use it. It takes a file descriptor to read from and * locations to store the crc and the number of bytes read. It returns 0 on * success and 1 on failure. Errno is set on failure. */ int crc(int fd, u_int32_t *cval, off_t *clen) { u_char *p; ssize_t nr; u_int32_t thecrc; off_t len; u_char buf[16 * 1024]; #define COMPUTE(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)] thecrc = 0; len = 0; while ((nr = read(fd, buf, sizeof(buf))) > 0) for (len += nr, p = buf; nr--; ++p) { COMPUTE(thecrc, *p); } if (nr < 0) return 1; *clen = len; /* Include the length of the file. */ for (; len != 0; len >>= 8) { COMPUTE(thecrc, len & 0xff); } *cval = ~thecrc; return 0; }
int crc(int fd, uint32_t *cval, off_t *clen) { uint32_t lcrc; int nr; off_t len; u_char *p; u_char buf[16 * 1024]; #define COMPUTE(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)] lcrc = len = 0; crc_total = ~crc_total; while ((nr = read(fd, buf, sizeof(buf))) > 0) for (len += nr, p = buf; nr--; ++p) { COMPUTE(lcrc, *p); COMPUTE(crc_total, *p); } if (nr < 0) return (1); *clen = len; /* Include the length of the file. */ for (; len != 0; len >>= 8) { COMPUTE(lcrc, len & 0xff); COMPUTE(crc_total, len & 0xff); } *cval = ~lcrc; crc_total = ~crc_total; return (0); }
XMoshSum digestBlock( hp_byte* byteBlock, XMoshSum currentSum ) { #define COMPUTE( a, b, c, d, temp_d, f, g, i, m ) \ temp_d = d; \ d = c; \ c = b; \ b = b + LROT( ( a + f + K[ i ] + m[ g ] ), s[ i ] ); \ a = temp_d; \ hp_word32* block = ( hp_word32* ) byteBlock; hp_word32* digest_words = ( hp_word32* ) ¤tSum.data; hp_word32 A = digest_words[ 0 ]; hp_word32 B = digest_words[ 1 ]; hp_word32 C = digest_words[ 2 ]; hp_word32 D = digest_words[ 3 ]; hp_word32 F = 0; hp_word32 g = 0; hp_word32 temp_D = 0; for( int i = 0; i < 16; i++ ) { F = ( B & C ) | ( ( ~B ) & D ); g = i; COMPUTE( A, B, C, D, temp_D, F, g, i, block ); } for( int i = 16; i < 32; i++ ) { F = ( D & B ) | ( ( ~D ) & C ); g = ( ( 5 * i ) + 1 ) % 16; COMPUTE( A, B, C, D, temp_D, F, g, i, block ); } for( int i = 32; i < 48; i++ ) { F = B ^ C ^ D; g = ( ( 3 * i ) + 5 ) % 16; COMPUTE( A, B, C, D, temp_D, F, g, i, block ); } for( int i = 48; i < 64; i++ ) { F = C ^ ( B | ( ~D ) ); g = ( 7 * i ) % 16; COMPUTE( A, B, C, D, temp_D, F, g, i, block ); } digest_words[ 0 ] += A; digest_words[ 1 ] += B; digest_words[ 2 ] += C; digest_words[ 3 ] += D; return currentSum; #undef COMPUTE }
uint32_t compute_crc(uint32_t crc, uint8_t* data, size_t len) { size_t i; for(i=0; i<len; ++i) COMPUTE(crc, data[i]); return crc; }
mlib_status __mlib_VectorMinimum_D64( mlib_d64 *min, const mlib_d64 *x, mlib_s32 n) { COMPUTE(mlib_d64, D64); }
uint32_t crc_buf(uint32_t thecrc, const void *buf, size_t len) { const uint8_t *p = buf; for (p = buf; len; p++, len--) COMPUTE(thecrc, *p); return thecrc; }
mlib_status __mlib_VectorMinimum_F32( mlib_f32 *min, const mlib_f32 *x, mlib_s32 n) { COMPUTE(mlib_f32, F32); }
int crc(u_char* psrc, uint32_t *cval, int clen) { uint32_t lcrc; int nr; off_t len; u_char *pbuf; int total_len = clen; #define COMPUTE(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)] lcrc = len = 0; crc_total = ~crc_total; pbuf = psrc; while (total_len>0) { if (total_len >= 64) nr = 64; else nr = total_len; total_len-=nr; for (len += nr; nr--; ++pbuf) { COMPUTE(lcrc, *pbuf); COMPUTE(crc_total, *pbuf); } } /* Include the length of the file. */ for (; len != 0; len >>= 8) { COMPUTE(lcrc, len & 0xff); COMPUTE(crc_total, len & 0xff); } *cval = ~lcrc; crc_total = ~crc_total; return (0); }
int crc(int fd, u_int32_t *cval, u_int32_t *clen) { u_char *p; int nr; u_int32_t thecrc, len; u_int32_t crctot; u_char buf[16 * 1024]; #define COMPUTE(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)] thecrc = len = crctot = 0; if (sflag) crctot = ~crc_total; while ((nr = read(fd, buf, sizeof(buf))) > 0) if (sflag) { for (len += nr, p = buf; nr--; ++p) { COMPUTE(thecrc, *p); COMPUTE(crctot, *p); } } else { for (len += nr, p = buf; nr--; ++p) COMPUTE(thecrc, *p); } if (nr < 0) return 1; *clen = len; /* Include the length of the file. */ if (sflag) { for (; len != 0; len >>= 8) { COMPUTE(thecrc, len & 0xff); COMPUTE(crctot, len & 0xff); } } else { for (; len != 0; len >>= 8)
ACE_UINT16 ACE::crc_ccitt (const void *buffer, size_t len, ACE_UINT16 crc) { crc = ~crc; for (const char *p = (const char *) buffer, *e = (const char *) buffer + len; p != e; ++p) { COMPUTE (crc, *p); } return ~crc; }
// Open versioned namespace, if enabled by the user. ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_UINT16 ACE::crc_ccitt (const char *string) { ACE_UINT16 crc = 0xFFFF; for (const char *p = string; *p != 0; ++p) { COMPUTE (crc, *p); } return ~crc; }
ACE_UINT16 ACE::crc_ccitt (const iovec *iov, int len, ACE_UINT16 crc) { crc = ~crc; for (int i = 0; i < len; ++i) { for (const char *p = (const char *) iov[i].iov_base, *e = (const char *) iov[i].iov_base + iov[i].iov_len; p != e; ++p) COMPUTE (crc, *p); } return ~crc; }
int main() { COMPUTE (); return 0; }
void computerow(struct config *cp, int pos) { COMPUTE(LLOOP, 0); /*DPRINTF(("computerow: pos=%d bx=%d bo=%d\n", pos, bx, bo));*/ }
void computecol(struct config *cp, int pos) { COMPUTE(TLOOP, bsize); /*DPRINTF(("computecol: pos=%d bx=%d bo=%d\n", pos, bx, bo));*/ }
/* NOTE: this function may rearrange the order of entries in the SegInfo list. */ Bool VG_(use_CF_info) ( /*MOD*/Addr* ipP, /*MOD*/Addr* spP, /*MOD*/Addr* fpP, Addr min_accessible, Addr max_accessible ) { Bool ok; Int i; SegInfo* si; DiCfSI* cfsi = NULL; Addr cfa, ipHere, spHere, fpHere, ipPrev, spPrev, fpPrev; CfiExprEvalContext eec; static UInt n_search = 0; static UInt n_steps = 0; n_search++; if (0) VG_(printf)("search for %p\n", *ipP); for (si = segInfo_list; si != NULL; si = si->next) { n_steps++; /* Use the per-SegInfo summary address ranges to skip inapplicable SegInfos quickly. */ if (si->cfsi_used == 0) continue; if (*ipP < si->cfsi_minaddr || *ipP > si->cfsi_maxaddr) continue; i = ML_(search_one_cfitab)( si, *ipP ); if (i != -1) { vg_assert(i >= 0 && i < si->cfsi_used); cfsi = &si->cfsi[i]; break; } } if (cfsi == NULL) return False; if (0 && ((n_search & 0xFFFFF) == 0)) VG_(printf)("%u %u\n", n_search, n_steps); /* Start of performance-enhancing hack: once every 16 (chosen hackily after profiling) successful searches, move the found SegInfo one step closer to the start of the list. This makes future searches cheaper. For starting konqueror on amd64, this in fact reduces the total amount of searching done by the above find-the-right-SegInfo loop by more than a factor of 20. */ if ((n_search & 0xF) == 0) { /* Move si one step closer to the start of the list. */ SegInfo* si0 = segInfo_list; SegInfo* si1 = NULL; SegInfo* si2 = NULL; SegInfo* tmp; while (True) { if (si0 == NULL) break; if (si0 == si) break; si2 = si1; si1 = si0; si0 = si0->next; } if (si0 == si && si0 != NULL && si1 != NULL && si2 != NULL) { /* si0 points to si, si1 to its predecessor, and si2 to si1's predecessor. Swap si0 and si1, that is, move si0 one step closer to the start of the list. */ tmp = si0->next; si2->next = si0; si0->next = si1; si1->next = tmp; } } /* End of performance-enhancing hack. */ if (0) { VG_(printf)("found cfisi: "); ML_(ppDiCfSI)(si->cfsi_exprs, cfsi); } ipPrev = spPrev = fpPrev = 0; ipHere = *ipP; spHere = *spP; fpHere = *fpP; /* First compute the CFA. */ cfa = 0; switch (cfsi->cfa_how) { case CFIC_SPREL: cfa = cfsi->cfa_off + spHere; break; case CFIC_FPREL: cfa = cfsi->cfa_off + fpHere; break; case CFIC_EXPR: if (0) { VG_(printf)("CFIC_EXPR: "); ML_(ppCfiExpr)(si->cfsi_exprs, cfsi->cfa_off); VG_(printf)("\n"); } eec.ipHere = ipHere; eec.spHere = spHere; eec.fpHere = fpHere; eec.min_accessible = min_accessible; eec.max_accessible = max_accessible; ok = True; cfa = evalCfiExpr(si->cfsi_exprs, cfsi->cfa_off, &eec, &ok ); if (!ok) return False; break; default: vg_assert(0); } /* Now we know the CFA, use it to roll back the registers we're interested in. */ # define COMPUTE(_prev, _here, _how, _off) \ do { \ switch (_how) { \ case CFIR_UNKNOWN: \ return False; \ case CFIR_SAME: \ _prev = _here; break; \ case CFIR_MEMCFAREL: { \ Addr a = cfa + (Word)_off; \ if (a < min_accessible \ || a+sizeof(Addr) > max_accessible) \ return False; \ _prev = *(Addr*)a; \ break; \ } \ case CFIR_CFAREL: \ _prev = cfa + (Word)_off; \ break; \ case CFIR_EXPR: \ if (0) \ ML_(ppCfiExpr)(si->cfsi_exprs,_off); \ eec.ipHere = ipHere; \ eec.spHere = spHere; \ eec.fpHere = fpHere; \ eec.min_accessible = min_accessible; \ eec.max_accessible = max_accessible; \ ok = True; \ _prev = evalCfiExpr(si->cfsi_exprs, _off, &eec, &ok ); \ if (!ok) return False; \ break; \ default: \ vg_assert(0); \ } \ } while (0) COMPUTE(ipPrev, ipHere, cfsi->ra_how, cfsi->ra_off); COMPUTE(spPrev, spHere, cfsi->sp_how, cfsi->sp_off); COMPUTE(fpPrev, fpHere, cfsi->fp_how, cfsi->fp_off); # undef COMPUTE *ipP = ipPrev; *spP = spPrev; *fpP = fpPrev; return True; }
uint32_t crc_byte(uint32_t thecrc, unsigned int byte_val) { COMPUTE(thecrc, byte_val & 0xff); return thecrc; }