summaryrefslogtreecommitdiff
path: root/chip/g/dcrypto/compare.c
blob: b2647d128ec154c73d58acb4a30cc41de0d6b8c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* Copyright 2016 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "dcrypto.h"

/* Constant time comparator. */
int DCRYPTO_equals(const void *a, const void *b, size_t len)
{
	size_t i;
	const uint8_t *pa = a;
	const uint8_t *pb = b;
	uint8_t diff = 0;

	for (i = 0; i < len; i++)
		diff |= pa[i] ^ pb[i];

	return !diff;
}