LLVM API Documentation
00001 /* 00002 * This code is derived from (original license follows): 00003 * 00004 * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. 00005 * MD5 Message-Digest Algorithm (RFC 1321). 00006 * 00007 * Homepage: 00008 * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 00009 * 00010 * Author: 00011 * Alexander Peslyak, better known as Solar Designer <solar at openwall.com> 00012 * 00013 * This software was written by Alexander Peslyak in 2001. No copyright is 00014 * claimed, and the software is hereby placed in the public domain. 00015 * In case this attempt to disclaim copyright and place the software in the 00016 * public domain is deemed null and void, then the software is 00017 * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the 00018 * general public under the following terms: 00019 * 00020 * Redistribution and use in source and binary forms, with or without 00021 * modification, are permitted. 00022 * 00023 * There's ABSOLUTELY NO WARRANTY, express or implied. 00024 * 00025 * See md5.c for more information. 00026 */ 00027 00028 #ifndef LLVM_SUPPORT_MD5_H 00029 #define LLVM_SUPPORT_MD5_H 00030 00031 #include "llvm/ADT/ArrayRef.h" 00032 #include "llvm/ADT/SmallString.h" 00033 #include "llvm/Support/DataTypes.h" 00034 00035 namespace llvm { 00036 00037 class MD5 { 00038 // Any 32-bit or wider unsigned integer data type will do. 00039 typedef uint32_t MD5_u32plus; 00040 00041 MD5_u32plus a, b, c, d; 00042 MD5_u32plus hi, lo; 00043 uint8_t buffer[64]; 00044 MD5_u32plus block[16]; 00045 00046 public: 00047 typedef uint8_t MD5Result[16]; 00048 00049 MD5(); 00050 00051 /// \brief Updates the hash for the byte stream provided. 00052 void update(ArrayRef<uint8_t> Data); 00053 00054 /// \brief Updates the hash for the StringRef provided. 00055 void update(StringRef Str); 00056 00057 /// \brief Finishes off the hash and puts the result in result. 00058 void final(MD5Result &result); 00059 00060 /// \brief Translates the bytes in \p Res to a hex string that is 00061 /// deposited into \p Str. The result will be of length 32. 00062 static void stringifyResult(MD5Result &Res, SmallString<32> &Str); 00063 00064 private: 00065 const uint8_t *body(ArrayRef<uint8_t> Data); 00066 }; 00067 00068 } 00069 00070 #endif