void Encrypt(uint8_t *block, uint8_t *roundKeys) { uint32_t* blk = (uint32_t*) block; uint32_t* rk = (uint32_t*) roundKeys; int8_t i; uint32_t b0 = blk[0]; uint32_t b1 = blk[1]; uint32_t b2 = blk[2]; uint32_t b3 = blk[3]; for (i = 0; i < NUMBER_OF_ROUNDS; i += 4, rk += 4) { b3 = rot32r3((b2 ^ RK(rk, 3)) + (b3 ^ RK(rk, 1))); b2 = rot32r5((b1 ^ RK(rk, 2)) + (b2 ^ RK(rk, 1))); b1 = rot32l9((b0 ^ RK(rk, 0)) + (b1 ^ RK(rk, 1))); rk += 4; b0 = rot32r3((b3 ^ RK(rk, 3)) + (b0 ^ RK(rk, 1))); b3 = rot32r5((b2 ^ RK(rk, 2)) + (b3 ^ RK(rk, 1))); b2 = rot32l9((b1 ^ RK(rk, 0)) + (b2 ^ RK(rk, 1))); rk += 4; b1 = rot32r3((b0 ^ RK(rk, 3)) + (b1 ^ RK(rk, 1))); b0 = rot32r5((b3 ^ RK(rk, 2)) + (b0 ^ RK(rk, 1))); b3 = rot32l9((b2 ^ RK(rk, 0)) + (b3 ^ RK(rk, 1))); rk += 4; b2 = rot32r3((b1 ^ RK(rk, 3)) + (b2 ^ RK(rk, 1))); b1 = rot32r5((b0 ^ RK(rk, 2)) + (b1 ^ RK(rk, 1))); b0 = rot32l9((b3 ^ RK(rk, 0)) + (b0 ^ RK(rk, 1))); } blk[0] = b0; blk[1] = b1; blk[2] = b2; blk[3] = b3; }
void Decrypt(uint8_t *block, uint8_t *roundKeys) { uint32_t *block32 = (uint32_t *)block; const uint32_t *rk = (uint32_t *)roundKeys; uint32_t y = block32[0]; uint32_t x = block32[1]; int8_t i; for (i = NUMBER_OF_ROUNDS - 1; i >= 0; --i) { y = rot32r3(x ^ y); x = rot32l8((x ^ READ_ROUND_KEY_DOUBLE_WORD(rk[i])) - y); } block32[0] = y; block32[1] = x; }