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 2837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#ifndef LLVM_SUPPORT_MD5_H 2937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#define LLVM_SUPPORT_MD5_H 309f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher 3136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/ADT/ArrayRef.h" 32f7306f224e7f85c2690256636613422c4a7b8230Eric Christopher#include "llvm/ADT/SmallString.h" 339f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher#include "llvm/Support/DataTypes.h" 349f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher 359f31f7c3055a3c028c54888832ed61c6912aac41Eric Christophernamespace llvm { 369f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher 379f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopherclass MD5 { 389f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher // Any 32-bit or wider unsigned integer data type will do. 399f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher typedef uint32_t MD5_u32plus; 409f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher 419f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher MD5_u32plus a, b, c, d; 429f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher MD5_u32plus hi, lo; 43800e6ee52fd32e0b129cbccd811166d7e215e6adEric Christopher uint8_t buffer[64]; 449f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher MD5_u32plus block[16]; 459f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher 46f7306f224e7f85c2690256636613422c4a7b8230Eric Christopherpublic: 47800e6ee52fd32e0b129cbccd811166d7e215e6adEric Christopher typedef uint8_t MD5Result[16]; 48f7306f224e7f85c2690256636613422c4a7b8230Eric Christopher 499f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher MD5(); 509f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher 51769d24a60d798ffa3a47a01c9e7a0dcfaefbb882Eric Christopher /// \brief Updates the hash for the byte stream provided. 52800e6ee52fd32e0b129cbccd811166d7e215e6adEric Christopher void update(ArrayRef<uint8_t> Data); 539f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher 54769d24a60d798ffa3a47a01c9e7a0dcfaefbb882Eric Christopher /// \brief Updates the hash for the StringRef provided. 55769d24a60d798ffa3a47a01c9e7a0dcfaefbb882Eric Christopher void update(StringRef Str); 56769d24a60d798ffa3a47a01c9e7a0dcfaefbb882Eric Christopher 579f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher /// \brief Finishes off the hash and puts the result in result. 5837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines void final(MD5Result &Result); 59f7306f224e7f85c2690256636613422c4a7b8230Eric Christopher 6060057270d9ea9cb9527e0ac8b77ba2c5a08a8af9Eric Christopher /// \brief Translates the bytes in \p Res to a hex string that is 6160057270d9ea9cb9527e0ac8b77ba2c5a08a8af9Eric Christopher /// deposited into \p Str. The result will be of length 32. 6237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines static void stringifyResult(MD5Result &Result, SmallString<32> &Str); 639f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher 649f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopherprivate: 65800e6ee52fd32e0b129cbccd811166d7e215e6adEric Christopher const uint8_t *body(ArrayRef<uint8_t> Data); 669f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher}; 679f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher 689f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher} 699f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher 709f31f7c3055a3c028c54888832ed61c6912aac41Eric Christopher#endif 71