1259698Sdim/*
2259698Sdim * This code is derived from (original license follows):
3259698Sdim *
4259698Sdim * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
5259698Sdim * MD5 Message-Digest Algorithm (RFC 1321).
6259698Sdim *
7259698Sdim * Homepage:
8259698Sdim * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
9259698Sdim *
10259698Sdim * Author:
11259698Sdim * Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
12259698Sdim *
13259698Sdim * This software was written by Alexander Peslyak in 2001.  No copyright is
14259698Sdim * claimed, and the software is hereby placed in the public domain.
15259698Sdim * In case this attempt to disclaim copyright and place the software in the
16259698Sdim * public domain is deemed null and void, then the software is
17259698Sdim * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
18259698Sdim * general public under the following terms:
19259698Sdim *
20259698Sdim * Redistribution and use in source and binary forms, with or without
21259698Sdim * modification, are permitted.
22259698Sdim *
23259698Sdim * There's ABSOLUTELY NO WARRANTY, express or implied.
24259698Sdim *
25259698Sdim * See md5.c for more information.
26259698Sdim */
27259698Sdim
28259698Sdim#ifndef LLVM_SYSTEM_MD5_H
29259698Sdim#define LLVM_SYSTEM_MD5_H
30259698Sdim
31259698Sdim#include "llvm/ADT/SmallString.h"
32259698Sdim#include "llvm/Support/DataTypes.h"
33259698Sdim
34259698Sdimnamespace llvm {
35259698Sdim
36259698Sdimtemplate <typename T> class ArrayRef;
37259698Sdim
38259698Sdimclass MD5 {
39259698Sdim  // Any 32-bit or wider unsigned integer data type will do.
40259698Sdim  typedef uint32_t MD5_u32plus;
41259698Sdim
42259698Sdim  MD5_u32plus a, b, c, d;
43259698Sdim  MD5_u32plus hi, lo;
44259698Sdim  uint8_t buffer[64];
45259698Sdim  MD5_u32plus block[16];
46259698Sdim
47259698Sdimpublic:
48259698Sdim  typedef uint8_t MD5Result[16];
49259698Sdim
50259698Sdim  MD5();
51259698Sdim
52259698Sdim  /// \brief Updates the hash for the byte stream provided.
53259698Sdim  void update(ArrayRef<uint8_t> Data);
54259698Sdim
55259698Sdim  /// \brief Updates the hash for the StringRef provided.
56259698Sdim  void update(StringRef Str);
57259698Sdim
58259698Sdim  /// \brief Finishes off the hash and puts the result in result.
59259698Sdim  void final(MD5Result &result);
60259698Sdim
61259698Sdim  /// \brief Translates the bytes in \p Res to a hex string that is
62259698Sdim  /// deposited into \p Str. The result will be of length 32.
63259698Sdim  static void stringifyResult(MD5Result &Res, SmallString<32> &Str);
64259698Sdim
65259698Sdimprivate:
66259698Sdim  const uint8_t *body(ArrayRef<uint8_t> Data);
67259698Sdim};
68259698Sdim
69259698Sdim}
70259698Sdim
71259698Sdim#endif
72