1*0afa8e06SEd Maste /* $OpenBSD: timingsafe_bcmp.c,v 1.1 2010/09/24 13:33:00 matthew Exp $ */
2*0afa8e06SEd Maste /*
3*0afa8e06SEd Maste * Copyright (c) 2010 Damien Miller. All rights reserved.
4*0afa8e06SEd Maste *
5*0afa8e06SEd Maste * Permission to use, copy, modify, and distribute this software for any
6*0afa8e06SEd Maste * purpose with or without fee is hereby granted, provided that the above
7*0afa8e06SEd Maste * copyright notice and this permission notice appear in all copies.
8*0afa8e06SEd Maste *
9*0afa8e06SEd Maste * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*0afa8e06SEd Maste * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*0afa8e06SEd Maste * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*0afa8e06SEd Maste * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*0afa8e06SEd Maste * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*0afa8e06SEd Maste * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*0afa8e06SEd Maste * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*0afa8e06SEd Maste */
17*0afa8e06SEd Maste
18*0afa8e06SEd Maste /* OPENBSD ORIGINAL: lib/libc/string/timingsafe_bcmp.c */
19*0afa8e06SEd Maste
20*0afa8e06SEd Maste #include "openbsd-compat.h"
21*0afa8e06SEd Maste
22*0afa8e06SEd Maste #if !defined(HAVE_TIMINGSAFE_BCMP)
23*0afa8e06SEd Maste
24*0afa8e06SEd Maste int
timingsafe_bcmp(const void * b1,const void * b2,size_t n)25*0afa8e06SEd Maste timingsafe_bcmp(const void *b1, const void *b2, size_t n)
26*0afa8e06SEd Maste {
27*0afa8e06SEd Maste const unsigned char *p1 = b1, *p2 = b2;
28*0afa8e06SEd Maste int ret = 0;
29*0afa8e06SEd Maste
30*0afa8e06SEd Maste for (; n > 0; n--)
31*0afa8e06SEd Maste ret |= *p1++ ^ *p2++;
32*0afa8e06SEd Maste return (ret != 0);
33*0afa8e06SEd Maste }
34*0afa8e06SEd Maste
35*0afa8e06SEd Maste #endif /* !defined(HAVE_TIMINGSAFE_BCMP) */
36