xref: /aosp_15_r20/external/libchrome/crypto/secure_util.h (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2012 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 #ifndef CRYPTO_SECURE_UTIL_H_
6*635a8641SAndroid Build Coastguard Worker #define CRYPTO_SECURE_UTIL_H_
7*635a8641SAndroid Build Coastguard Worker 
8*635a8641SAndroid Build Coastguard Worker #include <stddef.h>
9*635a8641SAndroid Build Coastguard Worker 
10*635a8641SAndroid Build Coastguard Worker #include "crypto/crypto_export.h"
11*635a8641SAndroid Build Coastguard Worker 
12*635a8641SAndroid Build Coastguard Worker namespace crypto {
13*635a8641SAndroid Build Coastguard Worker 
14*635a8641SAndroid Build Coastguard Worker // Performs a constant-time comparison of two strings, returning true if the
15*635a8641SAndroid Build Coastguard Worker // strings are equal.
16*635a8641SAndroid Build Coastguard Worker //
17*635a8641SAndroid Build Coastguard Worker // For cryptographic operations, comparison functions such as memcmp() may
18*635a8641SAndroid Build Coastguard Worker // expose side-channel information about input, allowing an attacker to
19*635a8641SAndroid Build Coastguard Worker // perform timing analysis to determine what the expected bits should be. In
20*635a8641SAndroid Build Coastguard Worker // order to avoid such attacks, the comparison must execute in constant time,
21*635a8641SAndroid Build Coastguard Worker // so as to not to reveal to the attacker where the difference(s) are.
22*635a8641SAndroid Build Coastguard Worker // For an example attack, see
23*635a8641SAndroid Build Coastguard Worker // http://groups.google.com/group/keyczar-discuss/browse_thread/thread/5571eca0948b2a13
24*635a8641SAndroid Build Coastguard Worker CRYPTO_EXPORT bool SecureMemEqual(const void* s1, const void* s2, size_t n);
25*635a8641SAndroid Build Coastguard Worker 
26*635a8641SAndroid Build Coastguard Worker }  // namespace crypto
27*635a8641SAndroid Build Coastguard Worker 
28*635a8641SAndroid Build Coastguard Worker #endif  // CRYPTO_SECURE_UTIL_H_
29*635a8641SAndroid Build Coastguard Worker 
30