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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/base_api.h" | 9 #include "base/base_export.h" |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 | 13 |
14 // MD5 stands for Message Digest algorithm 5. | 14 // MD5 stands for Message Digest algorithm 5. |
15 // MD5 is a robust hash function, designed for cyptography, but often used | 15 // MD5 is a robust hash function, designed for cyptography, but often used |
16 // for file checksums. The code is complex and slow, but has few | 16 // for file checksums. The code is complex and slow, but has few |
17 // collisions. | 17 // collisions. |
18 // See Also: | 18 // See Also: |
19 // http://en.wikipedia.org/wiki/MD5 | 19 // http://en.wikipedia.org/wiki/MD5 |
(...skipping 18 matching lines...) Expand all Loading... |
38 struct MD5Digest { | 38 struct MD5Digest { |
39 unsigned char a[16]; | 39 unsigned char a[16]; |
40 }; | 40 }; |
41 | 41 |
42 // Used for storing intermediate data during an MD5 computation. Callers | 42 // Used for storing intermediate data during an MD5 computation. Callers |
43 // should not access the data. | 43 // should not access the data. |
44 typedef char MD5Context[88]; | 44 typedef char MD5Context[88]; |
45 | 45 |
46 // Computes the MD5 sum of the given data buffer with the given length. | 46 // Computes the MD5 sum of the given data buffer with the given length. |
47 // The given 'digest' structure will be filled with the result data. | 47 // The given 'digest' structure will be filled with the result data. |
48 BASE_API void MD5Sum(const void* data, size_t length, MD5Digest* digest); | 48 BASE_EXPORT void MD5Sum(const void* data, size_t length, MD5Digest* digest); |
49 | 49 |
50 // Initializes the given MD5 context structure for subsequent calls to | 50 // Initializes the given MD5 context structure for subsequent calls to |
51 // MD5Update(). | 51 // MD5Update(). |
52 BASE_API void MD5Init(MD5Context* context); | 52 BASE_EXPORT void MD5Init(MD5Context* context); |
53 | 53 |
54 // For the given buffer of |data| as a StringPiece, updates the given MD5 | 54 // For the given buffer of |data| as a StringPiece, updates the given MD5 |
55 // context with the sum of the data. You can call this any number of times | 55 // context with the sum of the data. You can call this any number of times |
56 // during the computation, except that MD5Init() must have been called first. | 56 // during the computation, except that MD5Init() must have been called first. |
57 BASE_API void MD5Update(MD5Context* context, const StringPiece& data); | 57 BASE_EXPORT void MD5Update(MD5Context* context, const StringPiece& data); |
58 | 58 |
59 // Finalizes the MD5 operation and fills the buffer with the digest. | 59 // Finalizes the MD5 operation and fills the buffer with the digest. |
60 BASE_API void MD5Final(MD5Digest* digest, MD5Context* context); | 60 BASE_EXPORT void MD5Final(MD5Digest* digest, MD5Context* context); |
61 | 61 |
62 // Converts a digest into human-readable hexadecimal. | 62 // Converts a digest into human-readable hexadecimal. |
63 BASE_API std::string MD5DigestToBase16(const MD5Digest& digest); | 63 BASE_EXPORT std::string MD5DigestToBase16(const MD5Digest& digest); |
64 | 64 |
65 // Returns the MD5 (in hexadecimal) of a string. | 65 // Returns the MD5 (in hexadecimal) of a string. |
66 BASE_API std::string MD5String(const StringPiece& str); | 66 BASE_EXPORT std::string MD5String(const StringPiece& str); |
67 | 67 |
68 } // namespace base | 68 } // namespace base |
69 | 69 |
70 // TODO(tfarina): Fix third_party/hunspell then remove this hack. | 70 // TODO(tfarina): Fix third_party/hunspell then remove this hack. |
71 using base::MD5Digest; | 71 using base::MD5Digest; |
72 | 72 |
73 #endif // BASE_MD5_H_ | 73 #endif // BASE_MD5_H_ |
OLD | NEW |