sha1.h 1.6 KB

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