]> git.saurik.com Git - apple/xnu.git/blame - osfmk/corecrypto/cc/src/cc_cmp_safe.c
xnu-3789.1.32.tar.gz
[apple/xnu.git] / osfmk / corecrypto / cc / src / cc_cmp_safe.c
CommitLineData
39037602
A
1/*
2 * cc_cmp_safe.c
3 * corecrypto
4 *
5 * Created on 04/22/2014
6 *
7 * Copyright (c) 2014,2015 Apple Inc. All rights reserved.
8 *
9 */
10
11#include <corecrypto/cc_priv.h>
12
13int cc_cmp_safe (size_t num, const void * ptr1, const void * ptr2)
14{
15 size_t i;
16 const uint8_t *s=(const uint8_t *)ptr1;
17 const uint8_t *t=(const uint8_t *)ptr2;
18 uint8_t flag=((num<=0)?1:0); // If 0 return an error
19 for (i=0;i<num;i++)
20 {
21 flag|=(s[i]^t[i]);
22 }
23 HEAVISIDE_STEP_UINT8(flag,flag); // flag=(flag==0)?0:1;
24 return flag; // 0 iff all bytes were equal, 1 if there is any difference
25}