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