1218767Sdes/* $OpenBSD: timingsafe_bcmp.c,v 1.1 2010/09/24 13:33:00 matthew Exp $ */ 2218767Sdes/* 3218767Sdes * Copyright (c) 2010 Damien Miller. All rights reserved. 4218767Sdes * 5218767Sdes * Permission to use, copy, modify, and distribute this software for any 6218767Sdes * purpose with or without fee is hereby granted, provided that the above 7218767Sdes * copyright notice and this permission notice appear in all copies. 8218767Sdes * 9218767Sdes * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10218767Sdes * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11218767Sdes * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12218767Sdes * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13218767Sdes * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14218767Sdes * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15218767Sdes * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16218767Sdes */ 17218767Sdes 18218767Sdes/* OPENBSD ORIGINAL: lib/libc/string/timingsafe_bcmp.c */ 19218767Sdes 20218767Sdes#include "includes.h" 21218767Sdes#ifndef HAVE_TIMINGSAFE_BCMP 22218767Sdes 23218767Sdesint 24218767Sdestimingsafe_bcmp(const void *b1, const void *b2, size_t n) 25218767Sdes{ 26218767Sdes const unsigned char *p1 = b1, *p2 = b2; 27218767Sdes int ret = 0; 28218767Sdes 29218767Sdes for (; n > 0; n--) 30218767Sdes ret |= *p1++ ^ *p2++; 31218767Sdes return (ret != 0); 32218767Sdes} 33218767Sdes 34218767Sdes#endif /* TIMINGSAFE_BCMP */ 35