[email protected] | da7582b7 | 2012-01-10 19:10:33 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 4 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 5 | #ifndef CRYPTO_SHA2_H_ |
6 | #define CRYPTO_SHA2_H_ | ||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 7 | |
avi | dd373b8b | 2015-12-21 21:34:43 | [diff] [blame^] | 8 | #include <stddef.h> |
9 | |||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 10 | #include <string> |
11 | |||||
[email protected] | daf079a | 2013-04-17 21:42:40 | [diff] [blame] | 12 | #include "base/strings/string_piece.h" |
[email protected] | d613a990 | 2011-08-05 20:59:11 | [diff] [blame] | 13 | #include "crypto/crypto_export.h" |
[email protected] | 82091cc | 2011-06-17 21:11:13 | [diff] [blame] | 14 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 15 | namespace crypto { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 16 | |
17 | // These functions perform SHA-256 operations. | ||||
18 | // | ||||
19 | // Functions for SHA-384 and SHA-512 can be added when the need arises. | ||||
20 | |||||
[email protected] | b13b9bd | 2011-09-28 21:15:27 | [diff] [blame] | 21 | static const size_t kSHA256Length = 32; // Length in bytes of a SHA-256 hash. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 22 | |
23 | // Computes the SHA-256 hash of the input string 'str' and stores the first | ||||
24 | // 'len' bytes of the hash in the output buffer 'output'. If 'len' > 32, | ||||
25 | // only 32 bytes (the full hash) are stored in the 'output' buffer. | ||||
[email protected] | da7582b7 | 2012-01-10 19:10:33 | [diff] [blame] | 26 | CRYPTO_EXPORT void SHA256HashString(const base::StringPiece& str, |
[email protected] | d613a990 | 2011-08-05 20:59:11 | [diff] [blame] | 27 | void* output, size_t len); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 28 | |
[email protected] | e1d6a59 | 2010-09-03 21:02:15 | [diff] [blame] | 29 | // Convenience version of the above that returns the result in a 32-byte |
30 | // string. | ||||
[email protected] | da7582b7 | 2012-01-10 19:10:33 | [diff] [blame] | 31 | CRYPTO_EXPORT std::string SHA256HashString(const base::StringPiece& str); |
[email protected] | e1d6a59 | 2010-09-03 21:02:15 | [diff] [blame] | 32 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 33 | } // namespace crypto |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 34 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 35 | #endif // CRYPTO_SHA2_H_ |