summaryrefslogtreecommitdiff
path: root/board/cr50/dcrypto/compare.c
blob: db6193752b0559b3d152a4e9b6554d092e042cb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* Copyright 2016 The Chromium OS Authors. All rights reserved.
 * 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;
}