blob: 1852bdee0dcb60aad9766de8fe6261dd655d904a [file] [log] [blame]
[email protected]da7582b72012-01-10 19:10:331// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitd7cae122008-07-26 21:49:384
[email protected]4b559b4d2011-04-14 17:37:145#ifndef CRYPTO_SHA2_H_
6#define CRYPTO_SHA2_H_
initial.commitd7cae122008-07-26 21:49:387
avidd373b8b2015-12-21 21:34:438#include <stddef.h>
9
Adam Langleyfc2c6b592019-08-30 19:21:0610#include <array>
initial.commitd7cae122008-07-26 21:49:3811#include <string>
12
Adam Langleyfc2c6b592019-08-30 19:21:0613#include "base/containers/span.h"
[email protected]daf079a2013-04-17 21:42:4014#include "base/strings/string_piece.h"
[email protected]d613a9902011-08-05 20:59:1115#include "crypto/crypto_export.h"
[email protected]82091cc2011-06-17 21:11:1316
[email protected]4b559b4d2011-04-14 17:37:1417namespace crypto {
initial.commitd7cae122008-07-26 21:49:3818
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]b13b9bd2011-09-28 21:15:2723static const size_t kSHA256Length = 32; // Length in bytes of a SHA-256 hash.
initial.commitd7cae122008-07-26 21:49:3824
Adam Langleyfc2c6b592019-08-30 19:21:0625// Computes the SHA-256 hash of |input|.
26CRYPTO_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.
31CRYPTO_EXPORT std::string SHA256HashString(base::StringPiece str);
32
initial.commitd7cae122008-07-26 21:49:3833// 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 Benjamincda45eb2017-11-06 18:16:5236CRYPTO_EXPORT void SHA256HashString(base::StringPiece str,
37 void* output,
38 size_t len);
initial.commitd7cae122008-07-26 21:49:3839
[email protected]4b559b4d2011-04-14 17:37:1440} // namespace crypto
initial.commitd7cae122008-07-26 21:49:3841
[email protected]4b559b4d2011-04-14 17:37:1442#endif // CRYPTO_SHA2_H_