1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file. 4*635a8641SAndroid Build Coastguard Worker 5*635a8641SAndroid Build Coastguard Worker #ifndef CRYPTO_SHA2_H_ 6*635a8641SAndroid Build Coastguard Worker #define CRYPTO_SHA2_H_ 7*635a8641SAndroid Build Coastguard Worker 8*635a8641SAndroid Build Coastguard Worker #include <stddef.h> 9*635a8641SAndroid Build Coastguard Worker 10*635a8641SAndroid Build Coastguard Worker #include <string> 11*635a8641SAndroid Build Coastguard Worker 12*635a8641SAndroid Build Coastguard Worker #include "base/strings/string_piece.h" 13*635a8641SAndroid Build Coastguard Worker #include "crypto/crypto_export.h" 14*635a8641SAndroid Build Coastguard Worker 15*635a8641SAndroid Build Coastguard Worker namespace crypto { 16*635a8641SAndroid Build Coastguard Worker 17*635a8641SAndroid Build Coastguard Worker // These functions perform SHA-256 operations. 18*635a8641SAndroid Build Coastguard Worker // 19*635a8641SAndroid Build Coastguard Worker // Functions for SHA-384 and SHA-512 can be added when the need arises. 20*635a8641SAndroid Build Coastguard Worker 21*635a8641SAndroid Build Coastguard Worker static const size_t kSHA256Length = 32; // Length in bytes of a SHA-256 hash. 22*635a8641SAndroid Build Coastguard Worker 23*635a8641SAndroid Build Coastguard Worker // Computes the SHA-256 hash of the input string 'str' and stores the first 24*635a8641SAndroid Build Coastguard Worker // 'len' bytes of the hash in the output buffer 'output'. If 'len' > 32, 25*635a8641SAndroid Build Coastguard Worker // only 32 bytes (the full hash) are stored in the 'output' buffer. 26*635a8641SAndroid Build Coastguard Worker CRYPTO_EXPORT void SHA256HashString(base::StringPiece str, 27*635a8641SAndroid Build Coastguard Worker void* output, 28*635a8641SAndroid Build Coastguard Worker size_t len); 29*635a8641SAndroid Build Coastguard Worker 30*635a8641SAndroid Build Coastguard Worker // Convenience version of the above that returns the result in a 32-byte 31*635a8641SAndroid Build Coastguard Worker // string. 32*635a8641SAndroid Build Coastguard Worker CRYPTO_EXPORT std::string SHA256HashString(base::StringPiece str); 33*635a8641SAndroid Build Coastguard Worker 34*635a8641SAndroid Build Coastguard Worker } // namespace crypto 35*635a8641SAndroid Build Coastguard Worker 36*635a8641SAndroid Build Coastguard Worker #endif // CRYPTO_SHA2_H_ 37