int memread(struct data_buffer buf) { long sum = 0; char page[4096]; char *addr = buf.addr; char *end = buf.addr + buf.size; for (; addr < end; addr += sizeof(page)) { memcpy(page, addr, sizeof(page)); sum += sum_buf(page, sizeof(page)); } // The optimization of a compiler may remove the code entirely // if we don't return the sum. return sum; }
/** * Produce the final GOST 34.11 output */ void GOST_34_11::final_result(byte out[]) { if(position) { clear_mem(buffer.begin() + position, buffer.size() - position); compress_n(buffer, 1); } SecureBuffer<byte, 32> length_buf; const u64bit bit_count = count * 8; store_le(bit_count, length_buf); SecureBuffer<byte, 32> sum_buf(sum); compress_n(length_buf, 1); compress_n(sum_buf, 1); copy_mem(out, hash.begin(), 32); clear(); }