X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Futils.c;h=555ea50d7461b38c9a000bfe559e10ed275e0ccf;hp=3b221f59f0ef731f62b0369314de5964bdf855fd;hb=57bbc06733b973fb0ed8ba226f9159de870768b2;hpb=68f4ca711593416d0defd81199b176ba604c6cb1 diff --git a/src/utils.c b/src/utils.c index 3b221f59..555ea50d 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,7 +1,7 @@ /* utils.c -- gathering of some stupid small functions Copyright (C) 1999-2005 Ivo Timmermans - 2000-2009 Guus Sliepen + 2000-2014 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -78,3 +78,18 @@ unsigned int bitfield_to_int(const void *bitfield, size_t size) { memcpy(&value, bitfield, size); return value; } + +/** + * As memcmp(), but constant-time. + * Returns 0 when data is equal, non-zero otherwise. + */ +int memcmp_constant_time (const void *a, const void *b, size_t size) { + const uint8_t *a1 = a, *b1 = b; + int ret = 0; + size_t i; + + for (i = 0; i < size; i++) + ret |= *a1++ ^ *b1++; + + return ret; +}