OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_MD5_H_ | 5 #ifndef BASE_MD5_H_ |
6 #define BASE_MD5_H_ | 6 #define BASE_MD5_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 // The output of an MD5 operation. | 38 // The output of an MD5 operation. |
39 struct MD5Digest { | 39 struct MD5Digest { |
40 uint8_t a[16]; | 40 uint8_t a[16]; |
41 }; | 41 }; |
42 | 42 |
43 // Used for storing intermediate data during an MD5 computation. Callers | 43 // Used for storing intermediate data during an MD5 computation. Callers |
44 // should not access the data. | 44 // should not access the data. |
45 typedef char MD5Context[88]; | 45 typedef char MD5Context[88]; |
46 | 46 |
47 // Computes the MD5 sum of the given data buffer with the given length. | |
48 // The given 'digest' structure will be filled with the result data. | |
49 BASE_EXPORT void MD5Sum(const void* data, size_t length, MD5Digest* digest); | |
50 | |
51 // Initializes the given MD5 context structure for subsequent calls to | 47 // Initializes the given MD5 context structure for subsequent calls to |
52 // MD5Update(). | 48 // MD5Update(). |
53 BASE_EXPORT void MD5Init(MD5Context* context); | 49 BASE_EXPORT void MD5Init(MD5Context* context); |
54 | 50 |
55 // For the given buffer of |data| as a StringPiece, updates the given MD5 | 51 // For the given buffer of |data| as a StringPiece, updates the given MD5 |
56 // context with the sum of the data. You can call this any number of times | 52 // context with the sum of the data. You can call this any number of times |
57 // during the computation, except that MD5Init() must have been called first. | 53 // during the computation, except that MD5Init() must have been called first. |
58 BASE_EXPORT void MD5Update(MD5Context* context, const StringPiece& data); | 54 BASE_EXPORT void MD5Update(MD5Context* context, const StringPiece& data); |
59 | 55 |
60 // Finalizes the MD5 operation and fills the buffer with the digest. | 56 // Finalizes the MD5 operation and fills the buffer with the digest. |
61 BASE_EXPORT void MD5Final(MD5Digest* digest, MD5Context* context); | 57 BASE_EXPORT void MD5Final(MD5Digest* digest, MD5Context* context); |
62 | 58 |
63 // MD5IntermediateFinal() generates a digest without finalizing the MD5 | 59 // MD5IntermediateFinal() generates a digest without finalizing the MD5 |
64 // operation. Can be used to generate digests for the input seen thus far, | 60 // operation. Can be used to generate digests for the input seen thus far, |
65 // without affecting the digest generated for the entire input. | 61 // without affecting the digest generated for the entire input. |
66 BASE_EXPORT void MD5IntermediateFinal(MD5Digest* digest, | 62 BASE_EXPORT void MD5IntermediateFinal(MD5Digest* digest, |
67 const MD5Context* context); | 63 const MD5Context* context); |
68 | 64 |
69 // Converts a digest into human-readable hexadecimal. | 65 // Converts a digest into human-readable hexadecimal. |
70 BASE_EXPORT std::string MD5DigestToBase16(const MD5Digest& digest); | 66 BASE_EXPORT std::string MD5DigestToBase16(const MD5Digest& digest); |
71 | 67 |
| 68 // Computes the MD5 sum of the given data buffer with the given length. |
| 69 // The given 'digest' structure will be filled with the result data. |
| 70 BASE_EXPORT void MD5Sum(const void* data, size_t length, MD5Digest* digest); |
| 71 |
72 // Returns the MD5 (in hexadecimal) of a string. | 72 // Returns the MD5 (in hexadecimal) of a string. |
73 BASE_EXPORT std::string MD5String(const StringPiece& str); | 73 BASE_EXPORT std::string MD5String(const StringPiece& str); |
74 | 74 |
75 } // namespace base | 75 } // namespace base |
76 | 76 |
77 #endif // BASE_MD5_H_ | 77 #endif // BASE_MD5_H_ |
OLD | NEW |