1 // Copyright 2011 The Chromium Authors 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 BASE_HASH_SHA1_H_ 6 #define BASE_HASH_SHA1_H_ 7 8 #include <stddef.h> 9 10 #include <array> 11 #include <string> 12 13 #include "base/base_export.h" 14 #include "base/containers/span.h" 15 #include "base/strings/string_piece.h" 16 #include "build/build_config.h" 17 #if BUILDFLAG(IS_NACL) 18 #include "base/hash/sha1_nacl.h" 19 #else 20 #include "base/hash/sha1_boringssl.h" 21 #endif 22 23 namespace base { 24 25 enum { kSHA1Length = 20 }; // Length in bytes of a SHA-1 hash. 26 27 // The output of an SHA-1 operation. 28 using SHA1Digest = std::array<uint8_t, kSHA1Length>; 29 30 // These functions perform SHA-1 operations. 31 // Computes the SHA-1 hash of the input |data| and returns the full hash. 32 BASE_EXPORT SHA1Digest SHA1HashSpan(span<const uint8_t> data); 33 // Computes the SHA-1 hash of the input string |str| and returns the full 34 // hash. 35 BASE_EXPORT std::string SHA1HashString(StringPiece str); 36 // Computes the SHA-1 hash of the |len| bytes in |data| and puts the hash 37 // in |hash|. |hash| must be kSHA1Length bytes long. 38 BASE_EXPORT void SHA1HashBytes(const unsigned char* data, 39 size_t len, 40 unsigned char* hash); 41 42 // These functions allow streaming SHA-1 operations. 43 BASE_EXPORT void SHA1Init(SHA1Context& context); 44 BASE_EXPORT void SHA1Update(const StringPiece data, SHA1Context& context); 45 BASE_EXPORT void SHA1Final(SHA1Context& context, SHA1Digest& digest); 46 } // namespace base 47 48 #endif // BASE_HASH_SHA1_H_ 49