PageLanguageDetectionTest has the failure rate of 5 - 6% on XP/Vista. Mark it
[chromium-blink-merge.git] / base / md5.h
blob227e008f84dadf307137292a3500b0e3b474e92e
1 // Copyright (c) 2006-2009 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.
5 #ifndef BASE_MD5_H_
6 #define BASE_MD5_H_
8 #include <string>
10 // MD5 stands for Message Digest algorithm 5.
11 // MD5 is a robust hash function, designed for cyptography, but often used
12 // for file checksums. The code is complex and slow, but has few
13 // collisions.
14 // See Also:
15 // http://en.wikipedia.org/wiki/MD5
17 // These functions perform MD5 operations. The simplest call is MD5Sum() to
18 // generate the MD5 sum of the given data.
20 // You can also compute the MD5 sum of data incrementally by making multiple
21 // calls to MD5Update():
22 // MD5Context ctx; // intermediate MD5 data: do not use
23 // MD5Init(&ctx);
24 // MD5Update(&ctx, data1, length1);
25 // MD5Update(&ctx, data2, length2);
26 // ...
28 // MD5Digest digest; // the result of the computation
29 // MD5Final(&digest, &ctx);
31 // You can call MD5DigestToBase16() to generate a string of the digest.
33 // The output of an MD5 operation
34 typedef struct MD5Digest_struct {
35 unsigned char a[16];
36 } MD5Digest;
38 // Used for storing intermediate data during an MD5 computation. Callers
39 // should not access the data.
40 typedef char MD5Context[88];
42 // Computes the MD5 sum of the given data buffer with the given length.
43 // The given 'digest' structure will be filled with the result data.
44 void MD5Sum(const void* data, size_t length, MD5Digest* digest);
46 // Initializes the given MD5 context structure for subsequent calls to
47 // MD5Update().
48 void MD5Init(MD5Context* context);
50 // For the given buffer of data, updates the given MD5 context with the sum of
51 // the data. You can call this any number of times during the computation,
52 // except that MD5Init() must have been called first.
53 void MD5Update(MD5Context* context, const void* buf, size_t len);
55 // Finalizes the MD5 operation and fills the buffer with the digest.
56 void MD5Final(MD5Digest* digest, MD5Context* pCtx);
58 // Converts a digest into human-readable hexadecimal.
59 std::string MD5DigestToBase16(const MD5Digest& digest);
61 // Returns the MD5 (in hexadecimal) of a string.
62 std::string MD5String(const std::string& str);
64 #endif // BASE_MD5_H_