1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file. 4*635a8641SAndroid Build Coastguard Worker 5*635a8641SAndroid Build Coastguard Worker #include <stddef.h> 6*635a8641SAndroid Build Coastguard Worker 7*635a8641SAndroid Build Coastguard Worker #include "crypto/secure_util.h" 8*635a8641SAndroid Build Coastguard Worker 9*635a8641SAndroid Build Coastguard Worker namespace crypto { 10*635a8641SAndroid Build Coastguard Worker SecureMemEqual(const void * s1,const void * s2,size_t n)11*635a8641SAndroid Build Coastguard Workerbool SecureMemEqual(const void* s1, const void* s2, size_t n) { 12*635a8641SAndroid Build Coastguard Worker const unsigned char* s1_ptr = reinterpret_cast<const unsigned char*>(s1); 13*635a8641SAndroid Build Coastguard Worker const unsigned char* s2_ptr = reinterpret_cast<const unsigned char*>(s2); 14*635a8641SAndroid Build Coastguard Worker unsigned char tmp = 0; 15*635a8641SAndroid Build Coastguard Worker for (size_t i = 0; i < n; ++i, ++s1_ptr, ++s2_ptr) 16*635a8641SAndroid Build Coastguard Worker tmp |= *s1_ptr ^ *s2_ptr; 17*635a8641SAndroid Build Coastguard Worker return (tmp == 0); 18*635a8641SAndroid Build Coastguard Worker } 19*635a8641SAndroid Build Coastguard Worker 20*635a8641SAndroid Build Coastguard Worker } // namespace crypto 21*635a8641SAndroid Build Coastguard Worker 22