X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=secnet.git;a=blobdiff_plain;f=util.c;h=3d119874eb1c11c7d7b9e367a6bf1a2bef6c4b4b;hp=de91e1e205ad964dca0768b68b969b2a15bf8633;hb=5ad34db2ccbbfbc936cd16121bed2110b70594ba;hpb=28db900b071a43718c4227e759fa76cb8c6359af diff --git a/util.c b/util.c index de91e1e..3d11987 100644 --- a/util.c +++ b/util.c @@ -381,6 +381,22 @@ static list_t *buffer_apply(closure_t *self, struct cloc loc, dict_t *context, return new_closure(&st->cl); } +int consttime_memeq(const void *s1in, const void *s2in, size_t n) +{ + const uint8_t *s1=s1in, *s2=s2in; + register volatile uint8_t accumulator=0; + + while (n-- > 0) { + accumulator |= (*s1++ ^ *s2++); + } + accumulator |= accumulator >> 4; /* constant-time */ + accumulator |= accumulator >> 2; /* boolean canonicalisation */ + accumulator |= accumulator >> 1; + accumulator &= 1; + accumulator ^= 1; + return accumulator; +} + void util_module(dict_t *dict) { add_closure(dict,"sysbuffer",buffer_apply);