Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion src/my_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@

#define NOINLINE __attribute__((noinline))

char caesarLookup[][26] = {
"abcdefghijklmnopqrstuvwxyz",
"bcdefghijklmnopqrstuvwxyza",
"cdefghijklmnopqrstuvwxyzab",
"defghijklmnopqrstuvwxyzabc",
"efghijklmnopqrstuvwxyzabcd",
"fghijklmnopqrstuvwxyzabcde",
"ghijklmnopqrstuvwxyzabcdef",
"hijklmnopqrstuvwxyzabcdefg",
"ijklmnopqrstuvwxyzabcdefgh",
"jklmnopqrstuvwxyzabcdefghi",
"klmnopqrstuvwxyzabcdefghij",
"lmnopqrstuvwxyzabcdefghijk",
"mnopqrstuvwxyzabcdefghijkl",
"nopqrstuvwxyzabcdefghijklm",
"opqrstuvwxyzabcdefghijklmn",
"pqrstuvwxyzabcdefghijklmno",
"qrstuvwxyzabcdefghijklmnop",
"rstuvwxyzabcdefghijklmnopq",
"stuvwxyzabcdefghijklmnopqr",
"tuvwxyzabcdefghijklmnopqrs",
"uvwxyzabcdefghijklmnopqrst",
"vwxyzabcdefghijklmnopqrstu",
"wxyzabcdefghijklmnopqrstuv",
"xyzabcdefghijklmnopqrstuvw",
"yzabcdefghijklmnopqrstuvwx",
"zabcdefghijklmnopqrstuvwxy"
};

uint8_t lookup[256];

void init(void)
Expand All @@ -15,9 +44,29 @@ void init(void)
lookup[i] = (uint8_t)rand();
}

void caesarEncrypt(char input[], int length, char output[], int shift)
{
for(int i = 0; i < length; ++i)
{
if(input[i] < 'a' || input[i] > 'z')
{
output[i] = input[i];
continue;
}

output[i] = caesarLookup[shift][input[i] - 'a'];

Check failure

Code scanning / Microwalk

Secret-dependent memory access

Found vulnerable memory access instruction, leakage score 100.00% +/- 0%.
}
}

void lookup_leakage(uint8_t *input, int inputLength, uint8_t *output)
{
// Empty and constant time
// Convert input to alpha string
char *alpha = (char *)malloc(inputLength + 1);
for(int i = 0; i < inputLength; ++i)
alpha[i] = 'a' + (input[i] % 26);
alpha[inputLength] = '\0';

caesarEncrypt(alpha, inputLength, (char *)output, input[0] % 26);
}

int branch_leakage(uint8_t *input, int inputLength)
Expand Down