1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// 9 is a common value for cksum_size, but the exact value shouldn't
// matter.
const usize_t CKSUM_SIZE = 9;
// These values are filled-in by FindCksumCollision
uint8_t golden_cksum_bytes[CKSUM_SIZE] = {
0x8d, 0x83, 0xe7, 0x6f, 0x46, 0x7f, 0xed, 0x51, 0xe6
};
uint8_t collision_cksum_bytes[CKSUM_SIZE] = {
0xaf, 0x55, 0x16, 0x89, 0x7c, 0x70, 0x00, 0xe5, 0xa7
};
void FindCksumCollision() {
// TODO! This is not being used.
if (golden_cksum_bytes[0] != 0) {
CHECK(memcmp(golden_cksum_bytes, collision_cksum_bytes, CKSUM_SIZE) != 0);
CHECK_EQ(xd3_lcksum(golden_cksum_bytes, CKSUM_SIZE),
xd3_lcksum(collision_cksum_bytes, CKSUM_SIZE));
return;
}
MTRandom rand;
MTRandom8 rand8(&rand);
for (size_t i = 0; i < CKSUM_SIZE; i++) {
collision_cksum_bytes[i] = golden_cksum_bytes[i] = rand8.Rand8();
}
uint32_t golden = xd3_lcksum(golden_cksum_bytes, CKSUM_SIZE);
size_t i = 0;
while (true) {
collision_cksum_bytes[i++] = rand8.Rand8();
if (golden == xd3_lcksum(collision_cksum_bytes, CKSUM_SIZE) &&
memcmp(collision_cksum_bytes, golden_cksum_bytes, CKSUM_SIZE) != 0) {
break;
}
if (i == CKSUM_SIZE) {
i = 0;
}
}
Block b1, b2;
b1.Append(golden_cksum_bytes, CKSUM_SIZE);
b2.Append(collision_cksum_bytes, CKSUM_SIZE);
DP(RINT "Found a cksum collision\n");
b1.Print();
b2.Print();
}
|