Search code examples
ccompile-time-constant

constant-time implementation of variable rotation RC6 cipher


RC6 wiki uses variable left rotation value that depends on logarithmic value. Iam interested in finding a way to implement constant time c code of RC6. Is there open-source or an idea of how to implement the variable left rotation in constant-time code.


Solution

  • This point is addressed in section 4.1 of https://pdfs.semanticscholar.org/bf3e/23be81385817319524ee6bb1d62e9054d153.pdf . The short summary is:

    • Most processors take constant time for rotations including data dependent rotations (that was the case when rc6 was proposed anyway)

    • Even if the run time to shift k bits is proportional to k cycles, then to do a circular left rotation you need to shift left k-bits followed by shift right 32-k bits, so that results in a constant time of 32 cycles.

    I don't know fine details of modern architectures, but I suppose I would turn the question around and ask for an example where that logic is not true.