- // calculate all mac for every the block we will write
- for (i = startblock; i <= endblock; i++){
- Calc_wb_mac(i, tag_data[i - startblock].d, div_key, MAC);
- // usb command d start pointer = d + (i - 6) * 12
- // memcpy(pointer,tag_data[i - 6],8) 8 bytes
- // memcpy(pointer + 8,mac,sizoof(mac) 4 bytes;
- // next one
- ptr = w.d.asBytes + (i - startblock) * 12;
- memcpy(ptr, &(tag_data[i - startblock].d[0]), 8);
- memcpy(ptr + 8,MAC, 4);
+ // calculate MAC for every block we will write
+ for (int i = 0; i < endblock - startblock + 1; i++) {
+ Calc_wb_mac(startblock + i, tag_data[i], div_key, MAC);
+ ptr = w.d.asBytes + i * 12;
+ memcpy(ptr, tag_data[i], 8);
+ memcpy(ptr + 8, MAC, 4);