On Mon, May 20, 2013 at 6:28 PM, Eric Christopher <span dir="ltr"><<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: echristo<br>
Date: Mon May 20 20:28:35 2013<br>
New Revision: 182348<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=182348&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=182348&view=rev</a><br>
Log:<br>
Add an md5 library derived from a public domain implementation for dwarf4<br>
type signature computation.<br>
<br>
Added:<br>
    llvm/trunk/include/llvm/Support/MD5.h<br>
    llvm/trunk/lib/Support/MD5.cpp<br></blockquote><div><br></div><div>Tests would be nice!</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Modified:<br>
    llvm/trunk/LICENSE.TXT<br>
<br>
Modified: llvm/trunk/LICENSE.TXT<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/LICENSE.TXT?rev=182348&r1=182347&r2=182348&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/LICENSE.TXT?rev=182348&r1=182347&r2=182348&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/LICENSE.TXT (original)<br>
+++ llvm/trunk/LICENSE.TXT Mon May 20 20:28:35 2013<br>
@@ -68,3 +68,4 @@ Google Test         llvm/utils/unittest/<br>
 OpenBSD regex       llvm/lib/Support/{reg*, COPYRIGHT.regex}<br>
 pyyaml tests        llvm/test/YAMLParser/{*.data, LICENSE.TXT}<br>
 ARM contributions   llvm/lib/Target/ARM/LICENSE.TXT<br>
+md5 contributions   llvm/lib/Support/md5*<br>
<br>
Added: llvm/trunk/include/llvm/Support/MD5.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MD5.h?rev=182348&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MD5.h?rev=182348&view=auto</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/Support/MD5.h (added)<br>
+++ llvm/trunk/include/llvm/Support/MD5.h Mon May 20 20:28:35 2013<br>
@@ -0,0 +1,59 @@<br>
+/*<br>
+ * This code is derived from (original license follows):<br>
+ *<br>
+ * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.<br>
+ * MD5 Message-Digest Algorithm (RFC 1321).<br>
+ *<br>
+ * Homepage:<br>
+ * <a href="http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5" target="_blank">http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5</a><br>
+ *<br>
+ * Author:<br>
+ * Alexander Peslyak, better known as Solar Designer <solar at <a href="http://openwall.com" target="_blank">openwall.com</a>><br>
+ *<br>
+ * This software was written by Alexander Peslyak in 2001.  No copyright is<br>
+ * claimed, and the software is hereby placed in the public domain.<br>
+ * In case this attempt to disclaim copyright and place the software in the<br>
+ * public domain is deemed null and void, then the software is<br>
+ * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the<br>
+ * general public under the following terms:<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted.<br>
+ *<br>
+ * There's ABSOLUTELY NO WARRANTY, express or implied.<br>
+ *<br>
+ * See md5.c for more information.<br>
+ */<br>
+<br>
+#ifndef LLVM_SYSTEM_MD5_H<br>
+#define LLVM_SYSTEM_MD5_H<br>
+<br>
+#include "llvm/Support/DataTypes.h"<br>
+<br>
+namespace llvm {<br>
+<br>
+class MD5 {<br>
+  // Any 32-bit or wider unsigned integer data type will do.<br>
+  typedef uint32_t MD5_u32plus;<br>
+<br>
+  MD5_u32plus a, b, c, d;<br>
+  MD5_u32plus hi, lo;<br>
+  unsigned char buffer[64];<br>
+  MD5_u32plus block[16];<br>
+<br>
+ public:<br>
+  MD5();<br>
+<br>
+  /// \brief Updates the hash for arguments provided.<br>
+  void Update(void *data, unsigned long size);<br></blockquote><div><br></div><div>ArrayRef? Also 'update', 'Data', 'Size'.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+<br>
+  /// \brief Finishes off the hash and puts the result in result.<br>
+  void Final(unsigned char *result);<br></blockquote><div><br></div><div>unsigned char (&result)[16] here; a typedef for "unsigned char [16]" might be useful too.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+<br>
+private:<br>
+  void *body(void *data, unsigned long size);<br>
+};<br>
+<br>
+}<br>
+<br>
+#endif<br>
<br>
Added: llvm/trunk/lib/Support/MD5.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/MD5.cpp?rev=182348&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/MD5.cpp?rev=182348&view=auto</a><br>

==============================================================================<br>
--- llvm/trunk/lib/Support/MD5.cpp (added)<br>
+++ llvm/trunk/lib/Support/MD5.cpp Mon May 20 20:28:35 2013<br>
@@ -0,0 +1,266 @@<br>
+/*<br>
+ * This code is derived from (original license follows):<br>
+ *<br>
+ * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.<br>
+ * MD5 Message-Digest Algorithm (RFC 1321).<br>
+ *<br>
+ * Homepage:<br>
+ * <a href="http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5" target="_blank">http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5</a><br>
+ *<br>
+ * Author:<br>
+ * Alexander Peslyak, better known as Solar Designer <solar at <a href="http://openwall.com" target="_blank">openwall.com</a>><br>
+ *<br>
+ * This software was written by Alexander Peslyak in 2001.  No copyright is<br>
+ * claimed, and the software is hereby placed in the public domain.<br>
+ * In case this attempt to disclaim copyright and place the software in the<br>
+ * public domain is deemed null and void, then the software is<br>
+ * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the<br>
+ * general public under the following terms:<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted.<br>
+ *<br>
+ * There's ABSOLUTELY NO WARRANTY, express or implied.<br>
+ *<br>
+ * (This is a heavily cut-down "BSD license".)<br>
+ *<br>
+ * This differs from Colin Plumb's older public domain implementation in that<br>
+ * no exactly 32-bit integer data type is required (any 32-bit or wider<br>
+ * unsigned integer data type will do), there's no compile-time endianness<br>
+ * configuration, and the function prototypes match OpenSSL's.  No code from<br>
+ * Colin Plumb's implementation has been reused; this comment merely compares<br>
+ * the properties of the two independent implementations.<br>
+ *<br>
+ * The primary goals of this implementation are portability and ease of use.<br>
+ * It is meant to be fast, but not as fast as possible.  Some known<br>
+ * optimizations are not included to reduce source code size and avoid<br>
+ * compile-time configuration.<br>
+ */<br>
+<br>
+#include "llvm/Support/MD5.h"<br>
+#include <cstring><br>
+<br>
+// The basic MD5 functions.<br>
+<br>
+// F and G are optimized compared to their RFC 1321 definitions for<br>
+// architectures that lack an AND-NOT instruction, just like in Colin Plumb's<br>
+// implementation.<br>
+#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))<br>
+#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))<br>
+#define H(x, y, z) ((x) ^ (y) ^ (z))<br>
+#define I(x, y, z) ((y) ^ ((x) | ~(z)))<br>
+<br>
+// The MD5 transformation for all four rounds.<br>
+#define STEP(f, a, b, c, d, x, t, s)                                           \<br>
+  (a) += f((b), (c), (d)) + (x) + (t);                                         \<br>
+  (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s))));                   \<br>
+  (a) += (b);<br>
+<br>
+// SET reads 4 input bytes in little-endian byte order and stores them<br>
+// in a properly aligned word in host byte order.<br>
+#define SET(n)                                                                 \<br>
+  (block[(n)] =                                                                \<br>
+       (MD5_u32plus) ptr[(n) * 4] | ((MD5_u32plus) ptr[(n) * 4 + 1] << 8) |    \<br>
+       ((MD5_u32plus) ptr[(n) * 4 + 2] << 16) |                                \<br>
+       ((MD5_u32plus) ptr[(n) * 4 + 3] << 24))<br>
+#define GET(n) (block[(n)])<br>
+<br>
+namespace llvm {<br>
+<br>
+/// \brief This processes one or more 64-byte data blocks, but does NOT update<br>
+///the bit counters.  There are no alignment requirements.<br>
+void *MD5::body(void *data, unsigned long size) {<br>
+  unsigned char *ptr;<br>
+  MD5_u32plus a, b, c, d;<br>
+  MD5_u32plus saved_a, saved_b, saved_c, saved_d;<br>
+<br>
+  ptr = (unsigned char *)data;<br>
+<br>
+  a = this->a;<br>
+  b = this->b;<br>
+  c = this->c;<br>
+  d = this->d;<br>
+<br>
+  do {<br>
+    saved_a = a;<br>
+    saved_b = b;<br>
+    saved_c = c;<br>
+    saved_d = d;<br>
+<br>
+    // Round 1<br>
+    STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)<br>
+    STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)<br>
+    STEP(F, c, d, a, b, SET(2), 0x242070db, 17)<br>
+    STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)<br>
+    STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)<br>
+    STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)<br>
+    STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)<br>
+    STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)<br>
+    STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)<br>
+    STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)<br>
+    STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)<br>
+    STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)<br>
+    STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)<br>
+    STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)<br>
+    STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)<br>
+    STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)<br>
+<br>
+    // Round 2<br>
+    STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)<br>
+    STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)<br>
+    STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)<br>
+    STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)<br>
+    STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)<br>
+    STEP(G, d, a, b, c, GET(10), 0x02441453, 9)<br>
+    STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)<br>
+    STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)<br>
+    STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)<br>
+    STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)<br>
+    STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)<br>
+    STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)<br>
+    STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)<br>
+    STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)<br>
+    STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)<br>
+    STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)<br>
+<br>
+    // Round 3<br>
+    STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)<br>
+    STEP(H, d, a, b, c, GET(8), 0x8771f681, 11)<br>
+    STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)<br>
+    STEP(H, b, c, d, a, GET(14), 0xfde5380c, 23)<br>
+    STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)<br>
+    STEP(H, d, a, b, c, GET(4), 0x4bdecfa9, 11)<br>
+    STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)<br>
+    STEP(H, b, c, d, a, GET(10), 0xbebfbc70, 23)<br>
+    STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)<br>
+    STEP(H, d, a, b, c, GET(0), 0xeaa127fa, 11)<br>
+    STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)<br>
+    STEP(H, b, c, d, a, GET(6), 0x04881d05, 23)<br>
+    STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)<br>
+    STEP(H, d, a, b, c, GET(12), 0xe6db99e5, 11)<br>
+    STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)<br>
+    STEP(H, b, c, d, a, GET(2), 0xc4ac5665, 23)<br>
+<br>
+    // Round 4<br>
+    STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)<br>
+    STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)<br>
+    STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)<br>
+    STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)<br>
+    STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)<br>
+    STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)<br>
+    STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)<br>
+    STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)<br>
+    STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)<br>
+    STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)<br>
+    STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)<br>
+    STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)<br>
+    STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)<br>
+    STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)<br>
+    STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)<br>
+    STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)<br>
+<br>
+    a += saved_a;<br>
+    b += saved_b;<br>
+    c += saved_c;<br>
+    d += saved_d;<br>
+<br>
+    ptr += 64;<br>
+  } while (size -= 64);<br>
+<br>
+  this->a = a;<br>
+  this->b = b;<br>
+  this->c = c;<br>
+  this->d = d;<br>
+<br>
+  return ptr;<br>
+}<br>
+<br>
+MD5::MD5()<br>
+    : a(0x67452301), b(0xefcdab89), c(0x98badcfe), d(0x10325476), hi(0), lo(0) {<br>
+}<br>
+<br>
+/// Incrementally add \p size of \p data to the hash.<br>
+void MD5::Update(void *data, unsigned long size) {<br>
+  MD5_u32plus saved_lo;<br>
+  unsigned long used, free;<br>
+<br>
+  saved_lo = lo;<br>
+  if ((lo = (saved_lo + size) & 0x1fffffff) < saved_lo)<br>
+    hi++;<br>
+  hi += size >> 29;<br>
+<br>
+  used = saved_lo & 0x3f;<br>
+<br>
+  if (used) {<br>
+    free = 64 - used;<br>
+<br>
+    if (size < free) {<br>
+      memcpy(&buffer[used], data, size);<br>
+      return;<br>
+    }<br>
+<br>
+    memcpy(&buffer[used], data, free);<br>
+    data = (unsigned char *)data + free;<br>
+    size -= free;<br>
+    body(buffer, 64);<br>
+  }<br>
+<br>
+  if (size >= 64) {<br>
+    data = body(data, size & ~(unsigned long) 0x3f);<br>
+    size &= 0x3f;<br>
+  }<br>
+<br>
+  memcpy(buffer, data, size);<br>
+}<br>
+<br>
+/// \brief Finish the hash and place the resulting hash into \p result.<br>
+/// \param result is assumed to be a minimum of 16-bytes in size.<br>
+void MD5::Final(unsigned char *result) {<br>
+  unsigned long used, free;<br>
+<br>
+  used = lo & 0x3f;<br>
+<br>
+  buffer[used++] = 0x80;<br>
+<br>
+  free = 64 - used;<br>
+<br>
+  if (free < 8) {<br>
+    memset(&buffer[used], 0, free);<br>
+    body(buffer, 64);<br>
+    used = 0;<br>
+    free = 64;<br>
+  }<br>
+<br>
+  memset(&buffer[used], 0, free - 8);<br>
+<br>
+  lo <<= 3;<br>
+  buffer[56] = lo;<br>
+  buffer[57] = lo >> 8;<br>
+  buffer[58] = lo >> 16;<br>
+  buffer[59] = lo >> 24;<br>
+  buffer[60] = hi;<br>
+  buffer[61] = hi >> 8;<br>
+  buffer[62] = hi >> 16;<br>
+  buffer[63] = hi >> 24;<br>
+<br>
+  body(buffer, 64);<br>
+<br>
+  result[0] = a;<br>
+  result[1] = a >> 8;<br>
+  result[2] = a >> 16;<br>
+  result[3] = a >> 24;<br>
+  result[4] = b;<br>
+  result[5] = b >> 8;<br>
+  result[6] = b >> 16;<br>
+  result[7] = b >> 24;<br>
+  result[8] = c;<br>
+  result[9] = c >> 8;<br>
+  result[10] = c >> 16;<br>
+  result[11] = c >> 24;<br>
+  result[12] = d;<br>
+  result[13] = d >> 8;<br>
+  result[14] = d >> 16;<br>
+  result[15] = d >> 24;<br>
+}<br>
+<br>
+}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br>