Skip to content

Commit

Permalink
Add new cipher
Browse files Browse the repository at this point in the history
  • Loading branch information
JanWichelmann committed Jul 30, 2024
1 parent 8142683 commit 9f009c6
Showing 1 changed file with 50 additions and 1 deletion.
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 Error

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

0 comments on commit 9f009c6

Please sign in to comment.