blob: fe86d65553a6213b0a03afe8a08ce0087b479327 [file] [log] [blame]
Alex Vakulenkof6024732016-01-22 16:52:43 -08001// Copyright (c) 2011 The Chromium 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
Alex Vakulenko24854742016-01-22 16:55:13 -08005#include <stddef.h>
6
Alex Vakulenkof6024732016-01-22 16:52:43 -08007#include "crypto/secure_util.h"
8
9namespace crypto {
10
11bool SecureMemEqual(const void* s1, const void* s2, size_t n) {
12 const unsigned char* s1_ptr = reinterpret_cast<const unsigned char*>(s1);
13 const unsigned char* s2_ptr = reinterpret_cast<const unsigned char*>(s2);
14 unsigned char tmp = 0;
15 for (size_t i = 0; i < n; ++i, ++s1_ptr, ++s2_ptr)
16 tmp |= *s1_ptr ^ *s2_ptr;
17 return (tmp == 0);
18}
19
20} // namespace crypto
21