/** * Add a just-read-in checksum pair to the signature block. */ static rs_result rs_loadsig_add_sum(rs_job_t *job, rs_strong_sum_t *strong) { size_t new_size; rs_signature_t *sig = job->signature; rs_block_sig_t *asignature; sig->count++; new_size = sig->count * sizeof(rs_block_sig_t); sig->block_sigs = realloc(sig->block_sigs, new_size); if (sig->block_sigs == NULL) { return RS_MEM_ERROR; } asignature = &(sig->block_sigs[sig->count - 1]); asignature->weak_sum = job->weak_sig; asignature->i = sig->count; memcpy(asignature->strong_sum, strong, sig->strong_sum_len); if (rs_trace_enabled()) { char hexbuf[RS_MAX_STRONG_SUM_LENGTH * 2 + 2]; rs_hexify(hexbuf, strong, sig->strong_sum_len); rs_trace("read in checksum: weak=%#x, strong=%s", asignature->weak_sum, hexbuf); } job->stats.sig_blocks++; return RS_RUNNING; }
void rs_sumset_dump(rs_signature_t const *sums) { int i; rs_block_sig_t *b; char strong_hex[RS_MAX_STRONG_SUM_LENGTH * 3]; rs_log(RS_LOG_INFO|RS_LOG_NONAME, "sumset info: magic=%#x, block_len=%d, block_num=%d", sums->magic, sums->block_len, sums->count); for (i = 0; i < sums->count; i++) { b = rs_block_sig_ptr(sums, i); rs_hexify(strong_hex, b->strong_sum, sums->strong_sum_len); rs_log(RS_LOG_INFO|RS_LOG_NONAME, "sum %6d: weak="FMT_WEAKSUM", strong=%s", i, b->weak_sum, strong_hex); } }
/** * Dump signatures to the log. */ void rs_sumset_dump(rs_signature_t const *sums) { int i; char strong_hex[RS_STRONG_SUM_LEN * 3]; rs_log(RS_LOG_INFO, "sumset info: block_len=%d, file length=%lu, " "number of chunks=%d, remainder=%d", sums->block_len, (unsigned long) sums->flength, sums->count, sums->remainder); for (i = 0; i < sums->count; i++) { rs_hexify(strong_hex, sums->block_sigs[i].strong_sum, sums->strong_sum_len); rs_log(RS_LOG_INFO, "sum %6d: weak=%08x, strong=%s", i, sums->block_sigs[i].weak_sum, strong_hex); } }
/** * Generate the checksums for a block and write it out. Called when * we already know we have enough data in memory at \p block. */ static rs_result rs_sig_do_block(rs_job_t *job, const void *block, size_t len) { unsigned int weak_sum; rs_strong_sum_t strong_sum; weak_sum = rs_calc_weak_sum(block, len); rs_calc_strong_sum(block, len, &strong_sum); rs_squirt_n4(job, weak_sum); rs_tube_write(job, strong_sum, job->strong_sum_len); if (rs_trace_enabled()) { char strong_sum_hex[RS_MD4_LENGTH * 2 + 1]; rs_hexify(strong_sum_hex, strong_sum, job->strong_sum_len); rs_trace("sent weak sum 0x%08x and strong sum %s", weak_sum, strong_sum_hex); } job->stats.sig_blocks++; return RS_RUNNING; }