5
5
6
6
#define NOINLINE __attribute__((noinline))
7
7
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
+
8
37
uint8_t lookup [256 ];
9
38
10
39
void init (void )
@@ -15,9 +44,29 @@ void init(void)
15
44
lookup [i ] = (uint8_t )rand ();
16
45
}
17
46
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
+
18
61
void lookup_leakage (uint8_t * input , int inputLength , uint8_t * output )
19
62
{
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 );
21
70
}
22
71
23
72
int branch_leakage (uint8_t * input , int inputLength )
0 commit comments