From 3cdf6d45936b29b4a412b94a599a93f6e181f210 Mon Sep 17 00:00:00 2001 From: "palmer@chromium.org" Date: Fri, 7 Oct 2011 17:02:48 +0000 Subject: Make constant-time comparison operators for cryptographic uses public. Review URL: http://codereview.chromium.org/8124011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104502 0039d316-1c4b-4281-b951-d872f2087c98 --- crypto/secure_util.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 crypto/secure_util.cc (limited to 'crypto/secure_util.cc') diff --git a/crypto/secure_util.cc b/crypto/secure_util.cc new file mode 100644 index 0000000..3fe8aa9 --- /dev/null +++ b/crypto/secure_util.cc @@ -0,0 +1,19 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "crypto/secure_util.h" + +namespace crypto { + +bool SecureMemEqual(const void* s1, const void* s2, size_t n) { + const unsigned char* s1_ptr = reinterpret_cast(s1); + const unsigned char* s2_ptr = reinterpret_cast(s2); + unsigned char tmp = 0; + for (size_t i = 0; i < n; ++i, ++s1_ptr, ++s2_ptr) + tmp |= *s1_ptr ^ *s2_ptr; + return (tmp == 0); +} + +} // namespace crypto + -- cgit v1.1