blob: cfe05ca15540b689a42c8b2c84ba41277298075f [file] [log] [blame]
[email protected]cf211882012-07-11 07:19:141// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]3cdf6d42011-10-07 17:02:482// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CRYPTO_SECURE_UTIL_H_
6#define CRYPTO_SECURE_UTIL_H_
[email protected]3cdf6d42011-10-07 17:02:487
8#include <stddef.h>
9
10#include "crypto/crypto_export.h"
11
12namespace crypto {
13
14// Performs a constant-time comparison of two strings, returning true if the
15// strings are equal.
16//
17// For cryptographic operations, comparison functions such as memcmp() may
18// expose side-channel information about input, allowing an attacker to
19// perform timing analysis to determine what the expected bits should be. In
20// order to avoid such attacks, the comparison must execute in constant time,
21// so as to not to reveal to the attacker where the difference(s) are.
22// For an example attack, see
23// http://groups.google.com/group/keyczar-discuss/browse_thread/thread/5571eca0948b2a13
24CRYPTO_EXPORT bool SecureMemEqual(const void* s1, const void* s2, size_t n);
25
26} // namespace crypto
27
28#endif // CRYPTO_SECURE_UTIL_H_
29