secure_util.h 1.0 KB

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