Your best bet is to generate a huge body of inputs (including the relevant special cases), and tweak the code until it takes the same amount of time for all of them.
"For every problem there is always a solution
that is simple, obvious, and wrong." -- Mark Twain
I'm not an expert, but I know several people who are. Apparently the literature explains clearly why this most obvious of fixes is, as Twain predicts, wrong. The simple jitter that you can add is dealt with by statistical techniques.As I say, I'm not an expert, but if you google this it should give you references to papers that discuss the issues.
>Program the system to take the same amount of time to return both correct and incorrect passwords. This can be done in about six lines of code, Lawson said.
This makes things slower for the rest of us. 1 extra millisecond per user * 8 billion users * times 10 logins a day == Lots Of Lost Man Hours, probably enough to rebuild the great pyramids of Egypt by hand every year.
Security researchers are the reason we can't have nice things. :)
http://rdist.root.org/2010/01/07/timing-independent-array-co...