Skip to content

Commit 249a82e

Browse files
committed
Add new cipher
1 parent 8142683 commit 249a82e

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

src/my_lib.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,35 @@
55

66
#define NOINLINE __attribute__((noinline))
77

8+
char caesarLookup[][26] = {
9+
"abcdefghijklmnopqrstuvwxyz",
10+
"bcdefghijklmnopqrstuvwxyza",
11+
"cdefghijklmnopqrstuvwxyzab",
12+
"defghijklmnopqrstuvwxyzabc",
13+
"efghijklmnopqrstuvwxyzabcd",
14+
"fghijklmnopqrstuvwxyzabcde",
15+
"ghijklmnopqrstuvwxyzabcdef",
16+
"hijklmnopqrstuvwxyzabcdefg",
17+
"ijklmnopqrstuvwxyzabcdefgh",
18+
"jklmnopqrstuvwxyzabcdefghi",
19+
"klmnopqrstuvwxyzabcdefghij",
20+
"lmnopqrstuvwxyzabcdefghijk",
21+
"mnopqrstuvwxyzabcdefghijkl",
22+
"nopqrstuvwxyzabcdefghijklm",
23+
"opqrstuvwxyzabcdefghijklmn",
24+
"pqrstuvwxyzabcdefghijklmno",
25+
"qrstuvwxyzabcdefghijklmnop",
26+
"rstuvwxyzabcdefghijklmnopq",
27+
"stuvwxyzabcdefghijklmnopqr",
28+
"tuvwxyzabcdefghijklmnopqrs",
29+
"uvwxyzabcdefghijklmnopqrst",
30+
"vwxyzabcdefghijklmnopqrstu",
31+
"wxyzabcdefghijklmnopqrstuv",
32+
"xyzabcdefghijklmnopqrstuvw",
33+
"yzabcdefghijklmnopqrstuvwx",
34+
"zabcdefghijklmnopqrstuvwxy"
35+
};
36+
837
uint8_t lookup[256];
938

1039
void init(void)
@@ -15,9 +44,29 @@ void init(void)
1544
lookup[i] = (uint8_t)rand();
1645
}
1746

47+
void caesarEncrypt(char input[], int length, char output[], int shift)
48+
{
49+
for(int i = 0; i < length; ++i)
50+
{
51+
if(input[i] < 'a' || input[i] > 'z')
52+
{
53+
output[i] = input[i];
54+
continue;
55+
}
56+
57+
output[i] = caesarLookup[shift][input[i] - 'a'];
58+
}
59+
}
60+
1861
void lookup_leakage(uint8_t *input, int inputLength, uint8_t *output)
1962
{
20-
// Empty and constant time
63+
// Convert input to alpha string
64+
char *alpha = (char *)malloc(inputLength + 1);
65+
for(int i = 0; i < inputLength; ++i)
66+
alpha[i] = 'a' + (input[i] % 26);
67+
alpha[inputLength] = '\0';
68+
69+
caesarEncrypt(alpha, inputLength, (char *)output, input[0] % 26);
2170
}
2271

2372
int branch_leakage(uint8_t *input, int inputLength)

0 commit comments

Comments
 (0)