1 /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 2 * Use of this source code is governed by a BSD-style license that can be 3 * found in the LICENSE file. 4 * 5 * Utility functions that need to be built as part of the firmware. 6 */ 7 8 #include "sysincludes.h" 9 10 #include "utility.h" 11 12 int SafeMemcmp(const void *s1, const void *s2, size_t n) { 13 const unsigned char *us1 = s1; 14 const unsigned char *us2 = s2; 15 int result = 0; 16 17 if (0 == n) 18 return 0; 19 20 /* 21 * Code snippet without data-dependent branch due to Nate Lawson 22 * (nate (at) root.org) of Root Labs. 23 */ 24 while (n--) 25 result |= *us1++ ^ *us2++; 26 27 return result != 0; 28 } 29