From 8484250604832594aa53c074658ecd7f4ace90f6 Mon Sep 17 00:00:00 2001 From: Jan Wichelmann Date: Sat, 21 May 2022 17:58:02 +0200 Subject: [PATCH] Add leakage --- src/my_lib.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/my_lib.c b/src/my_lib.c index 8764882..c3517fd 100644 --- a/src/my_lib.c +++ b/src/my_lib.c @@ -17,17 +17,40 @@ void init(void) void lookup_leakage(uint8_t *input, int inputLength, uint8_t *output) { - // Empty and constant time + for(int i = 0; i < inputLength; ++i) + output[i] = lookup[input[i]]; +} + +static int NOINLINE branch_leakage_util(uint8_t data) +{ + // Use primes and random calculation to keep the compiler from optimizing this function too much + + if(data < 79) + return 7; + + if(data < 119) + return data; + + return 19 * data + 23; } int branch_leakage(uint8_t *input, int inputLength) { - // Empty and constant time - return lookup[0] + inputLength; + int result = 0; + + for(int i = 0; i < inputLength; ++i) + result += branch_leakage_util(input[i]); + + return result; } int loop_leakage(uint8_t *input, int inputLength) { - // Empty and constant time - return lookup[0] + inputLength; + for(int i = 0; i < input[0]; ++i) + { + if(lookup[i] < 5) + return 1; + } + + return 2; } \ No newline at end of file