+
+/**
+ * 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;
+}