X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=bmw%2Fbmw_large.c;h=4b2b768f25e3425d5bcb3161602b6b2303495b33;hb=cf610f6848d1a6aef4de849f9ec7895e20605583;hp=5b0039ab31663e81a3864a660a1ea311f2da1e26;hpb=2873506dc8ebc5657d24af0ad5eab1fc06ce09e9;p=avr-crypto-lib.git diff --git a/bmw/bmw_large.c b/bmw/bmw_large.c index 5b0039a..4b2b768 100644 --- a/bmw/bmw_large.c +++ b/bmw/bmw_large.c @@ -30,10 +30,10 @@ #include #include "bmw_large.h" -#define SHL64(a,n) ((a)<<(n)) -#define SHR64(a,n) ((a)>>(n)) -#define ROTL64(a,n) (((a)<<(n))|((a)>>(64-(n)))) -#define ROTR64(a,n) (((a)>>(n))|((a)<<(64-(n)))) +#define SHL64(a,n) shiftl64(a,n) +#define SHR64(a,n) shiftr64(a,n) +#define ROTL64(a,n) rotl64(a,n) +#define ROTR64(a,n) rotr64(a,n) #define TWEAK 1 #define BUG24 0 @@ -75,6 +75,26 @@ #define dump_x(a,b,c) #endif +static +uint64_t rotl64(uint64_t a, uint8_t r){ + return (a<>(64-r)); +} + +static +uint64_t rotr64(uint64_t a, uint8_t r){ + return (a>>r)|(a<<(64-r)); +} + +static +uint64_t shiftl64(uint64_t a, uint8_t r){ + return (a<>r); +} + static uint64_t bmw_large_s0(uint64_t x){ uint64_t r; @@ -183,7 +203,7 @@ uint64_t bmw_large_r7(uint64_t x){ #define K 0x0555555555555555LL #define MASK 0xFFFFFFFFFFFFFFFFLL static -uint64_t k_lut[] PROGMEM = { +const uint64_t k_lut[] PROGMEM = { 16LL*K, 17LL*K, 18LL*K, 19LL*K, 20LL*K, 21LL*K, 22LL*K, 23LL*K, 24LL*K, 25LL*K, 26LL*K, 27LL*K, @@ -191,7 +211,7 @@ uint64_t k_lut[] PROGMEM = { */ /* the same as above but precomputed to avoid compiler warnings */ static -uint64_t k_lut[] PROGMEM = { +const uint64_t k_lut[] PROGMEM = { 0x5555555555555550LL, 0x5aaaaaaaaaaaaaa5LL, 0x5ffffffffffffffaLL, 0x655555555555554fLL, 0x6aaaaaaaaaaaaaa4LL, 0x6ffffffffffffff9LL, 0x755555555555554eLL, 0x7aaaaaaaaaaaaaa3LL, 0x7ffffffffffffff8LL, @@ -288,8 +308,8 @@ uint64_t bmw_large_expand2(uint8_t j, const uint64_t* q, const void* m, const vo #if F0_HACK==2 /* to understand this implementation take a look at f0-opt-table.txt */ -static uint16_t hack_table[5] PROGMEM = { 0x0311, 0xDDB3, 0x2A79, 0x07AA, 0x51C2 }; -static uint8_t offset_table[5] PROGMEM = { 4+16, 6+16, 9+16, 12+16, 13+16 }; +static const uint16_t hack_table[5] PROGMEM = { 0x0311, 0xDDB3, 0x2A79, 0x07AA, 0x51C2 }; +static const uint8_t offset_table[5] PROGMEM = { 4+16, 6+16, 9+16, 12+16, 13+16 }; static @@ -335,7 +355,7 @@ void bmw_large_f0(uint64_t* q, const uint64_t* h, const void* m){ #if F0_HACK==1 static -uint8_t f0_lut[] PROGMEM ={ +const uint8_t f0_lut[] PROGMEM ={ 5<<1, ( 7<<1)+1, (10<<1)+0, (13<<1)+0, (14<<1)+0, 6<<1, ( 8<<1)+1, (11<<1)+0, (14<<1)+0, (15<<1)+1, 0<<1, ( 7<<1)+0, ( 9<<1)+0, (12<<1)+1, (15<<1)+0,