Are there other C standard library functions like memcmp that have timing side-channel risk?

309 Views Asked by At

I found that memcmp() will return false earlier if the first byte is different in both strings, and I thought it has a timing attack risk. However, when I tried to find out if there were other functions that had side-channel risks like memcmp, I couldn't find any information.

1

There are 1 best solutions below

6
On

Yes. strcmp and friends all work the same way. If in the rare case you are timing attack sensitive you have to write all your own comparison loops. The compiler can quite often optimize them back into timing sensitive loops now too, so you end up compiling such files with -O0. I know, so sad.

Typically you don't have this problem because you compare hashes.