David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 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 | |
| 5 | #ifndef CRYPTO_SHA2_H_ |
| 6 | #define CRYPTO_SHA2_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
Andrew Top | 0d1858f | 2019-05-15 22:01:47 -0700 | [diff] [blame] | 10 | #include "base/strings/string_piece.h" |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 11 | #include "crypto/crypto_export.h" |
Andrew Top | 0d1858f | 2019-05-15 22:01:47 -0700 | [diff] [blame] | 12 | #include "starboard/types.h" |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 13 | |
| 14 | namespace crypto { |
| 15 | |
| 16 | // These functions perform SHA-256 operations. |
| 17 | // |
| 18 | // Functions for SHA-384 and SHA-512 can be added when the need arises. |
| 19 | |
| 20 | static const size_t kSHA256Length = 32; // Length in bytes of a SHA-256 hash. |
| 21 | |
| 22 | // Computes the SHA-256 hash of the input string 'str' and stores the first |
| 23 | // 'len' bytes of the hash in the output buffer 'output'. If 'len' > 32, |
| 24 | // only 32 bytes (the full hash) are stored in the 'output' buffer. |
Andrew Top | 0d1858f | 2019-05-15 22:01:47 -0700 | [diff] [blame] | 25 | CRYPTO_EXPORT void SHA256HashString(base::StringPiece str, |
| 26 | void* output, |
| 27 | size_t len); |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 28 | |
| 29 | // Convenience version of the above that returns the result in a 32-byte |
| 30 | // string. |
Andrew Top | 0d1858f | 2019-05-15 22:01:47 -0700 | [diff] [blame] | 31 | CRYPTO_EXPORT std::string SHA256HashString(base::StringPiece str); |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 32 | |
| 33 | } // namespace crypto |
| 34 | |
| 35 | #endif // CRYPTO_SHA2_H_ |