Files
OpenCellular/chip/g/dcrypto/compare.c
nagendra modadugu d7222a4956 CR50: add a constant time buffer equals implementation
Various cryptographic operations leak timing
information if comparisons are not executed
in constant time.  This change adds DCRYPTO_equals(),
a constant runtime comparator.

Also replace crypto related callsites that used
memcmp() as a binary comparator.

BUG=none
BRANCH=none
TEST=tcg tests pass

Change-Id: I3d3da3c0524c3a349d60675902d1f2d338ad455f
Signed-off-by: nagendra modadugu <ngm@google.com>
Reviewed-on: https://chromium-review.googlesource.com/410163
Commit-Ready: Nagendra Modadugu <ngm@google.com>
Tested-by: Nagendra Modadugu <ngm@google.com>
Reviewed-by: Marius Schilder <mschilder@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-11-11 14:27:23 -08:00

21 lines
439 B
C

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