[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 | |||||
Adam Langley | fc2c6b59 | 2019-08-30 19:21:06 | [diff] [blame] | 10 | #include <array> |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 11 | #include <string> |
12 | |||||
Adam Langley | fc2c6b59 | 2019-08-30 19:21:06 | [diff] [blame] | 13 | #include "base/containers/span.h" |
[email protected] | daf079a | 2013-04-17 21:42:40 | [diff] [blame] | 14 | #include "base/strings/string_piece.h" |
[email protected] | d613a990 | 2011-08-05 20:59:11 | [diff] [blame] | 15 | #include "crypto/crypto_export.h" |
[email protected] | 82091cc | 2011-06-17 21:11:13 | [diff] [blame] | 16 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 17 | namespace crypto { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 18 | |
19 | // These functions perform SHA-256 operations. | ||||
20 | // | ||||
21 | // Functions for SHA-384 and SHA-512 can be added when the need arises. | ||||
22 | |||||
[email protected] | b13b9bd | 2011-09-28 21:15:27 | [diff] [blame] | 23 | 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] | 24 | |
Adam Langley | fc2c6b59 | 2019-08-30 19:21:06 | [diff] [blame] | 25 | // Computes the SHA-256 hash of |input|. |
26 | CRYPTO_EXPORT std::array<uint8_t, kSHA256Length> SHA256Hash( | ||||
27 | base::span<const uint8_t> input); | ||||
28 | |||||
29 | // Convenience version of the above that returns the result in a 32-byte | ||||
30 | // string. | ||||
31 | CRYPTO_EXPORT std::string SHA256HashString(base::StringPiece str); | ||||
32 | |||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 33 | // Computes the SHA-256 hash of the input string 'str' and stores the first |
34 | // 'len' bytes of the hash in the output buffer 'output'. If 'len' > 32, | ||||
35 | // only 32 bytes (the full hash) are stored in the 'output' buffer. | ||||
David Benjamin | cda45eb | 2017-11-06 18:16:52 | [diff] [blame] | 36 | CRYPTO_EXPORT void SHA256HashString(base::StringPiece str, |
37 | void* output, | ||||
38 | size_t len); | ||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 39 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 40 | } // namespace crypto |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 41 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 42 | #endif // CRYPTO_SHA2_H_ |