blob: 6d8f5a34ef530030d8445be84ff25b41c4198ad8 [file] [log] [blame]
David Ghandehari9e5b5872016-07-28 09:50:04 -07001// 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 Top0d1858f2019-05-15 22:01:47 -070010#include "base/strings/string_piece.h"
David Ghandehari9e5b5872016-07-28 09:50:04 -070011#include "crypto/crypto_export.h"
Andrew Top0d1858f2019-05-15 22:01:47 -070012#include "starboard/types.h"
David Ghandehari9e5b5872016-07-28 09:50:04 -070013
14namespace 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
20static 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 Top0d1858f2019-05-15 22:01:47 -070025CRYPTO_EXPORT void SHA256HashString(base::StringPiece str,
26 void* output,
27 size_t len);
David Ghandehari9e5b5872016-07-28 09:50:04 -070028
29// Convenience version of the above that returns the result in a 32-byte
30// string.
Andrew Top0d1858f2019-05-15 22:01:47 -070031CRYPTO_EXPORT std::string SHA256HashString(base::StringPiece str);
David Ghandehari9e5b5872016-07-28 09:50:04 -070032
33} // namespace crypto
34
35#endif // CRYPTO_SHA2_H_