sha1.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. namespace base {
  12. // These functions perform SHA-1 operations.
  13. enum { kSHA1Length = 20 }; // Length in bytes of a SHA-1 hash.
  14. // The output of a SHA-1 operation.
  15. using SHA1Digest = std::array<uint8_t, kSHA1Length>;
  16. // Computes the SHA-1 hash of the input |data| and returns the full hash.
  17. BASE_EXPORT SHA1Digest SHA1HashSpan(span<const uint8_t> data);
  18. // Computes the SHA-1 hash of the input string |str| and returns the full
  19. // hash.
  20. BASE_EXPORT std::string SHA1HashString(const std::string& str);
  21. // Computes the SHA-1 hash of the |len| bytes in |data| and puts the hash
  22. // in |hash|. |hash| must be kSHA1Length bytes long.
  23. BASE_EXPORT void SHA1HashBytes(const unsigned char* data,
  24. size_t len,
  25. unsigned char* hash);
  26. } // namespace base
  27. #endif // BASE_HASH_SHA1_H_