Fix platform conditionalization of NaCl IRT file name
[chromium-blink-merge.git] / base / md5.h
blob915dd8b77a59a6bbf3dd62e4a6a55ed10c69fbc4
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.
5 #ifndef BASE_MD5_H_
6 #define BASE_MD5_H_
7 #pragma once
9 #include "base/base_export.h"
10 #include "base/string_piece.h"
12 namespace base {
14 // MD5 stands for Message Digest algorithm 5.
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
17 // collisions.
18 // See Also:
19 // http://en.wikipedia.org/wiki/MD5
21 // These functions perform MD5 operations. The simplest call is MD5Sum() to
22 // generate the MD5 sum of the given data.
24 // You can also compute the MD5 sum of data incrementally by making multiple
25 // calls to MD5Update():
26 // MD5Context ctx; // intermediate MD5 data: do not use
27 // MD5Init(&ctx);
28 // MD5Update(&ctx, data1, length1);
29 // MD5Update(&ctx, data2, length2);
30 // ...
32 // MD5Digest digest; // the result of the computation
33 // MD5Final(&digest, &ctx);
35 // You can call MD5DigestToBase16() to generate a string of the digest.
37 // The output of an MD5 operation.
38 struct MD5Digest {
39 unsigned char a[16];
42 // Used for storing intermediate data during an MD5 computation. Callers
43 // should not access the data.
44 typedef char MD5Context[88];
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.
48 BASE_EXPORT void MD5Sum(const void* data, size_t length, MD5Digest* digest);
50 // Initializes the given MD5 context structure for subsequent calls to
51 // MD5Update().
52 BASE_EXPORT void MD5Init(MD5Context* context);
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
56 // during the computation, except that MD5Init() must have been called first.
57 BASE_EXPORT void MD5Update(MD5Context* context, const StringPiece& data);
59 // Finalizes the MD5 operation and fills the buffer with the digest.
60 BASE_EXPORT void MD5Final(MD5Digest* digest, MD5Context* context);
62 // Converts a digest into human-readable hexadecimal.
63 BASE_EXPORT std::string MD5DigestToBase16(const MD5Digest& digest);
65 // Returns the MD5 (in hexadecimal) of a string.
66 BASE_EXPORT std::string MD5String(const StringPiece& str);
68 } // namespace base
70 #endif // BASE_MD5_H_