MD5.h revision f7306f224e7f85c2690256636613422c4a7b8230
19f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher/*
29f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * This code is derived from (original license follows):
39f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher *
49f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
59f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * MD5 Message-Digest Algorithm (RFC 1321).
69f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher *
79f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * Homepage:
89f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
99f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher *
109f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * Author:
119f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
129f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher *
139f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * This software was written by Alexander Peslyak in 2001.  No copyright is
149f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * claimed, and the software is hereby placed in the public domain.
159f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * In case this attempt to disclaim copyright and place the software in the
169f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * public domain is deemed null and void, then the software is
179f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
189f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * general public under the following terms:
199f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher *
209f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * Redistribution and use in source and binary forms, with or without
219f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * modification, are permitted.
229f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher *
239f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * There's ABSOLUTELY NO WARRANTY, express or implied.
249f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher *
259f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher * See md5.c for more information.
269f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher */
279f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher
289f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher#ifndef LLVM_SYSTEM_MD5_H
299f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher#define LLVM_SYSTEM_MD5_H
309f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher
31f7306f224e7f85c2690256636613422c4a7b8230Eric Christopher#include "llvm/ADT/SmallString.h"
329f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher#include "llvm/Support/DataTypes.h"
339f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher
349f31f7c3055a3c028c54888832ed61c6912aac41Eric Christophernamespace llvm {
359f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher
36f7306f224e7f85c2690256636613422c4a7b8230Eric Christophertemplate <typename T> class ArrayRef;
37f7306f224e7f85c2690256636613422c4a7b8230Eric Christopher
389f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopherclass MD5 {
399f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher  // Any 32-bit or wider unsigned integer data type will do.
409f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher  typedef uint32_t MD5_u32plus;
419f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher
429f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher  MD5_u32plus a, b, c, d;
439f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher  MD5_u32plus hi, lo;
449f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher  unsigned char buffer[64];
459f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher  MD5_u32plus block[16];
469f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher
47f7306f224e7f85c2690256636613422c4a7b8230Eric Christopherpublic:
48f7306f224e7f85c2690256636613422c4a7b8230Eric Christopher  typedef unsigned char MD5Result[16];
49f7306f224e7f85c2690256636613422c4a7b8230Eric Christopher
509f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher  MD5();
519f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher
529f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher  /// \brief Updates the hash for arguments provided.
53f7306f224e7f85c2690256636613422c4a7b8230Eric Christopher  void update(ArrayRef<unsigned char> Data);
549f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher
559f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher  /// \brief Finishes off the hash and puts the result in result.
56f7306f224e7f85c2690256636613422c4a7b8230Eric Christopher  void final(MD5Result &result);
57f7306f224e7f85c2690256636613422c4a7b8230Eric Christopher
58f7306f224e7f85c2690256636613422c4a7b8230Eric Christopher  static void stringifyResult(MD5Result &Res, SmallString<32> &Str);
599f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher
609f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopherprivate:
61f7306f224e7f85c2690256636613422c4a7b8230Eric Christopher  const unsigned char *body(ArrayRef<unsigned char> Data);
629f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher};
639f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher
649f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher}
659f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher
669f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher#endif
67