I'd like to know if there is an easy way (maybe a library) to write constant-time programs in Python. In particular, I'd like to be able to specify that an if-else flow must always last the same time whether the if condition is True
or False
.
For instance:
if condition:
foo1()
else:
foo2()
foo3()
Running this program in constant-time would mean that the time that it takes to hit f3()
should be the same independently of the result of the evaluation of condition
. This would prevent a side-channel that could reveal the execution of f1()
or f2()
(cf. timing attacks).