You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2014/08/01 16:26:37 UTC

[1/2] TS-2964: Make URL hash run time selectable.

Repository: trafficserver
Updated Branches:
  refs/heads/master 426879358 -> 2ac12c4a2


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/lib/ts/INK_MD5.h
----------------------------------------------------------------------
diff --git a/lib/ts/INK_MD5.h b/lib/ts/INK_MD5.h
index 37585eb..d5d4e91 100644
--- a/lib/ts/INK_MD5.h
+++ b/lib/ts/INK_MD5.h
@@ -26,132 +26,19 @@
 
 #include "ink_code.h"
 #include "ink_defs.h"
-
-struct INK_MD5
-{
-
-  // This union is needed to fix strict-aliasing warnings.
-  // It is anonymous so that the 'b' member can remain in
-  // the top level scope of the struct. This is because
-  // other code touches that directly. Once that code is
-  // also fixed we can make this an Alias64 type from
-  // ink_align.h
-  union
-  {
-    uint64_t b[2];   // Legacy placeholder
-    uint64_t u64[2];
-    uint32_t u32[4];
-    uint8_t  u8[16];
-  };
-
-  const INK_MD5 & operator =(const INK_MD5 & md5)
-  {
-    u64[0] = md5.u64[0];
-    u64[1] = md5.u64[1];
-    return *this;
-  }
-  uint32_t word(int i)
-  {
-    return u32[i];
-  }
-  unsigned char byte(int i)
-  {
-    return u8[i];
-  }
-  INK_MD5 & loadFromBuffer(char const* md5_buf) {
-    memcpy((void *) u8, (void *) md5_buf, 16);
-    return (*this);
-  }
-  INK_MD5 & storeToBuffer(char const* md5_buf) {
-    memcpy((void *) md5_buf, (void *) u8, 16);
-    return (*this);
-  }
-  INK_MD5 & operator =(char const* md5) {
-    return (loadFromBuffer(md5));
-  }
-  INK_MD5 & operator =(unsigned char const* md5) {
-    return (loadFromBuffer((char *) md5));
-  }
-
-  char *toStr(char *md5_str)
-  {
-    return (char *) memcpy((void *) md5_str, (void *) u8, 16);
-  }
-  void encodeBuffer(unsigned char const* buffer, int len)
-  {
-    ink_code_md5(buffer, len, u8);
-  }
-  void encodeBuffer(const char *buffer, int len)
-  {
-    encodeBuffer(reinterpret_cast<unsigned char const*>(buffer), len);
-  }
-  char *str()
-  {
-    return ((char *) u8);
-  }
-  char *toHexStr(char hex_md5[33])
-  {
-    return (ink_code_md5_stringify_fast(hex_md5, str()));
-  }
-  void set(INK_MD5 & md5)
-  {
-    loadFromBuffer((char *) md5.u8);
-  }
-  void set(INK_MD5 * md5)
-  {
-    loadFromBuffer((char *) md5->u8);
-  }
-  void set(char *p)
-  {
-    loadFromBuffer(p);
-  }
-  void set(uint64_t a1, uint64_t a2)
-  {
-    u64[0] = a1;
-    u64[1] = a2;
-  }
-  char *string(char buf[33])
-  {
-    char hex_digits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
-    int i, j;
-
-    for (i = 0, j = 0; i < 16; i += 1, j += 2) {
-      buf[j + 0] = hex_digits[u8[i] >> 4];
-      buf[j + 1] = hex_digits[u8[i] & 0xF];
-    }
-    buf[32] = '\0';
-    return buf;
-  }
-
-  uint64_t fold() const
-  {
-    return (u64[0] ^ u64[1]);
-  }
-
-  uint64_t operator[] (int i) const
-  {
-    return u64[i];
-  }
-  bool operator==(INK_MD5 const& md5) const
-  {
-    return u64[0] == md5.u64[0] && u64[1] == md5.u64[1];
-  }
-  bool operator != (INK_MD5 const& that) const
-  {
-    return !(*this == that);
-  }
-
-  INK_MD5() {
-    u64[0] = 0;
-    u64[1] = 0;
-  }
-  INK_MD5(uint64_t a1, uint64_t a2) {
-    u64[0] = a1;
-    u64[1] = a2;
-  }
-
-  /// Static default constructed instance.
-  static INK_MD5 const ZERO;
+#include "CryptoHash.h"
+
+class MD5Context : public CryptoContext {
+protected:
+  MD5_CTX _ctx;
+public:
+  MD5Context();
+  /// Update the hash with @a data of @a length bytes.
+  virtual bool update(void const* data, int length);
+  /// Finalize and extract the @a hash.
+  virtual bool finalize(CryptoHash& hash);
 };
 
+typedef CryptoHash INK_MD5;
+
 #endif

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/lib/ts/MMH.cc
----------------------------------------------------------------------
diff --git a/lib/ts/MMH.cc b/lib/ts/MMH.cc
new file mode 100644
index 0000000..66d5c48
--- /dev/null
+++ b/lib/ts/MMH.cc
@@ -0,0 +1,588 @@
+/** @file
+
+  A brief file description
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include "ink_assert.h"
+#include "ink_platform.h"
+#include "MMH.h"
+
+#define MMH_X_SIZE	512
+
+/* BUG: INKqa11504: need it be to 64 bits...otherwise it overflows */
+static uint64_t MMH_x[MMH_X_SIZE + 8] = {
+  0x3ee18b32, 0x746d0d6b, 0x591be6a3, 0x760bd17f,
+  0x363c765d, 0x4bf3d5c5, 0x10f0510a, 0x39a84605,
+  0x2282b48f, 0x6903652e, 0x1b491170, 0x1ab8407a,
+  0x776b8aa8, 0x5b126ffe, 0x5095db1a, 0x565fe90c,
+  0x3ae1f068, 0x73fdf0cb, 0x72f39a81, 0x6a40a4a3,
+  0x4ef557fe, 0x360c1a2c, 0x4579b0ea, 0x61dfd174,
+  0x269b242f, 0x752d6298, 0x15f10fa3, 0x618b7ab3,
+  0x6699171f, 0x488f2c6c, 0x790f8cdb, 0x5ed15565,
+  0x04eba3c0, 0x5009ac0b, 0x3a5d6c1f, 0x1a4f7853,
+  0x1affabd4, 0x74aace1f, 0x2310b46d, 0x466b611a,
+  0x18c5d4a0, 0x7eb9fffe, 0x76098df6, 0x4172f860,
+  0x689e3c2f, 0x722cdc29, 0x64548175, 0x28f46721,
+  0x58fdf93f, 0x12c2dcee, 0x58cb1327, 0x02d4af27,
+  0x4d1c6fcd, 0x72fe572d, 0x7038d366, 0x0bfa1898,
+  0x788d2438, 0x1f131f37, 0x25729ee6, 0x635ea6a9,
+  0x3b0b5714, 0x6ac759d2, 0x5faf688a, 0x0c2fe571,
+  0x7487538e, 0x65491b59, 0x60cd86e4, 0x5d6482d8,
+  0x4a59fa77, 0x78439700, 0x56a51f48, 0x360544ae,
+  0x6c01b3ef, 0x2228c036, 0x15b7e88b, 0x326e0dd8,
+  0x509491af, 0x72d06023, 0x26181f5d, 0x7924c4a4,
+  0x70c60bf2, 0x7b5bc151, 0x28e42640, 0x48af0c3e,
+  0x009b6301, 0x06dd3366, 0x2ad1eb24, 0x102ce33c,
+  0x1e504f5a, 0x5ab4c90f, 0x669ccca1, 0x118d5954,
+  0x1a1e4a7c, 0x1807d1f9, 0x525a58d0, 0x2f13ae2d,
+  0x17335a52, 0x714eb2f9, 0x1865dfc7, 0x61b64b52,
+  0x0dc9e939, 0x4fccde4c, 0x6d5873af, 0x47c62b43,
+  0x0fa1d4b0, 0x2f00cdf8, 0x68029083, 0x52645fa6,
+  0x4bb37c9b, 0x53d60251, 0x48364566, 0x35b4889b,
+  0x46783d34, 0x30c12697, 0x210459a1, 0x36962f2d,
+  0x36305d8f, 0x170e9dbd, 0x687c8739, 0x261c14e4,
+  0x3cc51cc7, 0x02add945, 0x01a88529, 0x6617aa77,
+  0x6be627ca, 0x14c7fc46, 0x46fb3b41, 0x1bffff9e,
+  0x1e6c61be, 0x10966c8f, 0x3f69199b, 0x1b5e9e06,
+  0x4880890f, 0x055613e6, 0x6c742db5, 0x7be1e15e,
+  0x2522e317, 0x41fe3369, 0x2b462f30, 0x605b7e8e,
+  0x1c19b868, 0x3fadcb16, 0x781c5e24, 0x1c6b0c08,
+  0x499f0bb9, 0x04b0b766, 0x7d6cad1e, 0x097f7d36,
+  0x2e02956a, 0x03adc713, 0x4ce950b7, 0x6e57a313,
+  0x557badb5, 0x73212afb, 0x3f7f6ed2, 0x0558e3d6,
+  0x28376f73, 0x54dac21d, 0x6c3f4771, 0x67147bc8,
+  0x5ae9fd88, 0x51ede3c0, 0x1067d134, 0x5246b937,
+  0x056e74ed, 0x5d7869b2, 0x62356370, 0x76a0c583,
+  0x3defb558, 0x5200dcae, 0x1432a7e8, 0x3ae4ad55,
+  0x0c4cca8a, 0x0607c4d7, 0x1944ae2b, 0x726479f0,
+  0x558e6035, 0x5ae64061, 0x4e1e9a8a, 0x0cf04d9f,
+  0x46ef4a87, 0x0554224f, 0x70d70ab3, 0x03cc954e,
+  0x39d0cd57, 0x1b11fb56, 0x62a0e9ee, 0x55888135,
+  0x3e93ebeb, 0x29578ee1, 0x0bcb0ef4, 0x529e16af,
+  0x165bab64, 0x39ed562e, 0x52c59d67, 0x48c84d29,
+  0x0fd0d1c7, 0x795fd395, 0x79a1c4f3, 0x5010c835,
+  0x4fbe4ba8, 0x49a597e9, 0x29f017ff, 0x59dde0be,
+  0x2c660275, 0x15fcfbf7, 0x1eab540f, 0x38e2cf56,
+  0x74608d5c, 0x7cd4b02c, 0x52a115b9, 0x2bdee9ac,
+  0x5456c6da, 0x63626453, 0x15279241, 0x19b60519,
+  0x508af0e1, 0x2e3ce97b, 0x568710d4, 0x6abb3059,
+  0x7897b1a5, 0x17034ff6, 0x2aef7d5e, 0x5a281657,
+  0x0fa5d304, 0x76f0a37e, 0x31be0f08, 0x46ce7c20,
+  0x563e4e90, 0x31540773, 0x1cdc9c51, 0x10366bfa,
+  0x1b6cd03a, 0x615f1540, 0x18c3d6c8, 0x3cb2bf8e,
+  0x29bf799c, 0x40b87edb, 0x42c34863, 0x1e9edb40,
+  0x64734fe2, 0x3ddf176a, 0x1c458c7f, 0x06138c9f,
+  0x5e695e56, 0x02c98403, 0x0474de75, 0x660e1df8,
+  0x6df73788, 0x3770f68c, 0x758bb7d5, 0x0763d105,
+  0x16e61f16, 0x153974c1, 0x29ded842, 0x1a0d12c3,
+  0x599ec61d, 0x05904d54, 0x79e9b0ea, 0x4976da61,
+  0x5834243c, 0x67c17d2f, 0x65fbcda0, 0x17bdc554,
+  0x465e9741, 0x7a0ee6d5, 0x3b357597, 0x0d1da287,
+  0x01211373, 0x04a05de6, 0x5deb5dbd, 0x6d993eb0,
+  0x2064ce7c, 0x3011a8c1, 0x36ece6b1, 0x4a0963be,
+  0x0cf46ef0, 0x0d53ba44, 0x63260063, 0x187f1d6e,
+  0x7e866a7e, 0x4b6885af, 0x254d6d47, 0x715474fd,
+  0x6896dcb2, 0x7554eea6, 0x2161bf36, 0x5387f5f8,
+  0x5c4bc064, 0x059a7755, 0x7d4307e1, 0x17326e2f,
+  0x5e2315c1, 0x14c26eae, 0x1e5cd6f2, 0x352b7ac8,
+  0x66591ef3, 0x381e80cd, 0x19b3bfc1, 0x3668946f,
+  0x4b6d7d70, 0x20feab7d, 0x1b6340af, 0x356b6cab,
+  0x299099dc, 0x295ab8d4, 0x184c8623, 0x134f8e4c,
+  0x7caf609c, 0x716d81f9, 0x2e04231f, 0x1dd45301,
+  0x43e9fcf9, 0x1c225c06, 0x0994797e, 0x5b3f6006,
+  0x1d22dcec, 0x32993108, 0x3f0c2bcc, 0x4d44fbfa,
+  0x389de78c, 0x7f8be723, 0x5dab92c1, 0x7866afce,
+  0x3bfc7011, 0x4a27d7d3, 0x0c79d05c, 0x268dc4da,
+  0x3fe10f84, 0x1f18394d, 0x20b9ba99, 0x312e520a,
+  0x64cf2f05, 0x322a7c04, 0x4cc077ce, 0x7218aa35,
+  0x550cacb8, 0x5943be47, 0x15b346a8, 0x0d6a1d8e,
+  0x3f08a54d, 0x7a6e9807, 0x274f8bbc, 0x6feb2033,
+  0x64b10c2b, 0x2cbaa0b7, 0x0db7decc, 0x22b807e3,
+  0x10d15c39, 0x6a9b314c, 0x5ff27199, 0x5072b2cd,
+  0x4eaf4b49, 0x5a890464, 0x7df0ca60, 0x548e8983,
+  0x5e3f0a21, 0x70027683, 0x503e6bf2, 0x47ad6e0d,
+  0x77173b26, 0x6dc04878, 0x4d73a573, 0x439b4a1a,
+  0x2e6569a7, 0x1630e5de, 0x1be363af, 0x6f5f0e52,
+  0x5b266bc3, 0x2f2a51be, 0x204e7e14, 0x1b3314c6,
+  0x4472b8f9, 0x4162fb52, 0x72549950, 0x3223f889,
+  0x0e655f4a, 0x65c3dce4, 0x04825988, 0x22b41458,
+  0x53a4e10d, 0x3e2a66d5, 0x29de3e31, 0x0252fa74,
+  0x267fe54f, 0x42d6d8ba, 0x5951218f, 0x73db5791,
+  0x618444e4, 0x79abcaa1, 0x0ddcf5c8, 0x2cbed2e6,
+  0x73159e0e, 0x7aadc871, 0x10e3f9a4, 0x762e9d65,
+  0x2a7138c9, 0x59fe016f, 0x5b6c3ee4, 0x28888205,
+  0x695fa5b1, 0x50f92ddd, 0x07eefc3b, 0x42bb693a,
+  0x71312191, 0x3653ecbd, 0x1d80c4ed, 0x5a536187,
+  0x6a286789, 0x4a1ffbb3, 0x1e976003, 0x5a8c5f29,
+  0x2ac83bdb, 0x5ab9cb08, 0x63039928, 0x5a4c04f4,
+  0x7b329952, 0x40d40fcb, 0x01810524, 0x2555e83c,
+  0x748d0b4f, 0x534f1612, 0x272353f2, 0x6992e1ea,
+  0x33cc5e71, 0x5163b55e, 0x29886a7f, 0x7cfb1eae,
+  0x330271e0, 0x6f05e91c, 0x35b01e02, 0x64bbc053,
+  0x76eb9337, 0x62612f48, 0x044e0af2, 0x1dac022e,
+  0x1ca56f0c, 0x0210ef2c, 0x5af7a1a9, 0x2632f2b0,
+  0x23d0401c, 0x0c594a46, 0x77582293, 0x297df41b,
+  0x4c7b8718, 0x6c48d948, 0x4835e412, 0x74795651,
+  0x28ca3506, 0x4071f739, 0x032fdbf2, 0x097f7bc8,
+  0x44ced256, 0x47f25cb9, 0x43500684, 0x45481b9a,
+  0x5a5ecc82, 0x4fe9ed61, 0x337ee559, 0x556852b9,
+  0x0b24b460, 0x696db949, 0x7a2def9d, 0x4fcd5640,
+  0x1babd707, 0x5c9254a3, 0x44d26e0d, 0x0e26b8e4,
+  0x3b1c3b5c, 0x0078c784, 0x27a7dc96, 0x1d525589,
+  0x4384ae38, 0x447b77c3, 0x78488b8c, 0x5eab10f1,
+  0x16812737, 0x37cc8efa, 0x219cda83, 0x00bcc48f,
+  0x3c667020, 0x492d7eaa, 0x710d06ce, 0x4172c47a,
+  0x358098ec, 0x1fff647b, 0x65672792, 0x1a7b927d,
+  0x24006275, 0x04e630a0, 0x2f2a9185, 0x5873704b,
+  0x0a8c69bc, 0x06b49059, 0x49837c48, 0x4f90a2d0,
+  0x29ad7dd7, 0x3674be92, 0x46d5635f, 0x782758a2,
+  0x721a2a75, 0x13427ca9, 0x20e03cc9, 0x5f884596,
+  0x19dc210f, 0x066c954d, 0x52f43f40, 0x5d9c256f,
+  0x7f0acaae, 0x1e186b81, 0x55e9920f, 0x0e4f77b2,
+  0x6700ec53, 0x268837c0, 0x554ce08b, 0x4284e695,
+  0x2127e806, 0x384cb53b, 0x51076b2f, 0x23f9eb15
+};
+
+// We don't need this generator in release.
+#ifdef TEST
+// generator for above
+static void
+ink_init_MMH()
+{
+  srand48(13);                  // must remain the same!
+  for (int i = 0; i < MMH_X_SIZE; i++)
+    MMH_x[i] = lrand48();
+}
+#endif /* TEST */
+
+
+#ifndef __GNUC__
+// these are short < 16 bytes, help by permitting inlining
+static inline void
+_memcpy(void *dest, const void *src, int nbytes)
+{
+  for (int i = 0; i < nbytes; i++)
+    ((char *) dest)[i] = ((char *) src)[i];
+}
+
+#define memcpy _memcpy
+#endif
+
+int
+ink_code_incr_MMH_init(MMH_CTX * ctx)
+{
+  ctx->buffer_size = 0;
+  ctx->blocks = 0;
+  ctx->state[0] = ((uint64_t) MMH_x[MMH_X_SIZE + 0] << 32) + MMH_x[MMH_X_SIZE + 1];
+  ctx->state[1] = ((uint64_t) MMH_x[MMH_X_SIZE + 2] << 32) + MMH_x[MMH_X_SIZE + 3];
+  ctx->state[2] = ((uint64_t) MMH_x[MMH_X_SIZE + 4] << 32) + MMH_x[MMH_X_SIZE + 5];
+  ctx->state[3] = ((uint64_t) MMH_x[MMH_X_SIZE + 6] << 32) + MMH_x[MMH_X_SIZE + 7];
+  return 0;
+}
+
+int
+ink_code_MMH(unsigned char *input, int len, unsigned char *sixteen_byte_hash)
+{
+  MMH_CTX ctx;
+  ink_code_incr_MMH_init(&ctx);
+  ink_code_incr_MMH_update(&ctx, (const char *) input, len);
+  ink_code_incr_MMH_final(sixteen_byte_hash, &ctx);
+  return 0;
+}
+
+static inline void
+MMH_update(MMH_CTX * ctx, unsigned char *ab)
+{
+  uint32_t *b = (uint32_t *) ab;
+  ctx->state[0] += b[0] * MMH_x[(ctx->blocks + 0) % MMH_X_SIZE];
+  ctx->state[1] += b[1] * MMH_x[(ctx->blocks + 1) % MMH_X_SIZE];
+  ctx->state[2] += b[2] * MMH_x[(ctx->blocks + 2) % MMH_X_SIZE];
+  ctx->state[3] += b[3] * MMH_x[(ctx->blocks + 3) % MMH_X_SIZE];
+  ctx->blocks += 4;
+}
+
+static inline void
+MMH_updateb1(MMH_CTX * ctx, unsigned char *ab)
+{
+  uint32_t *b = (uint32_t *) (ab - 1);
+  uint32_t b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4];
+  b0 = (b0 << 8) + (b1 >> 24);
+  b1 = (b1 << 8) + (b2 >> 24);
+  b2 = (b2 << 8) + (b3 >> 24);
+  b3 = (b3 << 8) + (b4 >> 24);
+  ctx->state[0] += b0 * MMH_x[(ctx->blocks + 0) % MMH_X_SIZE];
+  ctx->state[1] += b1 * MMH_x[(ctx->blocks + 1) % MMH_X_SIZE];
+  ctx->state[2] += b2 * MMH_x[(ctx->blocks + 2) % MMH_X_SIZE];
+  ctx->state[3] += b3 * MMH_x[(ctx->blocks + 3) % MMH_X_SIZE];
+  ctx->blocks += 4;
+}
+
+static inline void
+MMH_updateb2(MMH_CTX * ctx, unsigned char *ab)
+{
+  uint32_t *b = (uint32_t *) (ab - 2);
+  uint32_t b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4];
+  b0 = (b0 << 16) + (b1 >> 16);
+  b1 = (b1 << 16) + (b2 >> 16);
+  b2 = (b2 << 16) + (b3 >> 16);
+  b3 = (b3 << 16) + (b4 >> 16);
+  ctx->state[0] += b0 * MMH_x[(ctx->blocks + 0) % MMH_X_SIZE];
+  ctx->state[1] += b1 * MMH_x[(ctx->blocks + 1) % MMH_X_SIZE];
+  ctx->state[2] += b2 * MMH_x[(ctx->blocks + 2) % MMH_X_SIZE];
+  ctx->state[3] += b3 * MMH_x[(ctx->blocks + 3) % MMH_X_SIZE];
+  ctx->blocks += 4;
+}
+
+static inline void
+MMH_updateb3(MMH_CTX * ctx, unsigned char *ab)
+{
+  uint32_t *b = (uint32_t *) (ab - 3);
+  uint32_t b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4];
+  b0 = (b0 << 24) + (b1 >> 8);
+  b1 = (b1 << 24) + (b2 >> 8);
+  b2 = (b2 << 24) + (b3 >> 8);
+  b3 = (b3 << 24) + (b4 >> 8);
+  ctx->state[0] += b0 * MMH_x[(ctx->blocks + 0) % MMH_X_SIZE];
+  ctx->state[1] += b1 * MMH_x[(ctx->blocks + 1) % MMH_X_SIZE];
+  ctx->state[2] += b2 * MMH_x[(ctx->blocks + 2) % MMH_X_SIZE];
+  ctx->state[3] += b3 * MMH_x[(ctx->blocks + 3) % MMH_X_SIZE];
+  ctx->blocks += 4;
+}
+
+static inline void
+MMH_updatel1(MMH_CTX * ctx, unsigned char *ab)
+{
+  uint32_t *b = (uint32_t *) (ab - 1);
+  uint32_t b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4];
+  b0 = (b0 >> 8) + (b1 << 24);
+  b1 = (b1 >> 8) + (b2 << 24);
+  b2 = (b2 >> 8) + (b3 << 24);
+  b3 = (b3 >> 8) + (b4 << 24);
+  ctx->state[0] += b0 * MMH_x[(ctx->blocks + 0) % MMH_X_SIZE];
+  ctx->state[1] += b1 * MMH_x[(ctx->blocks + 1) % MMH_X_SIZE];
+  ctx->state[2] += b2 * MMH_x[(ctx->blocks + 2) % MMH_X_SIZE];
+  ctx->state[3] += b3 * MMH_x[(ctx->blocks + 3) % MMH_X_SIZE];
+  ctx->blocks += 4;
+}
+
+static inline void
+MMH_updatel2(MMH_CTX * ctx, unsigned char *ab)
+{
+  uint32_t *b = (uint32_t *) (ab - 2);
+  uint32_t b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4];
+  b0 = (b0 >> 16) + (b1 << 16);
+  b1 = (b1 >> 16) + (b2 << 16);
+  b2 = (b2 >> 16) + (b3 << 16);
+  b3 = (b3 >> 16) + (b4 << 16);
+  ctx->state[0] += b0 * MMH_x[(ctx->blocks + 0) % MMH_X_SIZE];
+  ctx->state[1] += b1 * MMH_x[(ctx->blocks + 1) % MMH_X_SIZE];
+  ctx->state[2] += b2 * MMH_x[(ctx->blocks + 2) % MMH_X_SIZE];
+  ctx->state[3] += b3 * MMH_x[(ctx->blocks + 3) % MMH_X_SIZE];
+  ctx->blocks += 4;
+}
+
+static inline void
+MMH_updatel3(MMH_CTX * ctx, unsigned char *ab)
+{
+  uint32_t *b = (uint32_t *) (ab - 3);
+  uint32_t b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4];
+  b0 = (b0 >> 24) + (b1 << 8);
+  b1 = (b1 >> 24) + (b2 << 8);
+  b2 = (b2 >> 24) + (b3 << 8);
+  b3 = (b3 >> 24) + (b4 << 8);
+  ctx->state[0] += b0 * MMH_x[(ctx->blocks + 0) % MMH_X_SIZE];
+  ctx->state[1] += b1 * MMH_x[(ctx->blocks + 1) % MMH_X_SIZE];
+  ctx->state[2] += b2 * MMH_x[(ctx->blocks + 2) % MMH_X_SIZE];
+  ctx->state[3] += b3 * MMH_x[(ctx->blocks + 3) % MMH_X_SIZE];
+  ctx->blocks += 4;
+}
+
+int
+ink_code_incr_MMH_update(MMH_CTX * ctx, const char *ainput, int input_length)
+{
+  unsigned char *in = (unsigned char *) ainput;
+  unsigned char *end = in + input_length;
+  if (ctx->buffer_size) {
+    int l = 16 - ctx->buffer_size;
+    if (input_length >= l) {
+      memcpy(ctx->buffer + ctx->buffer_size, in, l);
+      ctx->buffer_size = 0;
+      in += l;
+      if (ctx->buffer_size & 0x0f)
+        return 0;
+      MMH_update(ctx, ctx->buffer);
+    } else
+      goto Lstore;
+  }
+  {
+    // check alignment
+    int alignment = (int)((intptr_t) in & 0x3);
+    if (alignment) {
+#if defined(_BIG_ENDIAN)
+#define big_endian 1
+#elif defined(_LITTLE_ENDIAN)
+#define big_endian 0
+#else
+      unsigned int endian = 1;
+      int big_endian = !*(char *) &endian;
+#endif
+      if (big_endian) {
+        if (alignment == 1) {
+          while (in + 16 <= end) {
+            MMH_updateb1(ctx, in);
+            in += 16;
+          }
+        } else if (alignment == 2) {
+          while (in + 16 <= end) {
+            MMH_updateb2(ctx, in);
+            in += 16;
+          }
+        } else if (alignment == 3)
+          while (in + 16 <= end) {
+            MMH_updateb3(ctx, in);
+            in += 16;
+          }
+      } else {
+        if (alignment == 1) {
+          while (in + 16 <= end) {
+            MMH_updatel1(ctx, in);
+            in += 16;
+          }
+        } else if (alignment == 2) {
+          while (in + 16 <= end) {
+            MMH_updatel2(ctx, in);
+            in += 16;
+          }
+        } else if (alignment == 3)
+          while (in + 16 <= end) {
+            MMH_updatel3(ctx, in);
+            in += 16;
+          }
+      }
+    } else {
+      while (in + 16 <= end) {
+        MMH_update(ctx, in);
+        in += 16;
+      }
+    }
+  }
+Lstore:
+  if (end - in) {
+    int oldbs = ctx->buffer_size;
+    ctx->buffer_size += (int) (end - in);
+#ifndef TEST
+    ink_assert(ctx->buffer_size < 16);
+#endif
+    memcpy(ctx->buffer + oldbs, in, (int) (end - in));
+  }
+  return 0;
+}
+
+#if defined(__GNUC__)
+#define _memset memset
+#else
+// NOT general purpose
+inline void
+_memset(unsigned char *b, int c, int len)
+{
+  (void) c;
+  int o = len & 0x3, i;
+  for (i = 0; i < o; i++)
+    b[i] = 0;
+  for (i = 0; i < (len - o) / 4; i++)
+    ((uint32_t *) (b + o))[i] = 0;
+}
+#endif
+
+
+int
+ink_code_incr_MMH_final(uint8_t *presult, MMH_CTX * ctx)
+{
+  unsigned int len = ctx->blocks * 4 + ctx->buffer_size;
+  // pad out to 16 bytes
+  if (ctx->buffer_size) {
+    _memset(ctx->buffer + ctx->buffer_size, 0, 16 - ctx->buffer_size);
+    ctx->buffer_size = 0;
+    MMH_update(ctx, ctx->buffer);
+  }
+  // append length (before padding)
+  unsigned int *pbuffer = (unsigned int *) ctx->buffer;
+  pbuffer[1] = pbuffer[2] = pbuffer[3] = pbuffer[0] = len;
+  MMH_update(ctx, ctx->buffer);
+  // final phase
+  uint32_t *b = (uint32_t *) presult;
+  uint64_t d = (((uint64_t) 1) << 32) + 15;
+  uint32_t b0 = uint32_t(ctx->state[0] % d);
+  uint32_t b1 = uint32_t(ctx->state[1] % d);
+  uint32_t b2 = uint32_t(ctx->state[2] % d);
+  uint32_t b3 = uint32_t(ctx->state[3] % d);
+  // scramble the bits, losslessly (reversibly)
+  b[0] = b0;
+  b[1] = b1 ^ (b0 >> 24) ^ (b0 << 8);
+  b[2] = b2 ^ (b1 >> 16) ^ (b1 << 16)
+    ^ (b0 >> 24) ^ (b0 << 8);
+  b[3] = b3 ^ (b1 >> 8) ^ (b1 << 24)
+    ^ (b2 >> 16) ^ (b2 << 16)
+    ^ (b0 >> 24) ^ (b0 << 8);
+
+  b0 = b[0];
+  b1 = b[1];
+  b2 = b[2];
+  b3 = b[3];
+
+  b[2] = b2 ^ (b3 >> 24) ^ (b3 << 8);
+  b[1] = b1 ^ (b2 >> 16) ^ (b2 << 16)
+    ^ (b3 >> 24) ^ (b3 << 8);
+  b[0] = b0 ^ (b3 >> 8) ^ (b3 << 24)
+    ^ (b2 >> 16) ^ (b2 << 16)
+    ^ (b1 >> 24) ^ (b1 << 8);
+  return 0;
+}
+
+MMHContext::MMHContext() {
+  ink_code_incr_MMH_init(&_ctx);
+}
+
+bool
+MMHContext::update(void const* data, int length) {
+  return 0 == ink_code_incr_MMH_update(&_ctx, static_cast<char const*>(data), length);
+}
+
+bool
+MMHContext::finalize(CryptoHash& hash) {
+  return 0 == ink_code_incr_MMH_final(hash.u8, &_ctx);
+}
+
+#ifdef TEST
+
+#define TEST_COLLISIONS 10000000
+
+static int
+xxcompar(uint32_t ** x, uint32_t ** y)
+{
+  for (int i = 0; i < 4; i++) {
+    if (x[i] > y[i])
+      return 1;
+    if (x[i] < y[i])
+      return -1;
+  }
+  return 0;
+}
+
+typedef uint32_t i4_t[4];
+i4_t *xxh;
+double *xf;
+
+main()
+{
+  union
+  {
+    unsigned char hash[16];
+    uint32_t h[4];
+  } h;
+
+  xxh = (i4_t *)ats_malloc(4 * sizeof(uint32_t) * TEST_COLLISIONS);
+  xf = (double *)ats_malloc(sizeof(double) * TEST_COLLISIONS);
+
+  printf("test collisions\n");
+  char *sc1 = "http://npdev:19080/1.6664000000/4000";
+  char *sc2 = "http://npdev:19080/1.8666000000/4000";
+  char *sc3 = "http://:@npdev/1.6664000000/4000;?";
+  char *sc4 = "http://:@npdev/1.8666000000/4000;?";
+  ink_code_MMH((unsigned char *) sc1, strlen(sc1), h.hash);
+  printf("%X %X %X %X\n", h.h[0], h.h[1], h.h[2], h.h[3]);
+  ink_code_MMH((unsigned char *) sc2, strlen(sc2), h.hash);
+  printf("%X %X %X %X\n", h.h[0], h.h[1], h.h[2], h.h[3]);
+  ink_code_MMH((unsigned char *) sc3, strlen(sc3), h.hash);
+  printf("%X %X %X %X\n", h.h[0], h.h[1], h.h[2], h.h[3]);
+  ink_code_MMH((unsigned char *) sc4, strlen(sc4), h.hash);
+  printf("%X %X %X %X\n", h.h[0], h.h[1], h.h[2], h.h[3]);
+
+  srand48(time(NULL));
+  for (int xx = 0; xx < TEST_COLLISIONS; xx++) {
+    char xs[256];
+    xf[xx] = drand48();
+    sprintf(xs, "http://@npdev/%16.14f/4000;?", xf[xx]);
+    ink_code_MMH((unsigned char *) xs, strlen(xs), (unsigned char *) &xxh[xx]);
+  }
+  qsort(xxh, TEST_COLLISIONS, 16, xxcompar);
+  for (int xy = 0; xy < TEST_COLLISIONS - 1; xy++) {
+    if (xxh[xy][0] == xxh[xy + 1][0] &&
+        xxh[xy][1] == xxh[xy + 1][1] && xxh[xy][2] == xxh[xy + 1][2] && xxh[xy][3] == xxh[xy + 1][3])
+      printf("********** collision %d\n", xy);
+  }
+
+  unsigned char *s = (unsigned char *) MMH_x;
+  int l = sizeof(MMH_x);
+  unsigned char *s1 = (unsigned char *)ats_malloc(l + 3);
+  s1 += 1;
+  memcpy(s1, s, l);
+  unsigned char *s2 = (unsigned char *)ats_malloc(l + 3);
+  s2 += 2;
+  memcpy(s2, s, l);
+  unsigned char *s3 = (unsigned char *)ats_malloc(l + 3);
+  s3 += 3;
+  memcpy(s3, s, l);
+
+  printf("test alignment\n");
+  ink_code_MMH(s, l, h.hash);
+  printf("%X %X %X %X\n", h.h[0], h.h[1], h.h[2], h.h[3]);
+  ink_code_MMH(s1, l, h.hash);
+  printf("%X %X %X %X\n", h.h[0], h.h[1], h.h[2], h.h[3]);
+  ink_code_MMH(s2, l, h.hash);
+  printf("%X %X %X %X\n", h.h[0], h.h[1], h.h[2], h.h[3]);
+  ink_code_MMH(s3, l, h.hash);
+  printf("%X %X %X %X\n", h.h[0], h.h[1], h.h[2], h.h[3]);
+
+  int i = 0;
+  MMH_CTX c;
+  unsigned char *t = s;
+  printf("test chunking\n");
+  ink_code_incr_MMH_init(&c);
+  for (i = 0; i < 24; i++) {
+    ink_code_incr_MMH_update(&c, (char *) t, i);
+    t += i;
+  }
+  ink_code_incr_MMH_final((char *) h.hash, &c);
+  printf("%X %X %X %X\n", h.h[0], h.h[1], h.h[2], h.h[3]);
+  int q = t - s;
+  ink_code_MMH(s, q, h.hash);
+  printf("%X %X %X %X\n", h.h[0], h.h[1], h.h[2], h.h[3]);
+
+  FILE *fp = fopen("/kernel/genunix", "r");
+  char x[4096];
+  int hist[256];
+  memset(hist, 0, sizeof(hist));
+  size_t xx;
+  while (((xx = fread(x, 1, 128, fp)) == 128)) {
+    ink_code_MMH((unsigned char *) x, 128, h.hash);
+    hist[h.h[0] & 255]++;
+  }
+  for (int z = 0; z < 256; z++) {
+    printf("%6d ", hist[z]);
+    if (!(z % 7))
+      printf("\n");
+  }
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/lib/ts/MMH.h
----------------------------------------------------------------------
diff --git a/lib/ts/MMH.h b/lib/ts/MMH.h
new file mode 100644
index 0000000..74f2c3c
--- /dev/null
+++ b/lib/ts/MMH.h
@@ -0,0 +1,119 @@
+/** @file
+
+  A brief file description
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#ifndef _MMH_h_
+#define	_MMH_h_
+
+#include "ink_code.h"
+#include "ink_defs.h"
+#include "CryptoHash.h"
+
+struct MMH_CTX
+{
+  uint64_t state[4];
+  unsigned char buffer[32];
+  int buffer_size;
+  int blocks;
+};
+
+// signed-unsigned-const gratuitous differences brought
+// to you by history and the ANSI committee
+
+int inkcoreapi ink_code_incr_MMH_init(MMH_CTX * context);
+int inkcoreapi ink_code_incr_MMH_update(MMH_CTX * context, const char *input, int input_length);
+int inkcoreapi ink_code_incr_MMH_final(uint8_t *sixteen_byte_hash_pointer, MMH_CTX * context);
+int inkcoreapi ink_code_MMH(unsigned char *input, int len, unsigned char *sixteen_byte_hash);
+
+/**
+  MMH will return different values on big-endian and little-endian
+  machines. It can be adapted to return the same values at some additional
+  cost.
+
+*/
+class MMHContext : public CryptoContext
+{
+protected:
+  MMH_CTX _ctx;
+public:
+  MMHContext();
+  /// Update the hash with @a data of @a length bytes.
+  virtual bool update(void const* data, int length);
+  /// Finalize and extract the @a hash.
+  virtual bool finalize(CryptoHash& hash);
+# if 0
+  MMH & loadFromBuffer(char *MMH_buf)
+  {
+    int i;
+    char *s, *d;
+
+    for (i = 0, s = MMH_buf, d = (char *) (&(b[0])); i < 8; i++, *d++ = *s++);
+    for (i = 0, d = (char *) (&(b[1])); i < 8; i++, *d++ = *s++);
+    return *this;
+  }
+  MMH & storeToBuffer(char *MMH_buf) {
+    int i;
+    char *s, *d;
+
+    for (i = 0, d = MMH_buf, s = (char *) (&(b[0])); i < 8; i++, *d++ = *s++);
+    for (i = 0, s = (char *) (&(b[1])); i < 8; i++, *d++ = *s++);
+    return *this;
+  }
+  MMH & operator =(char *MMH) {
+    return loadFromBuffer(MMH);
+  }
+  MMH & operator =(unsigned char *MMH) {
+    return loadFromBuffer(reinterpret_cast<char *>(MMH));
+  }
+
+  char *toStr(char *MMH_str) const
+  {
+    int i;
+    char *s, *d;
+
+    for (i = 0, d = MMH_str, s = (char *) (&(b[0])); i < 8; i++, *d++ = *s++);
+    for (i = 0, s = (char *) (&(b[1])); i < 8; i++, *d++ = *s++);
+
+    return MMH_str;
+  }
+  void encodeBuffer(unsigned char *buffer, int len)
+  {
+    unsigned char MMH[16];
+    ink_code_MMH(buffer, len, MMH);
+    *this = MMH;
+  }
+  void encodeBuffer(char *buffer, int len)
+  {
+    encodeBuffer((unsigned char *) buffer, len);
+  }
+  char *str()
+  {
+    return reinterpret_cast<char *>(b);
+  }
+  char *toHexStr(char hex_MMH[33])
+  {
+    return ink_code_md5_stringify_fast(hex_MMH, str());
+  }
+# endif
+};
+
+#endif

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/lib/ts/Makefile.am
----------------------------------------------------------------------
diff --git a/lib/ts/Makefile.am b/lib/ts/Makefile.am
index 73b04ad..437d654 100644
--- a/lib/ts/Makefile.am
+++ b/lib/ts/Makefile.am
@@ -46,6 +46,7 @@ libtsutil_la_SOURCES = \
   Bitops.cc \
   Bitops.h \
   Compatability.h \
+  Cryptohash.h \
   Diags.cc \
   Diags.h \
   DynArray.h \
@@ -70,6 +71,8 @@ libtsutil_la_SOURCES = \
   MatcherUtils.h \
   MimeTable.cc \
   MimeTable.h \
+  MMH.h \
+  MMH.cc \
   ParseRules.cc \
   ParseRules.h \
   Ptr.h \

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/lib/ts/ink_code.cc
----------------------------------------------------------------------
diff --git a/lib/ts/ink_code.cc b/lib/ts/ink_code.cc
index f3a403f..9d17a44 100644
--- a/lib/ts/ink_code.cc
+++ b/lib/ts/ink_code.cc
@@ -26,8 +26,23 @@
 #include "ink_code.h"
 #include "INK_MD5.h"
 #include "ink_assert.h"
+#include "INK_MD5.h"
+
+ats::CryptoHash const ats::CRYPTO_HASH_ZERO; // default constructed is correct.
+
+MD5Context::MD5Context() {
+  MD5_Init(&_ctx);
+}
 
-INK_MD5 const INK_MD5::ZERO; // default constructed is correct.
+bool
+MD5Context::update(void const* data, int length) {
+  return 0 != MD5_Update(&_ctx, data, length);
+}
+
+bool
+MD5Context::finalize(CryptoHash& hash) {
+  return 0 != MD5_Final(hash.u8, &_ctx);
+}
 
 /**
   @brief Wrapper around MD5_Init
@@ -111,7 +126,7 @@ ink_code_md5_stringify(char *dest33, const size_t destSize, const char *md5)
 */
 /* reentrant version */
 char *
-ink_code_md5_stringify_fast(char *dest33, const char *md5)
+ink_code_to_hex_str(char *dest33, uint8_t const* hash)
 {
   int i;
   char *d;
@@ -120,17 +135,17 @@ ink_code_md5_stringify_fast(char *dest33, const char *md5)
 
   d = dest33;
   for (i = 0; i < 16; i += 4) {
-    *(d + 0) = hex_digits[((unsigned char) md5[i + 0]) >> 4];
-    *(d + 1) = hex_digits[((unsigned char) md5[i + 0]) & 15];
-    *(d + 2) = hex_digits[((unsigned char) md5[i + 1]) >> 4];
-    *(d + 3) = hex_digits[((unsigned char) md5[i + 1]) & 15];
-    *(d + 4) = hex_digits[((unsigned char) md5[i + 2]) >> 4];
-    *(d + 5) = hex_digits[((unsigned char) md5[i + 2]) & 15];
-    *(d + 6) = hex_digits[((unsigned char) md5[i + 3]) >> 4];
-    *(d + 7) = hex_digits[((unsigned char) md5[i + 3]) & 15];
+    *(d + 0) = hex_digits[hash[i + 0] >> 4];
+    *(d + 1) = hex_digits[hash[i + 0] & 15];
+    *(d + 2) = hex_digits[hash[i + 1] >> 4];
+    *(d + 3) = hex_digits[hash[i + 1] & 15];
+    *(d + 4) = hex_digits[hash[i + 2] >> 4];
+    *(d + 5) = hex_digits[hash[i + 2] & 15];
+    *(d + 6) = hex_digits[hash[i + 3] >> 4];
+    *(d + 7) = hex_digits[hash[i + 3] & 15];
     d += 8;
   }
   *d = '\0';
   return (dest33);
-}                               /* End ink_code_stringify_md5_fast */
+}
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/lib/ts/ink_code.h
----------------------------------------------------------------------
diff --git a/lib/ts/ink_code.h b/lib/ts/ink_code.h
index 70bc830..ee492f6 100644
--- a/lib/ts/ink_code.h
+++ b/lib/ts/ink_code.h
@@ -26,6 +26,7 @@
 
 #include "ink_apidefs.h"
 #include <openssl/md5.h>
+#include "ink_defs.h"
 
 /* INK_MD5 context. */
 typedef MD5_CTX INK_DIGEST_CTX;
@@ -36,7 +37,7 @@ typedef MD5_CTX INK_DIGEST_CTX;
 
 inkcoreapi int ink_code_md5(unsigned char const* input, int input_length, unsigned char *sixteen_byte_hash_pointer);
 inkcoreapi char *ink_code_md5_stringify(char *dest33, const size_t destSize, const char *md5);
-inkcoreapi char *ink_code_md5_stringify_fast(char *dest33, const char *md5);
+inkcoreapi char *ink_code_to_hex_str(char *dest33, uint8_t const* md5);
 
 inkcoreapi int ink_code_incr_md5_init(INK_DIGEST_CTX * context);
 inkcoreapi int ink_code_incr_md5_update(INK_DIGEST_CTX * context, const char *input, int input_length);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/lib/ts/libts.h
----------------------------------------------------------------------
diff --git a/lib/ts/libts.h b/lib/ts/libts.h
index aa19d40..97ce163 100644
--- a/lib/ts/libts.h
+++ b/lib/ts/libts.h
@@ -85,6 +85,7 @@
 #include "InkPool.h"
 #include "List.h"
 #include "INK_MD5.h"
+#include "MMH.h"
 #include "Map.h"
 #include "MimeTable.h"
 #include "ParseRules.h"

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/proxy/InkAPI.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index abc652f..157df6f 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -3914,11 +3914,12 @@ TSCacheKeyDigestSet(TSCacheKey key, const char *input, int length)
   sdk_assert(sdk_sanity_check_cachekey(key) == TS_SUCCESS);
   sdk_assert(sdk_sanity_check_iocore_structure((void*) input) == TS_SUCCESS);
   sdk_assert(length > 0);
-
-  if (((CacheInfo *) key)->magic != CACHE_INFO_MAGIC_ALIVE)
+  CacheInfo* ci = reinterpret_cast<CacheInfo*>(key);
+  
+  if (ci->magic != CACHE_INFO_MAGIC_ALIVE)
     return TS_ERROR;
 
-  ((CacheInfo *) key)->cache_key.encodeBuffer((char *) input, length);
+  MD5Context().hash_immediate(ci->cache_key, input, length);
   return TS_SUCCESS;
 }
 
@@ -4890,8 +4891,8 @@ TSHttpTxnNewCacheLookupDo(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc url_loc)
     s->cache_info.lookup_url = &(s->cache_info.lookup_url_storage);
     l_url = s->cache_info.lookup_url;
   } else {
-    l_url->MD5_get(&md51);
-    new_url.MD5_get(&md52);
+    l_url->hash_get(&md51);
+    new_url.hash_get(&md52);
     if (md51 == md52)
       return TS_ERROR;
     o_url = &(s->cache_info.original_url);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/proxy/Prefetch.cc
----------------------------------------------------------------------
diff --git a/proxy/Prefetch.cc b/proxy/Prefetch.cc
index 9f49f19..213c200 100644
--- a/proxy/Prefetch.cc
+++ b/proxy/Prefetch.cc
@@ -636,9 +636,9 @@ PrefetchTransform::hash_add(char *s)
     Debug("PrefetchParserURLs", "Normalized URL: %s\n", s);
 
 
-  INK_MD5 md5;
-  md5.encodeBuffer(s, str_len);
-  index = md5.word(1) % HASH_TABLE_LENGTH;
+  INK_MD5 hash;
+  MD5Context().hash_immediate(hash, s, str_len);
+  index = hash.slice32(1) % HASH_TABLE_LENGTH;
 
   PrefetchUrlEntry **e = &hash_table[index];
   for (; *e; e = &(*e)->hash_link)
@@ -646,7 +646,7 @@ PrefetchTransform::hash_add(char *s)
       return NULL;
 
   *e = prefetchUrlEntryAllocator.alloc();
-  (*e)->init(ats_strdup(s), md5);
+  (*e)->init(ats_strdup(s), hash);
 
   return *e;
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/proxy/Update.cc
----------------------------------------------------------------------
diff --git a/proxy/Update.cc b/proxy/Update.cc
index 6481a49..1b1f75b 100644
--- a/proxy/Update.cc
+++ b/proxy/Update.cc
@@ -1674,8 +1674,7 @@ RecursiveHttpGet::RecursiveHttpGetEvent(int event, Event * d)
           }
           // I think we're generating the cache key just to get a hash of the URL.
           // Used to use Cache::generate_key that no longer works with vary_on_user_agent
-          // isn't turned on. ToDo.
-          ue->_URLhandle.MD5_get(&ue->_url_md5);
+          ue->_URLhandle.hash_get(&ue->_url_md5);
 
           if (_CL->HashAdd(ue)) {
             // Entry already exists

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/proxy/hdrs/URL.cc
----------------------------------------------------------------------
diff --git a/proxy/hdrs/URL.cc b/proxy/hdrs/URL.cc
index 732e018..7a34106 100644
--- a/proxy/hdrs/URL.cc
+++ b/proxy/hdrs/URL.cc
@@ -22,6 +22,7 @@
  */
 
 #include <assert.h>
+#include <new>
 #include "libts.h"
 #include "URL.h"
 #include "MIME.h"
@@ -96,6 +97,20 @@ int url_hash_method = 0;
 
 /*-------------------------------------------------------------------------
   -------------------------------------------------------------------------*/
+URLHashContext::HashType URLHashContext::Setting = URLHashContext::MMH;
+
+URLHashContext::URLHashContext() {
+  switch (Setting) {
+  case UNSPECIFIED:
+  case MD5:
+    _ctx = new(_obj) MD5Context;
+    break;
+  case MMH:
+    _ctx = new(_obj) MMHContext;
+    break;
+  default: ink_assert("Invalid global URL hash context");
+  };
+}
 
 void
 url_init()
@@ -191,6 +206,10 @@ url_init()
     URL_LEN_MMS = hdrtoken_wks_to_length(URL_SCHEME_MMS);
     URL_LEN_MMSU = hdrtoken_wks_to_length(URL_SCHEME_MMSU);
     URL_LEN_MMST = hdrtoken_wks_to_length(URL_SCHEME_MMST);
+
+    ink_assert(URLHashContext::OBJ_SIZE >= sizeof(MD5Context));
+    ink_assert(URLHashContext::OBJ_SIZE >= sizeof(MMHContext));
+
   }
 }
 
@@ -1581,14 +1600,11 @@ memcpy_tolower(char *d, const char *s, int n)
 // no buffer overflow, no unescaping needed
 
 static inline void
-url_MD5_get_fast(URLImpl * url, INK_MD5 * md5)
+url_MD5_get_fast(URLImpl * url, CryptoContext& ctx, CryptoHash* hash)
 {
-  INK_DIGEST_CTX md5_ctx;
   char buffer[BUFSIZE];
   char *p;
 
-  ink_code_incr_md5_init(&md5_ctx);
-
   p = buffer;
   memcpy_tolower(p, url->m_ptr_scheme, url->m_len_scheme);
   p += url->m_len_scheme;
@@ -1614,21 +1630,19 @@ url_MD5_get_fast(URLImpl * url, INK_MD5 * md5)
   *p++ = ((char *) &port)[0];
   *p++ = ((char *) &port)[1];
 
-  ink_code_incr_md5_update(&md5_ctx, buffer, p - buffer);
-  ink_code_incr_md5_final((char *) md5, &md5_ctx);
+  ctx.update(buffer, p - buffer);
+  ctx.finalize(hash);
 }
 
 
 static inline void
-url_MD5_get_general(URLImpl * url, INK_MD5 * md5)
+url_MD5_get_general(URLImpl * url, CryptoContext& ctx, CryptoHash& hash)
 {
-  INK_DIGEST_CTX md5_ctx;
-
   char buffer[BUFSIZE];
   char *p, *e;
   const char *strs[13], *ends[13];
   const char *t;
-  uint16_t port;
+  in_port_t port;
   int i, s;
 
   strs[0] = url->m_ptr_scheme;
@@ -1663,8 +1677,6 @@ url_MD5_get_general(URLImpl * url, INK_MD5 * md5)
   p = buffer;
   e = buffer + BUFSIZE;
 
-  ink_code_incr_md5_init(&md5_ctx);
-
   for (i = 0; i < 13; i++) {
     if (strs[i]) {
       t = strs[i];
@@ -1678,29 +1690,26 @@ url_MD5_get_general(URLImpl * url, INK_MD5 * md5)
         }
 
         if (p == e) {
-	  ink_code_incr_md5_update(&md5_ctx, buffer, BUFSIZE);
+          ctx.update(buffer, BUFSIZE);
           p = buffer;
         }
       }
     }
   }
 
-  if (p != buffer) {
-    ink_code_incr_md5_update(&md5_ctx, buffer, p - buffer);
-  }
+  if (p != buffer) ctx.update(buffer, p-buffer);
 
   port = url_canonicalize_port(url->m_url_type, url->m_port);
 
-  ink_code_incr_md5_update(&md5_ctx, (char *) &port, sizeof(port));
-  ink_code_incr_md5_final((char *) md5, &md5_ctx);
+  ctx.update(&port, sizeof(port));
+  ctx.finalize(hash);
+  Debug("amc", "hash 0x%" PRIx64 ":%" PRIx64, hash[0], hash[1]);
 }
 
-
-
-
 void
-url_MD5_get(URLImpl * url, INK_MD5 * md5)
+url_MD5_get(URLImpl * url, CryptoHash* hash)
 {
+  URLHashContext ctx;
   if ((url_hash_method != 0) &&
       (url->m_url_type == URL_TYPE_HTTP) &&
       ((url->m_len_user + url->m_len_password + url->m_len_params + url->m_len_query) == 0) &&
@@ -1710,15 +1719,14 @@ url_MD5_get(URLImpl * url, INK_MD5 * md5)
        url->m_len_path < BUFSIZE) &&
       (memchr(url->m_ptr_host, '%', url->m_len_host) == NULL) &&
       (memchr(url->m_ptr_path, '%', url->m_len_path) == NULL)) {
-    url_MD5_get_fast(url, md5);
-
+    url_MD5_get_fast(url, ctx, hash);
 #ifdef DEBUG
-    INK_MD5 md5_general;
-    url_MD5_get_general(url, &md5_general);
-    ink_assert(*md5 == md5_general);
+    CryptoHash md5_general;
+    url_MD5_get_general(url, ctx, md5_general);
+    ink_assert(*hash == md5_general);
 #endif
   } else {
-    url_MD5_get_general(url, md5);
+    url_MD5_get_general(url, ctx, *hash);
   }
 }
 
@@ -1730,23 +1738,23 @@ url_MD5_get(URLImpl * url, INK_MD5 * md5)
 void
 url_host_MD5_get(URLImpl * url, INK_MD5 * md5)
 {
-  INK_DIGEST_CTX md5_ctx;
-
-  ink_code_incr_md5_init(&md5_ctx);
+  MD5Context ctx;
 
   if (url->m_ptr_scheme) {
-    ink_code_incr_md5_update(&md5_ctx, url->m_ptr_scheme, url->m_len_scheme);
+    ctx.update(url->m_ptr_scheme, url->m_len_scheme);
   }
 
-  ink_code_incr_md5_update(&md5_ctx, "://", 3);
+  ctx.update("://", 3);
 
   if (url->m_ptr_host) {
-    ink_code_incr_md5_update(&md5_ctx, url->m_ptr_host, url->m_len_host);
+    ctx.update(url->m_ptr_host, url->m_len_host);
   }
 
-  ink_code_incr_md5_update(&md5_ctx, ":", 1);
+  ctx.update(":", 1);
 
+  // [amc] Why is this <int> and not <in_port_t>?
+  // Especially since it's in_port_t for url_MD5_get.
   int port = url_canonicalize_port(url->m_url_type, url->m_port);
-  ink_code_incr_md5_update(&md5_ctx, (char *) &port, sizeof(port));
-  ink_code_incr_md5_final((char *) md5, &md5_ctx);
+  ctx.update(&port, sizeof(port));
+  ctx.finalize(*md5);
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/proxy/hdrs/URL.h
----------------------------------------------------------------------
diff --git a/proxy/hdrs/URL.h b/proxy/hdrs/URL.h
index 0a6cd81..5bed604 100644
--- a/proxy/hdrs/URL.h
+++ b/proxy/hdrs/URL.h
@@ -28,6 +28,7 @@
 #include "HdrToken.h"
 #include "HdrHeap.h"
 #include "INK_MD5.h"
+#include "MMH.h"
 #include "MIME.h"
 
 #include "ink_apidefs.h"
@@ -86,6 +87,34 @@ struct URLImpl:public HdrHeapObjImpl
   void check_strings(HeapCheck *heaps, int num_heaps);
 };
 
+/// Crypto Hash context for URLs.
+/// @internal This just forwards on to another specific context but avoids
+/// putting that switch logic in multiple places.
+class URLHashContext : public CryptoContext {
+protected:
+  CryptoContext* _ctx; ///< Generic pointer to use for operations.
+  uint64_t _obj[32]; ///< Raw storage for instantiated context.
+public:
+  URLHashContext();
+  /// Update the hash with @a data of @a length bytes.
+  virtual bool update(void const* data, int length);
+  /// Finalize and extract the @a hash.
+  virtual bool finalize(CryptoHash& hash);
+
+  enum HashType { UNSPECIFIED, MD5, MMH }; ///< What type of hash we really are.
+  static HashType Setting;
+
+  /// For external checking.
+  static size_t const OBJ_SIZE = sizeof(_obj);
+};
+
+inline bool URLHashContext::update(void const* data, int length) {
+  return _ctx->update(data, length);
+}
+
+inline bool URLHashContext::finalize(CryptoHash& hash) {
+  return _ctx->finalize(hash);
+}
 
 extern const char *URL_SCHEME_FILE;
 extern const char *URL_SCHEME_FTP;
@@ -176,8 +205,8 @@ void url_called_set(URLImpl *url);
 char *url_string_get_buf(URLImpl *url, char *dstbuf, int dstbuf_size, int *length);
 
 const char *url_scheme_get(URLImpl *url, int *length);
-void url_MD5_get(URLImpl *url, INK_MD5 *md5);
-void url_host_MD5_get(URLImpl *url, INK_MD5 *md5);
+void url_MD5_get(URLImpl *url, CryptoHash *md5);
+void url_host_MD5_get(URLImpl *url, CryptoHash *md5);
 const char *url_scheme_set(HdrHeap *heap, URLImpl *url,
                            const char *value, int value_wks_idx, int length, bool copy_string);
 
@@ -249,8 +278,8 @@ public:
   char *string_get(Arena *arena, int *length = NULL);
   char *string_get_ref(int *length = NULL);
   char *string_get_buf(char *dstbuf, int dsbuf_size, int *length = NULL);
-  void MD5_get(INK_MD5 *md5);
-  void host_MD5_get(INK_MD5 *md5);
+  void hash_get(CryptoHash *md5);
+  void host_hash_get(CryptoHash *md5);
 
   const char *scheme_get(int *length);
   int scheme_get_wksidx();
@@ -440,7 +469,7 @@ URL::string_get_buf(char *dstbuf, int dsbuf_size, int *length)
   -------------------------------------------------------------------------*/
 
 inline void
-URL::MD5_get(INK_MD5 *md5)
+URL::hash_get(CryptoHash *md5)
 {
   ink_assert(valid());
   url_MD5_get(m_url_impl, md5);
@@ -450,7 +479,7 @@ URL::MD5_get(INK_MD5 *md5)
   -------------------------------------------------------------------------*/
 
 inline void
-URL::host_MD5_get(INK_MD5 *md5)
+URL::host_hash_get(CryptoHash *md5)
 {
   ink_assert(valid());
   url_host_MD5_get(m_url_impl, md5);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/proxy/http/HttpServerSession.h
----------------------------------------------------------------------
diff --git a/proxy/http/HttpServerSession.h b/proxy/http/HttpServerSession.h
index a788a35..2ac4602 100644
--- a/proxy/http/HttpServerSession.h
+++ b/proxy/http/HttpServerSession.h
@@ -175,7 +175,7 @@ extern ClassAllocator<HttpServerSession> httpServerSessionAllocator;
 inline void
 HttpServerSession::attach_hostname(const char *hostname)
 {
-  if (INK_MD5::ZERO == hostname_hash) {
+  if (CRYPTO_HASH_ZERO == hostname_hash) {
     ink_code_md5((unsigned char *) hostname, strlen(hostname), (unsigned char *) &hostname_hash);
   }
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/proxy/logging/LogFormat.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/LogFormat.cc b/proxy/logging/LogFormat.cc
index 3dc5c0c..db371d7 100644
--- a/proxy/logging/LogFormat.cc
+++ b/proxy/logging/LogFormat.cc
@@ -104,21 +104,19 @@ LogFormat::setup(const char *name, const char *format_str, unsigned interval_sec
 
 int32_t LogFormat::id_from_name(const char *name)
 {
-  int32_t
-    id = 0;
+  int32_t id = 0;
   if (name) {
-    INK_MD5
-      name_md5;
-    name_md5.encodeBuffer(name, (int)::strlen(name));
+    CryptoHash hash;
+    MD5Context().hash_immediate(hash, name, static_cast<int>(strlen(name)));
 #if defined(linux)
     /* Mask most signficant bit so that return value of this function
      * is not sign extended to be a negative number.
      * This problem is only known to occur on Linux which
      * is a 32-bit OS.
      */
-    id = (int32_t) name_md5.fold() & 0x7fffffff;
+    id = (int32_t) hash.fold() & 0x7fffffff;
 #else
-    id = (int32_t) name_md5.fold();
+    id = (int32_t) hash.fold();
 #endif
   }
   return id;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/proxy/logging/LogObject.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/LogObject.cc b/proxy/logging/LogObject.cc
index 2e305c9..f8d829b 100644
--- a/proxy/logging/LogObject.cc
+++ b/proxy/logging/LogObject.cc
@@ -337,10 +337,9 @@ uint64_t LogObject::compute_signature(LogFormat * format, char *filename, unsign
     ink_string_concatenate_strings(buffer, fl, ps, filename, flags & LogObject::BINARY ? "B" :
                                    (flags & LogObject::WRITES_TO_PIPE ? "P" : "A"), NULL);
 
-    INK_MD5 md5s;
-
-    md5s.encodeBuffer(buffer, buf_size - 1);
-    signature = md5s.fold();
+    CryptoHash hash;
+    MD5Context().hash_immediate(hash, buffer, buf_size - 1);
+    signature = hash.fold();
 
     ats_free(buffer);
   }


[2/2] git commit: TS-2964: Make URL hash run time selectable.

Posted by am...@apache.org.
TS-2964: Make URL hash run time selectable.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/2ac12c4a
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/2ac12c4a
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/2ac12c4a

Branch: refs/heads/master
Commit: 2ac12c4a2770600743d12964f4b998ba38b05116
Parents: 4268793
Author: Alan M. Carroll <am...@network-geographics.com>
Authored: Mon Jul 28 10:39:21 2014 -0500
Committer: Alan M. Carroll <am...@network-geographics.com>
Committed: Fri Aug 1 09:24:33 2014 -0500

----------------------------------------------------------------------
 iocore/cache/Cache.cc          |  72 ++---
 iocore/cache/CacheDir.cc       | 112 +++----
 iocore/cache/CacheHosting.cc   |   4 +-
 iocore/cache/CacheHttp.cc      |   2 +-
 iocore/cache/CachePages.cc     |   8 +-
 iocore/cache/CacheRead.cc      |  60 ++--
 iocore/cache/CacheTest.cc      |   4 +-
 iocore/cache/CacheVol.cc       |   2 +-
 iocore/cache/CacheWrite.cc     |  58 ++--
 iocore/cache/P_CacheDir.h      |   4 +-
 iocore/cache/P_CacheHosting.h  |   4 +-
 iocore/cache/P_CacheInternal.h |  12 +-
 iocore/cache/P_CacheVol.h      |  50 +--
 iocore/cache/RamCacheCLFUS.cc  |  46 +--
 iocore/cache/RamCacheLRU.cc    |  22 +-
 iocore/hostdb/HostDB.cc        |   3 +-
 lib/ts/CryptoHash.h            | 124 ++++++++
 lib/ts/INK_MD5.h               | 139 +--------
 lib/ts/MMH.cc                  | 588 ++++++++++++++++++++++++++++++++++++
 lib/ts/MMH.h                   | 119 ++++++++
 lib/ts/Makefile.am             |   3 +
 lib/ts/ink_code.cc             |  37 ++-
 lib/ts/ink_code.h              |   3 +-
 lib/ts/libts.h                 |   1 +
 proxy/InkAPI.cc                |  11 +-
 proxy/Prefetch.cc              |   8 +-
 proxy/Update.cc                |   3 +-
 proxy/hdrs/URL.cc              |  82 ++---
 proxy/hdrs/URL.h               |  41 ++-
 proxy/http/HttpServerSession.h |   2 +-
 proxy/logging/LogFormat.cc     |  12 +-
 proxy/logging/LogObject.cc     |   7 +-
 32 files changed, 1208 insertions(+), 435 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/iocore/cache/Cache.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index 03a3650..7d4a8f1 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -116,7 +116,7 @@ ClassAllocator<EvacuationBlock> evacuationBlockAllocator("evacuationBlock");
 ClassAllocator<CacheRemoveCont> cacheRemoveContAllocator("cacheRemoveCont");
 ClassAllocator<EvacuationKey> evacuationKeyAllocator("evacuationKey");
 int CacheVC::size_to_init = -1;
-CacheKey zero_key(0, 0);
+CacheKey zero_key;
 #if TS_USE_INTERIM_CACHE == 1
 ClassAllocator<MigrateToInterimCache> migrateToInterimCacheAllocator("migrateToInterimCache");
 #endif
@@ -1114,7 +1114,7 @@ int
 Vol::db_check(bool /* fix ATS_UNUSED */ )
 {
   char tt[256];
-  printf("    Data for [%s]\n", hash_id);
+  printf("    Data for [%s]\n", hash_text);
   printf("        Length:          %" PRIu64 "\n", (uint64_t)len);
   printf("        Write Position:  %" PRIu64 "\n", (uint64_t) (header->write_pos - skip));
   printf("        Phase:           %d\n", (int)!!header->phase);
@@ -1212,7 +1212,7 @@ vol_dir_clear(Vol *d)
   vol_clear_init(d);
 
   if (pwrite(d->fd, d->raw_dir, dir_len, d->skip) < 0) {
-    Warning("unable to clear cache directory '%s'", d->hash_id);
+    Warning("unable to clear cache directory '%s'", d->hash_text);
     return -1;
   }
   return 0;
@@ -1242,13 +1242,13 @@ Vol::init(char *s, off_t blocks, off_t dir_skip, bool clear)
 {
   dir_skip = ROUND_TO_STORE_BLOCK((dir_skip < START_POS ? START_POS : dir_skip));
   path = ats_strdup(s);
-  const size_t hash_id_size = strlen(s) + 32;
-  hash_id = (char *)ats_malloc(hash_id_size);
-  ink_strlcpy(hash_id, s, hash_id_size);
+  const size_t hash_text_size = strlen(s) + 32;
+  hash_text = (char *)ats_malloc(hash_text_size);
+  ink_strlcpy(hash_text, s, hash_text_size);
   const size_t s_size = strlen(s);
-  snprintf(hash_id + s_size, (hash_id_size - s_size), " %" PRIu64 ":%" PRIu64 "",
+  snprintf(hash_text + s_size, (hash_text_size - s_size), " %" PRIu64 ":%" PRIu64 "",
            (uint64_t)dir_skip, (uint64_t)blocks);
-  hash_id_md5.encodeBuffer(hash_id, strlen(hash_id));
+  MD5Context().hash_immediate(hash_id, hash_text, strlen(hash_text));
   len = blocks * STORE_BLOCK_SIZE;
   ink_assert(len <= MAX_VOL_SIZE);
   skip = dir_skip;
@@ -1286,7 +1286,7 @@ Vol::init(char *s, off_t blocks, off_t dir_skip, bool clear)
 #endif
 
   if (clear) {
-    Note("clearing cache directory '%s'", hash_id);
+    Note("clearing cache directory '%s'", hash_text);
     return clear_dir();
   }
 
@@ -1296,7 +1296,7 @@ Vol::init(char *s, off_t blocks, off_t dir_skip, bool clear)
   // try A
   off_t as = skip;
   if (is_debug_tag_set("cache_init"))
-    Note("reading directory '%s'", hash_id);
+    Note("reading directory '%s'", hash_text);
   SET_HANDLER(&Vol::handle_header_read);
   init_info->vol_aio[0].aiocb.aio_offset = as;
   init_info->vol_aio[1].aiocb.aio_offset = as + footer_offset;
@@ -1330,7 +1330,7 @@ Vol::handle_dir_clear(int event, void *data)
   if (event == AIO_EVENT_DONE) {
     op = (AIOCallback *) data;
     if ((size_t) op->aio_result != (size_t) op->aiocb.aio_nbytes) {
-      Warning("unable to clear cache directory '%s'", hash_id);
+      Warning("unable to clear cache directory '%s'", hash_text);
       fd = -1;
     }
 
@@ -1364,8 +1364,8 @@ Vol::handle_dir_read(int event, void *data)
   }
 
   if (header->magic != VOL_MAGIC || header->version.ink_major != CACHE_DB_MAJOR_VERSION || footer->magic != VOL_MAGIC) {
-    Warning("bad footer in cache directory for '%s', clearing", hash_id);
-    Note("clearing cache directory '%s'", hash_id);
+    Warning("bad footer in cache directory for '%s', clearing", hash_text);
+    Note("clearing cache directory '%s'", hash_text);
     clear_dir();
     return EVENT_DONE;
   }
@@ -1461,7 +1461,7 @@ Vol::handle_recover_from_data(int event, void * /* data ATS_UNUSED */ )
       io.aiocb.aio_nbytes = (skip + len) - recover_pos;
   } else if (event == AIO_EVENT_DONE) {
     if ((size_t) io.aiocb.aio_nbytes != (size_t) io.aio_result) {
-      Warning("disk read error on recover '%s', clearing", hash_id);
+      Warning("disk read error on recover '%s', clearing", hash_text);
       goto Lclear;
     }
     if (io.aiocb.aio_offset == header->last_write_pos) {
@@ -1478,7 +1478,7 @@ Vol::handle_recover_from_data(int event, void * /* data ATS_UNUSED */ )
       while (done < to_check) {
         Doc *doc = (Doc *) (s + done);
         if (doc->magic != DOC_MAGIC || doc->write_serial > header->write_serial) {
-          Warning("no valid directory found while recovering '%s', clearing", hash_id);
+          Warning("no valid directory found while recovering '%s', clearing", hash_text);
           goto Lclear;
         }
         done += round_to_approx_size(doc->len);
@@ -1621,7 +1621,7 @@ Ldone:{
     recover_pos += EVACUATION_SIZE;   // safely cover the max write size
     if (recover_pos < header->write_pos && (recover_pos + EVACUATION_SIZE >= header->write_pos)) {
       Debug("cache_init", "Head Pos: %" PRIu64 ", Rec Pos: %" PRIu64 ", Wrapped:%d", header->write_pos, recover_pos, recover_wrapped);
-      Warning("no valid directory found while recovering '%s', clearing", hash_id);
+      Warning("no valid directory found while recovering '%s', clearing", hash_text);
       goto Lclear;
     }
 
@@ -1728,7 +1728,7 @@ Vol::handle_header_read(int event, void *data)
         (hf[0]->sync_serial >= hf[2]->sync_serial || hf[2]->sync_serial != hf[3]->sync_serial)) {
       SET_HANDLER(&Vol::handle_dir_read);
       if (is_debug_tag_set("cache_init"))
-        Note("using directory A for '%s'", hash_id);
+        Note("using directory A for '%s'", hash_text);
       io.aiocb.aio_offset = skip;
       ink_assert(ink_aio_read(&io));
     }
@@ -1737,11 +1737,11 @@ Vol::handle_header_read(int event, void *data)
 
       SET_HANDLER(&Vol::handle_dir_read);
       if (is_debug_tag_set("cache_init"))
-        Note("using directory B for '%s'", hash_id);
+        Note("using directory B for '%s'", hash_text);
       io.aiocb.aio_offset = skip + vol_dirlen(this);
       ink_assert(ink_aio_read(&io));
     } else {
-      Note("no good directory, clearing '%s'", hash_id);
+      Note("no good directory, clearing '%s'", hash_text);
       clear_dir();
       delete init_info;
       init_info = 0;
@@ -1796,7 +1796,7 @@ InterimCacheVol::handle_recover_from_data(int event, void *data)
 
   if (event == EVENT_IMMEDIATE) {
     if (header->magic != VOL_MAGIC || header->version.ink_major != CACHE_DB_MAJOR_VERSION) {
-      Warning("bad header in cache directory for '%s', clearing", hash_id);
+      Warning("bad header in cache directory for '%s', clearing", hash_text);
       goto Lclear;
     } else if (header->sync_serial == 0) {
       io.aiocb.aio_buf = NULL;
@@ -1820,7 +1820,7 @@ InterimCacheVol::handle_recover_from_data(int event, void *data)
 
   } else if (event == AIO_EVENT_DONE) {
     if ((size_t) io.aiocb.aio_nbytes != (size_t) io.aio_result) {
-      Warning("disk read error on recover '%s', clearing", hash_id);
+      Warning("disk read error on recover '%s', clearing", hash_text);
       goto Lclear;
     }
 
@@ -1832,7 +1832,7 @@ InterimCacheVol::handle_recover_from_data(int event, void *data)
       while (done < to_check) {
         Doc *doc = (Doc *) (s + done);
         if (doc->magic != DOC_MAGIC || doc->write_serial > header->write_serial) {
-          Warning("no valid directory found while recovering '%s', clearing", hash_id);
+          Warning("no valid directory found while recovering '%s', clearing", hash_text);
           goto Lclear;
         }
         done += round_to_approx_size(doc->len);
@@ -1939,7 +1939,7 @@ Ldone: {
     recover_pos += EVACUATION_SIZE;
     if (recover_pos < header->write_pos && (recover_pos + EVACUATION_SIZE >= header->write_pos)) {
       Debug("cache_init", "Head Pos: %" PRIu64 ", Rec Pos: %" PRIu64 ", Wrapped:%d", header->write_pos, recover_pos, recover_wrapped);
-      Warning("no valid directory found while recovering '%s', clearing", hash_id);
+      Warning("no valid directory found while recovering '%s', clearing", hash_text);
       goto Lclear;
     }
 
@@ -2063,7 +2063,7 @@ build_vol_hash_table(CacheHostRecord *cp)
     forvol[i % num_vols]++;
   // seed random number generator
   for (int i = 0; i < num_vols; i++) {
-    uint64_t x = p[i]->hash_id_md5.fold();
+    uint64_t x = p[i]->hash_id.fold();
     rnd[i] = (unsigned int) x;
   }
   // initialize table to "empty"
@@ -2365,7 +2365,7 @@ CacheVC::handleReadDone(int event, Event *e)
       if (!io.ok()) {
         Debug("cache_disk_error", "Read error on disk %s\n \
 	    read range : [%" PRIu64 " - %" PRIu64 " bytes]  [%" PRIu64 " - %" PRIu64 " blocks] \n",
-              vol->hash_id, (uint64_t)io.aiocb.aio_offset, (uint64_t)io.aiocb.aio_offset + io.aiocb.aio_nbytes,
+              vol->hash_text, (uint64_t)io.aiocb.aio_offset, (uint64_t)io.aiocb.aio_offset + io.aiocb.aio_nbytes,
               (uint64_t)io.aiocb.aio_offset / 512, (uint64_t)(io.aiocb.aio_offset + io.aiocb.aio_nbytes) / 512);
       }
       goto Ldone;
@@ -2638,7 +2638,7 @@ LmemHit:
 }
 
 Action *
-Cache::lookup(Continuation *cont, CacheKey *key, CacheFragType type, char *hostname, int host_len)
+Cache::lookup(Continuation *cont, CacheKey *key, CacheFragType type, char const* hostname, int host_len)
 {
   if (!CacheProcessor::IsCacheReady(type)) {
     cont->handleEvent(CACHE_EVENT_LOOKUP_FAILED, 0);
@@ -2667,12 +2667,12 @@ Cache::lookup(Continuation *cont, CacheKey *key, CacheFragType type, char *hostn
 Action *
 Cache::lookup(Continuation *cont, CacheURL *url, CacheFragType type)
 {
-  INK_MD5 md5;
+  CryptoHash id;
 
-  url->MD5_get(&md5);
+  url->hash_get(&id);
   int len = 0;
-  const char *hostname = url->host_get(&len);
-  return lookup(cont, &md5, type, (char *) hostname, len);
+  char const* hostname = url->host_get(&len);
+  return lookup(cont, &id, type, hostname, len);
 }
 
 int
@@ -3241,9 +3241,9 @@ rebuild_host_table(Cache *cache)
 
 // if generic_host_rec.vols == NULL, what do we do???
 Vol *
-Cache::key_to_vol(CacheKey *key, char *hostname, int host_len)
+Cache::key_to_vol(CacheKey *key, char const* hostname, int host_len)
 {
-  uint32_t h = (key->word(2) >> DIR_TAG_WIDTH) % VOL_HASH_TABLE_SIZE;
+  uint32_t h = (key->slice32(2) >> DIR_TAG_WIDTH) % VOL_HASH_TABLE_SIZE;
   unsigned short *hash_table = hosttable->gen_host_rec.vol_hash_table;
   CacheHostRecord *host_rec = &hosttable->gen_host_rec;
 
@@ -3487,23 +3487,23 @@ CacheProcessor::open_write(Continuation *cont, int expected_size, URL *url, bool
 Action *
 CacheProcessor::remove(Continuation *cont, URL *url, bool cluster_cache_local, CacheFragType frag_type)
 {
-  INK_MD5 md5;
+  CryptoHash id;
   int len = 0;
   const char *hostname;
 
-  url->MD5_get(&md5);
+  url->hash_get(&id);
   hostname = url->host_get(&len);
 
   Debug("cache_remove", "[CacheProcessor::remove] Issuing cache delete for %s", url->string_get_ref());
 #ifdef CLUSTER_CACHE
   if (cache_clustering_enabled > 0 && !cluster_cache_local) {
     // Remove from cluster
-    return remove(cont, &md5, cluster_cache_local, frag_type, true, false, const_cast<char *>(hostname), len);
+    return remove(cont, &id, cluster_cache_local, frag_type, true, false, const_cast<char *>(hostname), len);
   }
 #endif
 
   // Remove from local cache only.
-  return caches[frag_type]->remove(cont, &md5, frag_type, true, false, const_cast<char*>(hostname), len);
+  return caches[frag_type]->remove(cont, &id, frag_type, true, false, const_cast<char*>(hostname), len);
 }
 
 CacheDisk*

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/iocore/cache/CacheDir.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/CacheDir.cc b/iocore/cache/CacheDir.cc
index ba0fddc..18b3be6 100644
--- a/iocore/cache/CacheDir.cc
+++ b/iocore/cache/CacheDir.cc
@@ -69,7 +69,7 @@ int
 OpenDir::open_write(CacheVC *cont, int allow_if_writers, int max_writers)
 {
   ink_assert(cont->vol->mutex->thread_holding == this_ethread());
-  unsigned int h = cont->first_key.word(0);
+  unsigned int h = cont->first_key.slice32(0);
   int b = h % OPEN_DIR_BUCKETS;
   for (OpenDirEntry *d = bucket[b].head; d; d = d->link.next) {
     if (!(d->writers.head->first_key == cont->first_key))
@@ -133,7 +133,7 @@ OpenDir::close_write(CacheVC *cont)
   cont->od->writers.remove(cont);
   cont->od->num_writers--;
   if (!cont->od->writers.head) {
-    unsigned int h = cont->first_key.word(0);
+    unsigned int h = cont->first_key.slice32(0);
     int b = h % OPEN_DIR_BUCKETS;
     bucket[b].remove(cont->od);
     delayed_readers.append(cont->od->readers);
@@ -148,7 +148,7 @@ OpenDir::close_write(CacheVC *cont)
 OpenDirEntry *
 OpenDir::open_read(INK_MD5 *key)
 {
-  unsigned int h = key->word(0);
+  unsigned int h = key->slice32(0);
   int b = h % OPEN_DIR_BUCKETS;
   for (OpenDirEntry *d = bucket[b].head; d; d = d->link.next)
     if (d->writers.head->first_key == *key)
@@ -591,8 +591,8 @@ int
 dir_probe(CacheKey *key, Vol *d, Dir *result, Dir ** last_collision)
 {
   ink_assert(d->mutex->thread_holding == this_ethread());
-  int s = key->word(0) % d->segments;
-  int b = key->word(1) % d->buckets;
+  int s = key->slice32(0) % d->segments;
+  int b = key->slice32(1) % d->buckets;
   Dir *seg = dir_segment(s, d);
   Dir *e = NULL, *p = NULL, *collision = *last_collision;
   Vol *vol = d;
@@ -624,7 +624,7 @@ Lagain:
           goto Lcont;
         }
         if (dir_valid(d, e)) {
-          DDebug("dir_probe_hit", "found %X %X vol %d bucket %d boffset %" PRId64 "", key->word(0), key->word(1), d->fd, b, dir_offset(e));
+          DDebug("dir_probe_hit", "found %X %X vol %d bucket %d boffset %" PRId64 "", key->slice32(0), key->slice32(1), d->fd, b, dir_offset(e));
           dir_assign(result, e);
           *last_collision = e;
 #if !TS_USE_INTERIM_CACHE
@@ -637,7 +637,7 @@ Lagain:
           continue;
         }
       } else
-        DDebug("dir_probe_tag", "tag mismatch %p %X vs expected %X", e, dir_tag(e), key->word(3));
+        DDebug("dir_probe_tag", "tag mismatch %p %X vs expected %X", e, dir_tag(e), key->slice32(3));
     Lcont:
       p = e;
       e = next_dir(e, seg);
@@ -648,7 +648,7 @@ Lagain:
     collision = NULL;
     goto Lagain;
   }
-  DDebug("dir_probe_miss", "missed %X %X on vol %d bucket %d at %p", key->word(0), key->word(1), d->fd, b, seg);
+  DDebug("dir_probe_miss", "missed %X %X on vol %d bucket %d at %p", key->slice32(0), key->slice32(1), d->fd, b, seg);
   CHECK_DIR(d);
   return 0;
 }
@@ -657,15 +657,15 @@ int
 dir_insert(CacheKey *key, Vol *d, Dir *to_part)
 {
   ink_assert(d->mutex->thread_holding == this_ethread());
-  int s = key->word(0) % d->segments, l;
-  int bi = key->word(1) % d->buckets;
+  int s = key->slice32(0) % d->segments, l;
+  int bi = key->slice32(1) % d->buckets;
   ink_assert(dir_approx_size(to_part) <= MAX_FRAG_SIZE + sizeofDoc);
   Dir *seg = dir_segment(s, d);
   Dir *e = NULL;
   Dir *b = dir_bucket(bi, seg);
   Vol *vol = d;
 #if defined(DEBUG) && defined(DO_CHECK_DIR_FAST)
-  unsigned int t = DIR_MASK_TAG(key->word(2));
+  unsigned int t = DIR_MASK_TAG(key->slice32(2));
   Dir *col = b;
   while (col) {
     ink_assert((dir_tag(col) != t) || (dir_offset(col) != dir_offset(to_part)));
@@ -700,15 +700,15 @@ Llink:
 Lfill:
 #if TS_USE_INTERIM_CACHE == 1
   dir_assign_data(b, to_part);
-  dir_set_tag(b, key->word(2));
+  dir_set_tag(b, key->slice32(2));
 #else
   dir_assign_data(e, to_part);
-  dir_set_tag(e, key->word(2));
+  dir_set_tag(e, key->slice32(2));
   ink_assert(vol_offset(d, e) < (d->skip + d->len));
 #endif
   DDebug("dir_insert",
         "insert %p %X into vol %d bucket %d at %p tag %X %X boffset %" PRId64 "",
-         e, key->word(0), d->fd, bi, e, key->word(1), dir_tag(e), dir_offset(e));
+         e, key->slice32(0), d->fd, bi, e, key->slice32(1), dir_tag(e), dir_offset(e));
   CHECK_DIR(d);
   d->header->dirty = 1;
   CACHE_INC_DIR_USED(d->mutex);
@@ -719,12 +719,12 @@ int
 dir_overwrite(CacheKey *key, Vol *d, Dir *dir, Dir *overwrite, bool must_overwrite)
 {
   ink_assert(d->mutex->thread_holding == this_ethread());
-  int s = key->word(0) % d->segments, l;
-  int bi = key->word(1) % d->buckets;
+  int s = key->slice32(0) % d->segments, l;
+  int bi = key->slice32(1) % d->buckets;
   Dir *seg = dir_segment(s, d);
   Dir *e = NULL;
   Dir *b = dir_bucket(bi, seg);
-  unsigned int t = DIR_MASK_TAG(key->word(2));
+  unsigned int t = DIR_MASK_TAG(key->slice32(2));
   int res = 1;
 #ifdef LOOP_CHECK_MODE
   int loop_count = 0;
@@ -786,7 +786,7 @@ Lfill:
   ink_assert(vol_offset(d, e) < d->skip + d->len);
   DDebug("dir_overwrite",
         "overwrite %p %X into vol %d bucket %d at %p tag %X %X boffset %" PRId64 "",
-         e, key->word(0), d->fd, bi, e, t, dir_tag(e), dir_offset(e));
+         e, key->slice32(0), d->fd, bi, e, t, dir_tag(e), dir_offset(e));
   CHECK_DIR(d);
   d->header->dirty = 1;
   return res;
@@ -796,8 +796,8 @@ int
 dir_delete(CacheKey *key, Vol *d, Dir *del)
 {
   ink_assert(d->mutex->thread_holding == this_ethread());
-  int s = key->word(0) % d->segments;
-  int b = key->word(1) % d->buckets;
+  int s = key->slice32(0) % d->segments;
+  int b = key->slice32(1) % d->buckets;
   Dir *seg = dir_segment(s, d);
   Dir *e = NULL, *p = NULL;
 #ifdef LOOP_CHECK_MODE
@@ -839,13 +839,13 @@ int
 dir_lookaside_probe(CacheKey *key, Vol *d, Dir *result, EvacuationBlock ** eblock)
 {
   ink_assert(d->mutex->thread_holding == this_ethread());
-  int i = key->word(3) % LOOKASIDE_SIZE;
+  int i = key->slice32(3) % LOOKASIDE_SIZE;
   EvacuationBlock *b = d->lookaside[i].head;
   while (b) {
     if (b->evac_frags.key == *key) {
       if (dir_valid(d, &b->new_dir)) {
         *result = b->new_dir;
-        DDebug("dir_lookaside", "probe %X success", key->word(0));
+        DDebug("dir_lookaside", "probe %X success", key->slice32(0));
         if (eblock)
           *eblock = b;
         return 1;
@@ -853,7 +853,7 @@ dir_lookaside_probe(CacheKey *key, Vol *d, Dir *result, EvacuationBlock ** ebloc
     }
     b = b->link.next;
   }
-  DDebug("dir_lookaside", "probe %X failed", key->word(0));
+  DDebug("dir_lookaside", "probe %X failed", key->slice32(0));
   return 0;
 }
 
@@ -861,9 +861,9 @@ int
 dir_lookaside_insert(EvacuationBlock *eblock, Vol *d, Dir *to)
 {
   CacheKey *key = &eblock->evac_frags.earliest_key;
-  DDebug("dir_lookaside", "insert %X %X, offset %d phase %d", key->word(0), key->word(1), (int) dir_offset(to), (int) dir_phase(to));
+  DDebug("dir_lookaside", "insert %X %X, offset %d phase %d", key->slice32(0), key->slice32(1), (int) dir_offset(to), (int) dir_phase(to));
   ink_assert(d->mutex->thread_holding == this_ethread());
-  int i = key->word(3) % LOOKASIDE_SIZE;
+  int i = key->slice32(3) % LOOKASIDE_SIZE;
   EvacuationBlock *b = new_EvacuationBlock(d->mutex->thread_holding);
   b->evac_frags.key = *key;
   b->evac_frags.earliest_key = *key;
@@ -879,13 +879,13 @@ int
 dir_lookaside_fixup(CacheKey *key, Vol *d)
 {
   ink_assert(d->mutex->thread_holding == this_ethread());
-  int i = key->word(3) % LOOKASIDE_SIZE;
+  int i = key->slice32(3) % LOOKASIDE_SIZE;
   EvacuationBlock *b = d->lookaside[i].head;
   while (b) {
     if (b->evac_frags.key == *key) {
       int res = dir_overwrite(key, d, &b->new_dir, &b->dir, false);
       DDebug("dir_lookaside", "fixup %X %X offset %" PRId64" phase %d %d",
-            key->word(0), key->word(1), dir_offset(&b->new_dir), dir_phase(&b->new_dir), res);
+            key->slice32(0), key->slice32(1), dir_offset(&b->new_dir), dir_phase(&b->new_dir), res);
 #if TS_USE_INTERIM_CACHE == 1
       int64_t o = dir_get_offset(&b->dir), n = dir_get_offset(&b->new_dir);
 #else
@@ -898,7 +898,7 @@ dir_lookaside_fixup(CacheKey *key, Vol *d)
     }
     b = b->link.next;
   }
-  DDebug("dir_lookaside", "fixup %X %X failed", key->word(0), key->word(1));
+  DDebug("dir_lookaside", "fixup %X %X failed", key->slice32(0), key->slice32(1));
   return 0;
 }
 
@@ -912,7 +912,7 @@ dir_lookaside_cleanup(Vol *d)
       if (!dir_valid(d, &b->new_dir)) {
         EvacuationBlock *nb = b->link.next;
         DDebug("dir_lookaside", "cleanup %X %X cleaned up",
-              b->evac_frags.earliest_key.word(0), b->evac_frags.earliest_key.word(1));
+              b->evac_frags.earliest_key.slice32(0), b->evac_frags.earliest_key.slice32(1));
         d->lookaside[i].remove(b);
         free_CacheVC(b->earliest_evacuator);
         free_EvacuationBlock(b, d->mutex->thread_holding);
@@ -929,19 +929,19 @@ void
 dir_lookaside_remove(CacheKey *key, Vol *d)
 {
   ink_assert(d->mutex->thread_holding == this_ethread());
-  int i = key->word(3) % LOOKASIDE_SIZE;
+  int i = key->slice32(3) % LOOKASIDE_SIZE;
   EvacuationBlock *b = d->lookaside[i].head;
   while (b) {
     if (b->evac_frags.key == *key) {
       DDebug("dir_lookaside", "remove %X %X offset %" PRId64" phase %d",
-            key->word(0), key->word(1), dir_offset(&b->new_dir), dir_phase(&b->new_dir));
+            key->slice32(0), key->slice32(1), dir_offset(&b->new_dir), dir_phase(&b->new_dir));
       d->lookaside[i].remove(b);
       free_EvacuationBlock(b, d->mutex->thread_holding);
       return;
     }
     b = b->link.next;
   }
-  DDebug("dir_lookaside", "remove %X %X failed", key->word(0), key->word(1));
+  DDebug("dir_lookaside", "remove %X %X failed", key->slice32(0), key->slice32(1));
   return;
 }
 
@@ -1015,13 +1015,13 @@ sync_cache_dir_on_shutdown(void)
     Vol *d = gvol[i];
 
     if (DISK_BAD(d->disk)) {
-      Debug("cache_dir_sync", "Dir %s: ignoring -- bad disk", d->hash_id);
+      Debug("cache_dir_sync", "Dir %s: ignoring -- bad disk", d->hash_text);
       continue;
     }
     size_t dirlen = vol_dirlen(d);
     ink_assert(dirlen > 0); // make clang happy - if not > 0 the vol is seriously messed up
     if (!d->header->dirty && !d->dir_sync_in_progress) {
-      Debug("cache_dir_sync", "Dir %s: ignoring -- not dirty", d->hash_id);
+      Debug("cache_dir_sync", "Dir %s: ignoring -- not dirty", d->hash_text);
       continue;
     }
     // recompute hit_evacuate_window
@@ -1032,7 +1032,7 @@ sync_cache_dir_on_shutdown(void)
     // dont worry about the cachevc s in the agg queue
     // directories have not been inserted for these writes
     if (d->agg_buf_pos) {
-      Debug("cache_dir_sync", "Dir %s: flushing agg buffer first", d->hash_id);
+      Debug("cache_dir_sync", "Dir %s: flushing agg buffer first", d->hash_text);
 
       // set write limit
       d->header->agg_pos = d->header->write_pos + d->agg_buf_pos;
@@ -1054,7 +1054,7 @@ sync_cache_dir_on_shutdown(void)
     for (int i = 0; i < d->num_interim_vols; i++) {
       InterimCacheVol *sv = &(d->interim_vols[i]);
       if (sv->agg_buf_pos) {
-        Debug("cache_dir_sync", "Dir %s: flushing agg buffer first to interim", d->hash_id);
+        Debug("cache_dir_sync", "Dir %s: flushing agg buffer first to interim", d->hash_text);
         sv->header->agg_pos = sv->header->write_pos + sv->agg_buf_pos;
 
         int r = pwrite(sv->fd, sv->agg_buffer, sv->agg_buf_pos, sv->header->write_pos);
@@ -1096,7 +1096,7 @@ sync_cache_dir_on_shutdown(void)
     off_t start = d->skip + (B ? dirlen : 0);
     B = pwrite(d->fd, buf, dirlen, start);
     ink_assert(B == dirlen);
-    Debug("cache_dir_sync", "done syncing dir for vol %s", d->hash_id);
+    Debug("cache_dir_sync", "done syncing dir for vol %s", d->hash_text);
   }
   Debug("cache_dir_sync", "sync done");
   if (buf)
@@ -1131,7 +1131,7 @@ Lrestart:
   if (event == AIO_EVENT_DONE) {
     // AIO Thread
     if (io.aio_result != (int64_t)io.aiocb.aio_nbytes) {
-      Warning("vol write error during directory sync '%s'", gvol[vol]->hash_id);
+      Warning("vol write error during directory sync '%s'", gvol[vol]->hash_text);
       event = EVENT_NONE;
       goto Ldone;
     }
@@ -1164,11 +1164,11 @@ Lrestart:
          The dirty bit it set in dir_insert, dir_overwrite and dir_delete_entry
        */
       if (!d->header->dirty) {
-        Debug("cache_dir_sync", "Dir %s not dirty", d->hash_id);
+        Debug("cache_dir_sync", "Dir %s not dirty", d->hash_text);
         goto Ldone;
       }
       if (d->is_io_in_progress() || d->agg_buf_pos) {
-        Debug("cache_dir_sync", "Dir %s: waiting for agg buffer", d->hash_id);
+        Debug("cache_dir_sync", "Dir %s: waiting for agg buffer", d->hash_text);
         d->dir_sync_waiting = 1;
         if (!d->is_io_in_progress())
           d->aggWrite(EVENT_IMMEDIATE, 0);
@@ -1182,7 +1182,7 @@ Lrestart:
 #endif
         return EVENT_CONT;
       }
-      Debug("cache_dir_sync", "pos: %" PRIu64 " Dir %s dirty...syncing to disk", d->header->write_pos, d->hash_id);
+      Debug("cache_dir_sync", "pos: %" PRIu64 " Dir %s dirty...syncing to disk", d->header->write_pos, d->hash_text);
       d->header->dirty = 0;
       if (buflen < dirlen) {
         if (buf)
@@ -1276,7 +1276,7 @@ Vol::dir_check(bool /* fix ATS_UNUSED */) // TODO: we should eliminate this para
     free += dir_freelist_length(this, s);
   }
   int total = buckets * segments * DIR_DEPTH;
-  printf("    Directory for [%s]\n", hash_id);
+  printf("    Directory for [%s]\n", hash_text);
   printf("        Bytes:     %d\n", total * SIZEOF_DIR);
   printf("        Segments:  %" PRIu64 "\n", (uint64_t)segments);
   printf("        Buckets:   %" PRIu64 "\n", (uint64_t)buckets);
@@ -1446,7 +1446,7 @@ EXCLUSIVE_REGRESSION_TEST(Cache_dir) (RegressionTest *t, int /* atype ATS_UNUSED
   CacheKey key;
   rand_CacheKey(&key, thread->mutex);
 
-  int s = key.word(0) % d->segments, i, j;
+  int s = key.slice32(0) % d->segments, i, j;
   Dir *seg = dir_segment(s, d);
 
   // test insert
@@ -1518,8 +1518,8 @@ EXCLUSIVE_REGRESSION_TEST(Cache_dir) (RegressionTest *t, int /* atype ATS_UNUSED
 #ifdef LOOP_CHECK_MODE
     // dir_probe in bucket with loop
     rand_CacheKey(&key, thread->mutex);
-    s1 = key.word(0) % d->segments;
-    b1 = key.word(1) % d->buckets;
+    s1 = key.slice32(0) % d->segments;
+    b1 = key.slice32(1) % d->buckets;
     dir_corrupt_bucket(dir_bucket(b1, dir_segment(s1, d)), s1, d);
     dir_insert(&key, d, &dir);
     Dir *last_collision = 0;
@@ -1527,8 +1527,8 @@ EXCLUSIVE_REGRESSION_TEST(Cache_dir) (RegressionTest *t, int /* atype ATS_UNUSED
 
 
     rand_CacheKey(&key, thread->mutex);
-    s1 = key.word(0) % d->segments;
-    b1 = key.word(1) % d->buckets;
+    s1 = key.slice32(0) % d->segments;
+    b1 = key.slice32(1) % d->buckets;
     dir_corrupt_bucket(dir_bucket(b1, dir_segment(s1, d)), s1, d);
 
     last_collision = 0;
@@ -1536,8 +1536,8 @@ EXCLUSIVE_REGRESSION_TEST(Cache_dir) (RegressionTest *t, int /* atype ATS_UNUSED
 
     // dir_overwrite in bucket with loop
     rand_CacheKey(&key, thread->mutex);
-    s1 = key.word(0) % d->segments;
-    b1 = key.word(1) % d->buckets;
+    s1 = key.slice32(0) % d->segments;
+    b1 = key.slice32(1) % d->buckets;
     CacheKey key1;
     key1.b[1] = 127;
     dir1 = dir;
@@ -1550,23 +1550,23 @@ EXCLUSIVE_REGRESSION_TEST(Cache_dir) (RegressionTest *t, int /* atype ATS_UNUSED
     dir_overwrite(&key, d, &dir, &dir, 1);
 
     rand_CacheKey(&key, thread->mutex);
-    s1 = key.word(0) % d->segments;
-    b1 = key.word(1) % d->buckets;
+    s1 = key.slice32(0) % d->segments;
+    b1 = key.slice32(1) % d->buckets;
     key.b[1] = 23;
     dir_insert(&key, d, &dir1);
     dir_corrupt_bucket(dir_bucket(b1, dir_segment(s1, d)), s1, d);
     dir_overwrite(&key, d, &dir, &dir, 0);
 
     rand_CacheKey(&key, thread->mutex);
-    s1 = key.word(0) % d->segments;
+    s1 = key.slice32(0) % d->segments;
     Dir *seg1 = dir_segment(s1, d);
     // dir_freelist_length in freelist with loop
     dir_corrupt_bucket(dir_from_offset(d->header->freelist[s], seg1), s1, d);
     dir_freelist_length(d, s1);
 
     rand_CacheKey(&key, thread->mutex);
-    s1 = key.word(0) % d->segments;
-    b1 = key.word(1) % d->buckets;
+    s1 = key.slice32(0) % d->segments;
+    b1 = key.slice32(1) % d->buckets;
     // dir_bucket_length in bucket with loop
     dir_corrupt_bucket(dir_bucket(b1, dir_segment(s1, d)), s1, d);
     dir_bucket_length(dir_bucket(b1, dir_segment(s1, d)), s1, d);
@@ -1575,8 +1575,8 @@ EXCLUSIVE_REGRESSION_TEST(Cache_dir) (RegressionTest *t, int /* atype ATS_UNUSED
 #else
     // test corruption detection
     rand_CacheKey(&key, thread->mutex);
-    s1 = key.word(0) % d->segments;
-    b1 = key.word(1) % d->buckets;
+    s1 = key.slice32(0) % d->segments;
+    b1 = key.slice32(1) % d->buckets;
 
     dir_insert(&key, d, &dir1);
     dir_insert(&key, d, &dir1);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/iocore/cache/CacheHosting.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/CacheHosting.cc b/iocore/cache/CacheHosting.cc
index 2d2f3b2..3c7395b 100644
--- a/iocore/cache/CacheHosting.cc
+++ b/iocore/cache/CacheHosting.cc
@@ -101,7 +101,7 @@ CacheHostMatcher::AllocateSpace(int num_entries)
 //    arg hostname
 //
 void
-CacheHostMatcher::Match(char *rdata, int rlen, CacheHostResult * result)
+CacheHostMatcher::Match(char const* rdata, int rlen, CacheHostResult * result)
 {
 
   void *opaque_ptr;
@@ -233,7 +233,7 @@ CacheHostTable::Print()
 //   Queries each table for the Result*
 //
 void
-CacheHostTable::Match(char *rdata, int rlen, CacheHostResult * result)
+CacheHostTable::Match(char const* rdata, int rlen, CacheHostResult * result)
 {
 
   hostMatch->Match(rdata, rlen, result);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/iocore/cache/CacheHttp.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/CacheHttp.cc b/iocore/cache/CacheHttp.cc
index e07698c..6bcc4fc 100644
--- a/iocore/cache/CacheHttp.cc
+++ b/iocore/cache/CacheHttp.cc
@@ -154,7 +154,7 @@ CacheHTTPInfoVector::print(char *buffer, size_t buf_size, bool temps)
 
       if (temps || !(data[i].alternate.object_key_get() == zero_key)) {
         snprintf(p, buf_size, "[%d %s]", data[i].alternate.id_get(),
-                     CacheKey(data[i].alternate.object_key_get()).string(buf));
+                     CacheKey(data[i].alternate.object_key_get()).toHexStr(buf));
         tmp = strlen(p);
         p += tmp;
         buf_size -= tmp;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/iocore/cache/CachePages.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/CachePages.cc b/iocore/cache/CachePages.cc
index 2f0e57a..c35f4f2 100644
--- a/iocore/cache/CachePages.cc
+++ b/iocore/cache/CachePages.cc
@@ -318,8 +318,8 @@ ShowCache::handleCacheEvent(int event, Event *e) {
         CHECK_SHOW(show("<P><TABLE border=1 width=100%%>"));
         CHECK_SHOW(show("<TR><TH bgcolor=\"#FFF0E0\" colspan=2>Doc</TH></TR>\n"));
         CHECK_SHOW(show("<TR><TD>Volume</td> <td>#%d - store='%s'</td></tr>\n", cache_vc->vol->cache_vol->vol_number, cache_vc->vol->path));
-        CHECK_SHOW(show("<TR><TD>first key</td> <td>%s</td></tr>\n", d->first_key.string(tmpstr)));
-        CHECK_SHOW(show("<TR><TD>key</td> <td>%s</td></tr>\n", d->key.string(tmpstr)));
+        CHECK_SHOW(show("<TR><TD>first key</td> <td>%s</td></tr>\n", d->first_key.toHexStr(tmpstr)));
+        CHECK_SHOW(show("<TR><TD>key</td> <td>%s</td></tr>\n", d->key.toHexStr(tmpstr)));
         CHECK_SHOW(show("<tr><td>sync_serial</td><td>%lu</tr>\n", d->sync_serial));
         CHECK_SHOW(show("<tr><td>write_serial</td><td>%lu</tr>\n", d->write_serial));
         CHECK_SHOW(show("<tr><td>header length</td><td>%lu</tr>\n", d->hlen));
@@ -371,7 +371,7 @@ ShowCache::handleCacheEvent(int event, Event *e) {
           } while (!done);
           CHECK_SHOW(show("</PRE></td></tr>\n"));
           CHECK_SHOW(show("<tr><td>Size</td><td>%" PRId64 "</td>\n", obj_size));
-          CHECK_SHOW(show("<tr><td>Key</td><td>%s</td>\n", obj_key.string(tmpstr)));
+          CHECK_SHOW(show("<tr><td>Key</td><td>%s</td>\n", obj_key.toHexStr(tmpstr)));
           t = obj->request_sent_time_get();
           ink_ctime_r(&t, tmpstr);
           CHECK_SHOW(show("<tr><td>Request sent time</td><td>%s</td></tr>\n", tmpstr));
@@ -418,7 +418,7 @@ ShowCache::lookup_url(int event, Event *e) {
   url.parse(&s, s + strlen(s));
   INK_MD5 md5;
   int len;
-  url.MD5_get(&md5);
+  url.hash_get(&md5);
   const char *hostname = url.host_get(&len);
   SET_HANDLER(&ShowCache::handleCacheEvent);
   Action *lookup_result = cacheProcessor.open_read(this, &md5, getClusterCacheLocal(&url, (char *)hostname), CACHE_FRAG_TYPE_HTTP, (char *) hostname, len);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/iocore/cache/CacheRead.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/CacheRead.cc b/iocore/cache/CacheRead.cc
index e1e5542..5b3d071 100644
--- a/iocore/cache/CacheRead.cc
+++ b/iocore/cache/CacheRead.cc
@@ -256,14 +256,14 @@ CacheVC::openReadChooseWriter(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSE
     }
     vector.clear(false);
     if (!write_vc) {
-      DDebug("cache_read_agg", "%p: key: %X writer alternate different: %d", this, first_key.word(1), alternate_index);
+      DDebug("cache_read_agg", "%p: key: %X writer alternate different: %d", this, first_key.slice32(1), alternate_index);
       od = NULL;
       return EVENT_RETURN;
     }
 
     DDebug("cache_read_agg",
           "%p: key: %X eKey: %d # alts: %d, ndx: %d, # writers: %d writer: %p",
-          this, first_key.word(1), write_vc->earliest_key.word(1),
+          this, first_key.slice32(1), write_vc->earliest_key.slice32(1),
           vector.count(), alternate_index, od->num_writers, write_vc);
   }
 #endif //HTTP_CACHE
@@ -287,7 +287,7 @@ CacheVC::openReadFromWriter(int event, Event * e)
   }
   cancel_trigger();
   intptr_t err = ECACHE_DOC_BUSY;
-  DDebug("cache_read_agg", "%p: key: %X In openReadFromWriter", this, first_key.word(1));
+  DDebug("cache_read_agg", "%p: key: %X In openReadFromWriter", this, first_key.slice32(1));
 #ifndef READ_WHILE_WRITER
   return openReadFromWriterFailure(CACHE_EVENT_OPEN_READ_FAILED, (Event *) -err);
 #else
@@ -325,7 +325,7 @@ CacheVC::openReadFromWriter(int event, Event * e)
     if (writer_done()) {
       MUTEX_RELEASE(lock);
       DDebug("cache_read_agg",
-            "%p: key: %X writer %p has left, continuing as normal read", this, first_key.word(1), write_vc);
+            "%p: key: %X writer %p has left, continuing as normal read", this, first_key.slice32(1), write_vc);
       od = NULL;
       write_vc = NULL;
       SET_HANDLER(&CacheVC::openReadStartHead);
@@ -353,13 +353,13 @@ CacheVC::openReadFromWriter(int event, Event * e)
     }
     DDebug("cache_read_agg",
           "%p: key: %X writer: closed:%d, fragment:%d, retry: %d",
-          this, first_key.word(1), write_vc->closed, write_vc->fragment, writer_lock_retry);
+          this, first_key.slice32(1), write_vc->closed, write_vc->fragment, writer_lock_retry);
     VC_SCHED_WRITER_RETRY();
   }
 
   CACHE_TRY_LOCK(writer_lock, write_vc->mutex, mutex->thread_holding);
   if (!writer_lock) {
-    DDebug("cache_read_agg", "%p: key: %X lock miss", this, first_key.word(1));
+    DDebug("cache_read_agg", "%p: key: %X lock miss", this, first_key.slice32(1));
     VC_SCHED_LOCK_RETRY();
   }
   MUTEX_RELEASE(lock);
@@ -370,7 +370,7 @@ CacheVC::openReadFromWriter(int event, Event * e)
   if (frag_type == CACHE_FRAG_TYPE_HTTP) {
     DDebug("cache_read_agg",
           "%p: key: %X http passed stage 1, closed: %d, frag: %d",
-          this, first_key.word(1), write_vc->closed, write_vc->fragment);
+          this, first_key.slice32(1), write_vc->closed, write_vc->fragment);
     if (!write_vc->alternate.valid())
       return openReadFromWriterFailure(CACHE_EVENT_OPEN_READ_FAILED, (Event *) - err);
     alternate.copy(&write_vc->alternate);
@@ -386,7 +386,7 @@ CacheVC::openReadFromWriter(int event, Event * e)
     } else {
       key = write_vc->update_key;
       ink_assert(write_vc->closed);
-      DDebug("cache_read_agg", "%p: key: %X writer header update", this, first_key.word(1));
+      DDebug("cache_read_agg", "%p: key: %X writer header update", this, first_key.slice32(1));
       // Update case (b) : grab doc_len from the writer's alternate
       doc_len = alternate.object_size_get();
       if (write_vc->update_key == cod->single_doc_key &&
@@ -417,7 +417,7 @@ CacheVC::openReadFromWriter(int event, Event * e)
     }
   } else {
 #endif //HTTP_CACHE
-    DDebug("cache_read_agg", "%p: key: %X non-http passed stage 1", this, first_key.word(1));
+    DDebug("cache_read_agg", "%p: key: %X non-http passed stage 1", this, first_key.slice32(1));
     key = write_vc->earliest_key;
 #ifdef HTTP_CACHE
   }
@@ -427,7 +427,7 @@ CacheVC::openReadFromWriter(int event, Event * e)
     last_collision = NULL;
     DDebug("cache_read_agg",
           "%p: key: %X closed: %d, fragment: %d, len: %d starting first fragment",
-          this, first_key.word(1), write_vc->closed, write_vc->fragment, (int)doc_len);
+          this, first_key.slice32(1), write_vc->closed, write_vc->fragment, (int)doc_len);
     MUTEX_RELEASE(writer_lock);
     // either a header + body update or a new document
     SET_HANDLER(&CacheVC::openReadStartEarliest);
@@ -444,7 +444,7 @@ CacheVC::openReadFromWriter(int event, Event * e)
   doc_len = write_vc->total_len;
   dir_clean(&first_dir);
   dir_clean(&earliest_dir);
-  DDebug("cache_read_agg", "%p: key: %X %X: single fragment read", this, first_key.word(1), key.word(0));
+  DDebug("cache_read_agg", "%p: key: %X %X: single fragment read", this, first_key.slice32(1), key.slice32(0));
   MUTEX_RELEASE(writer_lock);
   SET_HANDLER(&CacheVC::openReadFromWriterMain);
   CACHE_INCREMENT_DYN_STAT(cache_read_busy_success_stat);
@@ -465,11 +465,11 @@ CacheVC::openReadFromWriterMain(int /* event ATS_UNUSED */, Event * /* e ATS_UNU
   if (ntodo <= 0)
     return EVENT_CONT;
   if (length < ((int64_t)doc_len) - vio.ndone) {
-    DDebug("cache_read_agg", "truncation %X", first_key.word(1));
+    DDebug("cache_read_agg", "truncation %X", first_key.slice32(1));
     if (is_action_tag_set("cache")) {
       ink_release_assert(false);
     }
-    Warning("Document %X truncated at %d of %d, reading from writer", first_key.word(1), (int)vio.ndone, (int)doc_len);
+    Warning("Document %X truncated at %d of %d, reading from writer", first_key.slice32(1), (int)vio.ndone, (int)doc_len);
     return calluser(VC_EVENT_ERROR);
   }
   /* its possible that the user did a do_io_close before
@@ -544,9 +544,9 @@ CacheVC::openReadReadDone(int event, Event * e)
       if (doc->magic != DOC_MAGIC) {
         char tmpstring[100];
         if (doc->magic == DOC_CORRUPT)
-          Warning("Middle: Doc checksum does not match for %s", key.string(tmpstring));
+          Warning("Middle: Doc checksum does not match for %s", key.toHexStr(tmpstring));
         else
-          Warning("Middle: Doc magic does not match for %s", key.string(tmpstring));
+          Warning("Middle: Doc magic does not match for %s", key.toHexStr(tmpstring));
 #if TS_USE_INTERIM_CACHE == 1
         if (dir_ininterim(&dir)) {
           dir_delete(&key, vol, &dir);
@@ -587,23 +587,23 @@ Lread:
           if (dir_offset(&dir) == dir_offset(&earliest_dir)) {
 #endif
             DDebug("cache_read_agg", "%p: key: %X ReadRead complete: %d",
-                  this, first_key.word(1), (int)vio.ndone);
+                  this, first_key.slice32(1), (int)vio.ndone);
             doc_len = vio.ndone;
             goto Ldone;
           }
         }
         DDebug("cache_read_agg", "%p: key: %X ReadRead writer aborted: %d",
-              this, first_key.word(1), (int)vio.ndone);
+              this, first_key.slice32(1), (int)vio.ndone);
         goto Lerror;
       }
-      DDebug("cache_read_agg", "%p: key: %X ReadRead retrying: %d", this, first_key.word(1), (int)vio.ndone);
+      DDebug("cache_read_agg", "%p: key: %X ReadRead retrying: %d", this, first_key.slice32(1), (int)vio.ndone);
       VC_SCHED_WRITER_RETRY(); // wait for writer
     }
     // fall through for truncated documents
   }
 Lerror:
   char tmpstring[100];
-  Warning("Document %s truncated", earliest_key.string(tmpstring));
+  Warning("Document %s truncated", earliest_key.toHexStr(tmpstring));
   return calluser(VC_EVENT_ERROR);
 Ldone:
   return calluser(VC_EVENT_EOS);
@@ -752,22 +752,22 @@ Lread: {
         while (dir_probe(&earliest_key, vol, &dir, &last_collision)) {
           if (dir_offset(&dir) == dir_offset(&earliest_dir)) {
             DDebug("cache_read_agg", "%p: key: %X ReadMain complete: %d",
-                  this, first_key.word(1), (int)vio.ndone);
+                  this, first_key.slice32(1), (int)vio.ndone);
             doc_len = vio.ndone;
             goto Leos;
           }
         }
         DDebug("cache_read_agg", "%p: key: %X ReadMain writer aborted: %d",
-              this, first_key.word(1), (int)vio.ndone);
+              this, first_key.slice32(1), (int)vio.ndone);
         goto Lerror;
       }
-      DDebug("cache_read_agg", "%p: key: %X ReadMain retrying: %d", this, first_key.word(1), (int)vio.ndone);
+      DDebug("cache_read_agg", "%p: key: %X ReadMain retrying: %d", this, first_key.slice32(1), (int)vio.ndone);
       SET_HANDLER(&CacheVC::openReadMain);
       VC_SCHED_WRITER_RETRY();
     }
     if (is_action_tag_set("cache"))
       ink_release_assert(false);
-    Warning("Document %X truncated at %d of %d, missing fragment %X", first_key.word(1), (int)vio.ndone, (int)doc_len, key.word(1));
+    Warning("Document %X truncated at %d of %d, missing fragment %X", first_key.slice32(1), (int)vio.ndone, (int)doc_len, key.slice32(1));
     // remove the directory entry
     dir_delete(&earliest_key, vol, &earliest_dir);
   }
@@ -815,9 +815,9 @@ CacheVC::openReadStartEarliest(int /* event ATS_UNUSED */, Event * /* e ATS_UNUS
         ink_release_assert(false);
       }
       if (doc->magic == DOC_CORRUPT)
-        Warning("Earliest: Doc checksum does not match for %s", key.string(tmpstring));
+        Warning("Earliest: Doc checksum does not match for %s", key.toHexStr(tmpstring));
       else
-        Warning("Earliest : Doc magic does not match for %s", key.string(tmpstring));
+        Warning("Earliest : Doc magic does not match for %s", key.toHexStr(tmpstring));
       // remove the dir entry
       dir_delete(&key, vol, &dir);
       // try going through the directory entries again
@@ -911,7 +911,7 @@ Lread:
             od->move_resident_alt = 1;
             od->single_doc_key = doc1->key;
             dir_assign(&od->single_doc_dir, &dir);
-            dir_set_tag(&od->single_doc_dir, od->single_doc_key.word(2));
+            dir_set_tag(&od->single_doc_dir, od->single_doc_key.slice32(2));
           }
           SET_HANDLER(&CacheVC::openReadVecWrite);
           if ((ret = do_write_call()) == EVENT_RETURN)
@@ -1031,9 +1031,9 @@ CacheVC::openReadStartHead(int event, Event * e)
         ink_release_assert(false);
       }
       if (doc->magic == DOC_CORRUPT)
-        Warning("Head: Doc checksum does not match for %s", key.string(tmpstring));
+        Warning("Head: Doc checksum does not match for %s", key.toHexStr(tmpstring));
       else
-        Warning("Head : Doc magic does not match for %s", key.string(tmpstring));
+        Warning("Head : Doc magic does not match for %s", key.toHexStr(tmpstring));
       // remove the dir entry
       dir_delete(&key, vol, &dir);
       // try going through the directory entries again
@@ -1079,7 +1079,7 @@ CacheVC::openReadStartHead(int event, Event * e)
                "unmarshalled %d expecting %d in %d (base=%d, flen=%d) "
                "- vector n=%d size=%d"
                "first alt=%d[%s]"
-               , key.word(0)
+               , key.slice32(0)
                , uml, doc->hlen, doc->len, sizeofDoc, doc->_flen
                , vector.count(), alt_length
                , alt->m_magic
@@ -1104,7 +1104,7 @@ CacheVC::openReadStartHead(int event, Event * e)
       alternate_tmp = vector.get(alternate_index);
       if (!alternate_tmp->valid()) {
         if (buf) {
-          Note("OpenReadHead failed for cachekey %X : alternate inconsistency", key.word(0));
+          Note("OpenReadHead failed for cachekey %X : alternate inconsistency", key.slice32(0));
           dir_delete(&key, vol, &dir);
         }
         goto Ldone;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/iocore/cache/CacheTest.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/CacheTest.cc b/iocore/cache/CacheTest.cc
index 3c601ca..2bb1194 100644
--- a/iocore/cache/CacheTest.cc
+++ b/iocore/cache/CacheTest.cc
@@ -446,7 +446,7 @@ REGRESSION_TEST(cache_disk_replacement_stability)(RegressionTest *t, int level,
     vols[i].len = DEFAULT_STRIPE_SIZE;
     snprintf(buff, sizeof(buff), "/dev/sd%c %" PRIu64 ":%" PRIu64,
              'a' + i, DEFAULT_SKIP, vols[i].len);
-    vols[i].hash_id_md5.encodeBuffer(buff, strlen(buff));
+    MD5Context().hash_immediate(vols[i].hash_id, buff, strlen(buff));
   }
 
   hr1.vol_hash_table = 0;
@@ -462,7 +462,7 @@ REGRESSION_TEST(cache_disk_replacement_stability)(RegressionTest *t, int level,
   sample->len = 1024ULL * 1024 * 1024 * (1024+128); // 1.1 TB
   snprintf(buff, sizeof(buff), "/dev/sd%c %" PRIu64 ":%" PRIu64,
            'a' + sample_idx, DEFAULT_SKIP, sample->len);
-  sample->hash_id_md5.encodeBuffer(buff, strlen(buff));
+  MD5Context().hash_immediate(sample->hash_id, buff, strlen(buff));
   build_vol_hash_table(&hr2);
 
   // See what the difference is

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/iocore/cache/CacheVol.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/CacheVol.cc b/iocore/cache/CacheVol.cc
index 9fb690c..07d6199 100644
--- a/iocore/cache/CacheVol.cc
+++ b/iocore/cache/CacheVol.cc
@@ -438,7 +438,7 @@ CacheVC::scanOpenWrite(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */)
     dir_assign(&od->first_dir, &dir);
     if (doc->total_len) {
       dir_assign(&od->single_doc_dir, &dir);
-      dir_set_tag(&od->single_doc_dir, doc->key.word(2));
+      dir_set_tag(&od->single_doc_dir, doc->key.slice32(2));
       od->single_doc_key = doc->key;
       od->move_resident_alt = 1;
     }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/iocore/cache/CacheWrite.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/CacheWrite.cc b/iocore/cache/CacheWrite.cc
index ee2160f..7108fde 100644
--- a/iocore/cache/CacheWrite.cc
+++ b/iocore/cache/CacheWrite.cc
@@ -42,7 +42,7 @@ get_alternate_index(CacheHTTPInfoVector *cache_vector, CacheKey key)
   for (int i = 0; i < alt_count; i++) {
     obj = cache_vector->get(i);
     if (obj->compare_object_key(&key)) {
-      // Debug("cache_key", "Resident alternate key  %X", key.word(0));
+      // Debug("cache_key", "Resident alternate key  %X", key.slice32(0));
       return i;
     }
   }
@@ -126,7 +126,7 @@ CacheVC::updateVector(int /* event ATS_UNUSED */, Event */* e ATS_UNUSED */)
         f.rewrite_resident_alt = 1;
         write_len = doc->data_len();
         Debug("cache_update_alt",
-              "rewriting resident alt size: %d key: %X, first_key: %X", write_len, doc->key.word(0), first_key.word(0));
+              "rewriting resident alt size: %d key: %X, first_key: %X", write_len, doc->key.slice32(0), first_key.slice32(0));
       }
     }
     header_len = write_vector->marshal_length();
@@ -260,7 +260,7 @@ Vol::force_evacuate_head(Dir *evac_dir, int pinned)
   }
   b->f.pinned = pinned;
   b->f.evacuate_head = 1;
-  b->evac_frags.key.set(0, 0);  // ensure that the block gets
+  b->evac_frags.key = zero_key;  // ensure that the block gets
   // evacuated no matter what
   b->readers = 0;             // ensure that the block does not disappear
   return b;
@@ -319,7 +319,7 @@ Vol::aggWriteDone(int event, Event *e)
     header->write_pos += io.aiocb.aio_nbytes;
     ink_assert(header->write_pos >= start);
     DDebug("cache_agg", "Dir %s, Write: %" PRIu64 ", last Write: %" PRIu64 "\n",
-          hash_id, header->write_pos, header->last_write_pos);
+          hash_text, header->write_pos, header->last_write_pos);
     ink_assert(header->write_pos == header->agg_pos);
     if (header->write_pos + EVACUATION_SIZE > scan_pos)
       periodic_scan();
@@ -330,7 +330,7 @@ Vol::aggWriteDone(int event, Event *e)
     // for fragments is this aggregation buffer
     Debug("cache_disk_error", "Write error on disk %s\n \
               write range : [%" PRIu64 " - %" PRIu64 " bytes]  [%" PRIu64 " - %" PRIu64 " blocks] \n",
-          hash_id, (uint64_t)io.aiocb.aio_offset,
+          hash_text, (uint64_t)io.aiocb.aio_offset,
           (uint64_t)io.aiocb.aio_offset + io.aiocb.aio_nbytes,
           (uint64_t)io.aiocb.aio_offset / CACHE_BLOCK_SIZE,
           (uint64_t)(io.aiocb.aio_offset + io.aiocb.aio_nbytes) / CACHE_BLOCK_SIZE);
@@ -412,7 +412,7 @@ CacheVC::evacuateReadHead(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */
     alternate_tmp = vector.get(alternate_index);
     doc_len = alternate_tmp->object_size_get();
     Debug("cache_evac", "evacuateReadHead http earliest %X first: %X len: %" PRId64,
-          first_key.word(0), earliest_key.word(0), doc_len);
+          first_key.slice32(0), earliest_key.slice32(0), doc_len);
   } else
 #endif
   {
@@ -423,7 +423,7 @@ CacheVC::evacuateReadHead(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */
       goto Ldone;
     doc_len = doc->total_len;
     DDebug("cache_evac",
-          "evacuateReadHead non-http earliest %X first: %X len: %" PRId64, first_key.word(0), earliest_key.word(0), doc_len);
+          "evacuateReadHead non-http earliest %X first: %X len: %" PRId64, first_key.slice32(0), earliest_key.slice32(0), doc_len);
   }
   if (doc_len == total_len) {
     // the whole document has been evacuated. Insert the directory
@@ -450,7 +450,7 @@ CacheVC::evacuateDocDone(int /* event ATS_UNUSED */, Event */* e ATS_UNUSED */)
   ink_assert(vol->mutex->thread_holding == this_ethread());
   Doc *doc = (Doc *) buf->data();
   DDebug("cache_evac", "evacuateDocDone %X o %d p %d new_o %d new_p %d",
-        (int) key.word(0), (int) dir_offset(&overwrite_dir),
+        (int) key.slice32(0), (int) dir_offset(&overwrite_dir),
         (int) dir_phase(&overwrite_dir), (int) dir_offset(&dir), (int) dir_phase(&dir));
   int i = dir_evac_bucket(&overwrite_dir);
   // nasty beeping race condition, need to have the EvacuationBlock here
@@ -474,7 +474,7 @@ CacheVC::evacuateDocDone(int /* event ATS_UNUSED */, Event */* e ATS_UNUSED */)
           break;
         if (evac->earliest_key.fold()) {
           DDebug("cache_evac", "evacdocdone: evacuating key %X earliest %X",
-                evac->key.word(0), evac->earliest_key.word(0));
+                evac->key.slice32(0), evac->earliest_key.slice32(0));
           EvacuationBlock *eblock = 0;
           Dir dir_tmp;
           dir_lookaside_probe(&evac->earliest_key, vol, &dir_tmp, &eblock);
@@ -497,16 +497,16 @@ CacheVC::evacuateDocDone(int /* event ATS_UNUSED */, Event */* e ATS_UNUSED */)
       if (dir_head(&overwrite_dir) && b->f.evacuate_head) {
         DDebug("cache_evac",
               "evacuateDocDone evacuate_head %X %X hlen %d offset %d",
-              (int) key.word(0), (int) doc->key.word(0), doc->hlen, (int) dir_offset(&overwrite_dir));
+              (int) key.slice32(0), (int) doc->key.slice32(0), doc->hlen, (int) dir_offset(&overwrite_dir));
 
         if (dir_compare_tag(&overwrite_dir, &doc->first_key)) {
           OpenDirEntry *cod;
           DDebug("cache_evac", "evacuating vector: %X %d",
-                (int) doc->first_key.word(0), (int) dir_offset(&overwrite_dir));
+                (int) doc->first_key.slice32(0), (int) dir_offset(&overwrite_dir));
           if ((cod = vol->open_read(&doc->first_key))) {
             // writer  exists
             DDebug("cache_evac", "overwriting the open directory %X %d %d",
-                  (int) doc->first_key.word(0), (int) dir_offset(&cod->first_dir), (int) dir_offset(&dir));
+                  (int) doc->first_key.slice32(0), (int) dir_offset(&cod->first_dir), (int) dir_offset(&dir));
             cod->first_dir = dir;
 
           }
@@ -515,7 +515,7 @@ CacheVC::evacuateDocDone(int /* event ATS_UNUSED */, Event */* e ATS_UNUSED */)
             vol->ram_cache->fixup(&doc->first_key, (uint32_t)(o >> 32), (uint32_t)o, (uint32_t)(n >> 32), (uint32_t)n);
           }
         } else {
-          DDebug("cache_evac", "evacuating earliest: %X %d", (int) doc->key.word(0), (int) dir_offset(&overwrite_dir));
+          DDebug("cache_evac", "evacuating earliest: %X %d", (int) doc->key.slice32(0), (int) dir_offset(&overwrite_dir));
           ink_assert(dir_compare_tag(&overwrite_dir, &doc->key));
           ink_assert(b->earliest_evacuator == this);
           total_len += doc->data_len();
@@ -573,7 +573,7 @@ evacuate_fragments(CacheKey *key, CacheKey *earliest_key, int force, Vol *vol)
       b->readers = 0;
     DDebug("cache_evac",
           "next fragment %X Earliest: %X offset %d phase %d force %d",
-          (int) key->word(0), (int) earliest_key->word(0), (int) dir_offset(&dir), (int) dir_phase(&dir), force);
+          (int) key->slice32(0), (int) earliest_key->slice32(0), (int) dir_offset(&dir), (int) dir_phase(&dir), force);
   }
   return i;
 }
@@ -614,7 +614,7 @@ Vol::evacuateDocReadDone(int event, Event *e)
     goto Ldone;
   }
   DDebug("cache_evac", "evacuateDocReadDone %X offset %d",
-        (int) doc->key.word(0), (int) dir_offset(&doc_evacuator->overwrite_dir));
+        (int) doc->key.slice32(0), (int) dir_offset(&doc_evacuator->overwrite_dir));
 
   b = evacuate[dir_evac_bucket(&doc_evacuator->overwrite_dir)].head;
   while (b) {
@@ -635,7 +635,7 @@ Vol::evacuateDocReadDone(int event, Event *e)
       doc_evacuator->key = doc->first_key;
       b->evac_frags.key = doc->first_key;
       DDebug("cache_evac", "evacuating vector %X offset %d",
-            (int) doc->first_key.word(0), (int) dir_offset(&doc_evacuator->overwrite_dir));
+            (int) doc->first_key.slice32(0), (int) dir_offset(&doc_evacuator->overwrite_dir));
       b->f.unused = 57;
     } else {
       // if its an earliest fragment (alternate) evacuation, things get
@@ -648,7 +648,7 @@ Vol::evacuateDocReadDone(int event, Event *e)
       b->evac_frags.earliest_key = doc->key;
       b->earliest_evacuator = doc_evacuator;
       DDebug("cache_evac", "evacuating earliest %X %X evac: %p offset: %d",
-            (int) b->evac_frags.key.word(0), (int) doc->key.word(0),
+            (int) b->evac_frags.key.slice32(0), (int) doc->key.slice32(0),
             doc_evacuator, (int) dir_offset(&doc_evacuator->overwrite_dir));
       b->f.unused = 67;
     }
@@ -663,7 +663,7 @@ Vol::evacuateDocReadDone(int event, Event *e)
     doc_evacuator->key = ek->key;
     doc_evacuator->earliest_key = ek->earliest_key;
     DDebug("cache_evac", "evacuateDocReadDone key: %X earliest: %X",
-          (int) ek->key.word(0), (int) ek->earliest_key.word(0));
+          (int) ek->key.slice32(0), (int) ek->earliest_key.slice32(0));
     b->f.unused = 87;
   }
   // if the tag in the c->dir does match the first_key in the
@@ -891,7 +891,7 @@ Vol::evacuate_cleanup_blocks(int i)
          (header->phase == dir_phase(&b->dir) && header->write_pos <= vol_offset(this, &b->dir)))) {
       EvacuationBlock *x = b;
       DDebug("cache_evac", "evacuate cleanup free %X offset %d",
-            (int) b->evac_frags.key.word(0), (int) dir_offset(&b->dir));
+            (int) b->evac_frags.key.slice32(0), (int) dir_offset(&b->dir));
       b = b->link.next;
       evacuate[i].remove(x);
       free_EvacuationBlock(x, mutex->thread_holding);
@@ -977,7 +977,7 @@ Lagain:
         header->write_pos + agg_buf_pos + writelen > (skip + len))
       break;
     DDebug("agg_read", "copying: %d, %" PRIu64 ", key: %d",
-          agg_buf_pos, header->write_pos + agg_buf_pos, c->first_key.word(0));
+          agg_buf_pos, header->write_pos + agg_buf_pos, c->first_key.slice32(0));
     int wrotelen = agg_copy(agg_buffer + agg_buf_pos, c);
     ink_assert(writelen == wrotelen);
     agg_todo_size -= writelen;
@@ -1096,14 +1096,14 @@ CacheVC::openWriteCloseDir(int /* event ATS_UNUSED */, Event */* e ATS_UNUSED */
     if (f.update && closed > 0) {
       if (!total_len && alternate_index != CACHE_ALT_REMOVED) {
         Debug("cache_update", "header only %d (%" PRIu64 ", %" PRIu64 ")\n",
-              DIR_MASK_TAG(first_key.word(2)), update_key.b[0], update_key.b[1]);
+              DIR_MASK_TAG(first_key.slice32(2)), update_key.b[0], update_key.b[1]);
 
       } else if (total_len && alternate_index != CACHE_ALT_REMOVED) {
         Debug("cache_update", "header body, %d, (%" PRIu64 ", %" PRIu64 "), (%" PRIu64 ", %" PRIu64 ")\n",
-              DIR_MASK_TAG(first_key.word(2)), update_key.b[0], update_key.b[1], earliest_key.b[0], earliest_key.b[1]);
+              DIR_MASK_TAG(first_key.slice32(2)), update_key.b[0], update_key.b[1], earliest_key.b[0], earliest_key.b[1]);
       } else if (!total_len && alternate_index == CACHE_ALT_REMOVED) {
         Debug("cache_update", "alt delete, %d, (%" PRIu64 ", %" PRIu64 ")\n",
-              DIR_MASK_TAG(first_key.word(2)), update_key.b[0], update_key.b[1]);
+              DIR_MASK_TAG(first_key.slice32(2)), update_key.b[0], update_key.b[1]);
       }
     }
   }
@@ -1169,7 +1169,7 @@ CacheVC::openWriteCloseHeadDone(int event, Event *e)
           od->single_doc_key = earliest_key;
         }
         dir_assign(&od->single_doc_dir, &dir);
-        dir_set_tag(&od->single_doc_dir, od->single_doc_key.word(2));
+        dir_set_tag(&od->single_doc_dir, od->single_doc_key.slice32(2));
       }
     }
   }
@@ -1331,7 +1331,7 @@ CacheVC::openWriteWriteDone(int event, Event *e)
     ++fragment;
     write_pos += write_len;
     dir_insert(&key, vol, &dir);
-    DDebug("cache_insert", "WriteDone: %X, %X, %d", key.word(0), first_key.word(0), write_len);
+    DDebug("cache_insert", "WriteDone: %X, %X, %d", key.slice32(0), first_key.slice32(0), write_len);
     blocks = iobufferblock_skip(blocks, &offset, &length, write_len);
     next_CacheKey(&key, &key);
   }
@@ -1533,7 +1533,7 @@ Lagain:
         od->move_resident_alt = 1;
         od->single_doc_key = doc->key;
         dir_assign(&od->single_doc_dir, &dir);
-        dir_set_tag(&od->single_doc_dir, od->single_doc_key.word(2));
+        dir_set_tag(&od->single_doc_dir, od->single_doc_key.slice32(2));
       }
       first_buf = buf;
       goto Lsuccess;
@@ -1644,7 +1644,7 @@ Cache::open_write(Continuation *cont, CacheKey *key, CacheFragType frag_type,
    */
   do {
     rand_CacheKey(&c->key, cont->mutex);
-  } while (DIR_MASK_TAG(c->key.word(2)) == DIR_MASK_TAG(c->first_key.word(2)));
+  } while (DIR_MASK_TAG(c->key.slice32(2)) == DIR_MASK_TAG(c->first_key.slice32(2)));
   c->earliest_key = c->key;
 #ifdef HTTP_CACHE
   c->info = 0;
@@ -1707,7 +1707,7 @@ Cache::open_write(Continuation *cont, CacheKey *key, CacheHTTPInfo *info, time_t
   do {
     rand_CacheKey(&c->key, cont->mutex);
   }
-  while (DIR_MASK_TAG(c->key.word(2)) == DIR_MASK_TAG(c->first_key.word(2)));
+  while (DIR_MASK_TAG(c->key.slice32(2)) == DIR_MASK_TAG(c->first_key.slice32(2)));
   c->earliest_key = c->key;
   c->frag_type = CACHE_FRAG_TYPE_HTTP;
   c->vol = key_to_vol(key, hostname, host_len);
@@ -1859,7 +1859,7 @@ Lagain:
       else
         dir_insert(&mts->key, vol, &mts->dir);
       DDebug("cache_insert", "InterimCache: WriteDone: key: %X, first_key: %X, write_len: %d, write_offset: %" PRId64 ", dir_last_word: %X",
-          doc->key.word(0), doc->first_key.word(0), mts->agg_len, o, mts->dir.w[4]);
+          doc->key.slice32(0), doc->first_key.slice32(0), mts->agg_len, o, mts->dir.w[4]);
 
       if (mts->copy) {
         mts->interim_vol->vol->ram_cache->fixup(&mts->key, (uint32_t)(old_off >> 32), (uint32_t)old_off,

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/iocore/cache/P_CacheDir.h
----------------------------------------------------------------------
diff --git a/iocore/cache/P_CacheDir.h b/iocore/cache/P_CacheDir.h
index 013698a..638051c 100644
--- a/iocore/cache/P_CacheDir.h
+++ b/iocore/cache/P_CacheDir.h
@@ -289,7 +289,7 @@ struct OpenDir: public Continuation
 
   int open_write(CacheVC *c, int allow_if_writers, int max_writers);
   int close_write(CacheVC *c);
-  OpenDirEntry *open_read(INK_MD5 *key);
+  OpenDirEntry *open_read(CryptoHash *key);
   int signal_readers(int event, Event *e);
 
   OpenDir();
@@ -347,7 +347,7 @@ extern Dir empty_dir;
 TS_INLINE bool
 dir_compare_tag(Dir *e, CacheKey *key)
 {
-  return (dir_tag(e) == DIR_MASK_TAG(key->word(2)));
+  return (dir_tag(e) == DIR_MASK_TAG(key->slice32(2)));
 }
 
 TS_INLINE Dir *

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/iocore/cache/P_CacheHosting.h
----------------------------------------------------------------------
diff --git a/iocore/cache/P_CacheHosting.h b/iocore/cache/P_CacheHosting.h
index 5d1e793..ce376cc 100644
--- a/iocore/cache/P_CacheHosting.h
+++ b/iocore/cache/P_CacheHosting.h
@@ -80,7 +80,7 @@ public:
   CacheHostMatcher(const char * name, CacheType typ);
   ~CacheHostMatcher();
 
-  void Match(char *rdata, int rlen, CacheHostResult *result);
+  void Match(char const* rdata, int rlen, CacheHostResult *result);
   void AllocateSpace(int num_entries);
   void NewEntry(matcher_line *line_info);
   void Print();
@@ -107,7 +107,7 @@ public:
    ~CacheHostTable();
   int BuildTable(const char * config_file_path);
   int BuildTableFromString(const char * config_file_path, char *str);
-  void Match(char *rdata, int rlen, CacheHostResult *result);
+  void Match(char const* rdata, int rlen, CacheHostResult *result);
   void Print();
 
   int getEntryCount() const { return m_numEntries; }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/iocore/cache/P_CacheInternal.h
----------------------------------------------------------------------
diff --git a/iocore/cache/P_CacheInternal.h b/iocore/cache/P_CacheInternal.h
index 3b8987e..5afac60 100644
--- a/iocore/cache/P_CacheInternal.h
+++ b/iocore/cache/P_CacheInternal.h
@@ -1020,7 +1020,7 @@ struct Cache
   int open(bool reconfigure, bool fix);
   int close();
 
-  Action *lookup(Continuation *cont, CacheKey *key, CacheFragType type, char *hostname, int host_len);
+  Action *lookup(Continuation *cont, CacheKey *key, CacheFragType type, char const* hostname, int host_len);
   inkcoreapi Action *open_read(Continuation *cont, CacheKey *key, CacheFragType type, char *hostname, int len);
   inkcoreapi Action *open_write(Continuation *cont, CacheKey *key,
                                 CacheFragType frag_type, int options = 0,
@@ -1055,7 +1055,7 @@ struct Cache
 
   int open_done();
 
-  Vol *key_to_vol(CacheKey *key, char *hostname, int host_len);
+  Vol *key_to_vol(CacheKey *key, char const* hostname, int host_len);
 
   Cache()
     : cache_read_done(0), total_good_nvol(0), total_nvol(0), ready(CACHE_INITIALIZING), cache_size(0),  // in store block size
@@ -1074,7 +1074,7 @@ Cache::open_read(Continuation *cont, CacheURL *url, CacheHTTPHdr *request,
 {
   INK_MD5 md5;
   int len;
-  url->MD5_get(&md5);
+  url->hash_get(&md5);
   const char *hostname = url->host_get(&len);
   return open_read(cont, &md5, request, params, type, (char *) hostname, len);
 }
@@ -1082,7 +1082,7 @@ Cache::open_read(Continuation *cont, CacheURL *url, CacheHTTPHdr *request,
 TS_INLINE void
 Cache::generate_key(INK_MD5 *md5, URL *url)
 {
-  url->MD5_get(md5);
+  url->hash_get(md5);
 }
 
 TS_INLINE Action *
@@ -1091,7 +1091,7 @@ Cache::open_write(Continuation *cont, CacheURL *url, CacheHTTPHdr *request,
 {
   (void) request;
   INK_MD5 url_md5;
-  url->MD5_get(&url_md5);
+  url->hash_get(&url_md5);
   int len;
   const char *hostname = url->host_get(&len);
 
@@ -1229,7 +1229,7 @@ CacheProcessor::lookup(Continuation *cont, URL *url, bool cluster_cache_local, b
 {
   (void) local_only;
   INK_MD5 md5;
-  url->MD5_get(&md5);
+  url->hash_get(&md5);
   int host_len = 0;
   const char *hostname = url->host_get(&host_len);
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/iocore/cache/P_CacheVol.h
----------------------------------------------------------------------
diff --git a/iocore/cache/P_CacheVol.h b/iocore/cache/P_CacheVol.h
index ecf2d41..7c8ea0e 100644
--- a/iocore/cache/P_CacheVol.h
+++ b/iocore/cache/P_CacheVol.h
@@ -124,8 +124,8 @@ struct VolHeaderFooter
 struct EvacuationKey
 {
   SLink<EvacuationKey> link;
-  INK_MD5 key;
-  INK_MD5 earliest_key;
+  CryptoHash key;
+  CryptoHash earliest_key;
 };
 
 struct EvacuationBlock
@@ -236,9 +236,9 @@ struct AccessHistory {
     return tail;
   }
 
-  void set_in_progress(INK_MD5 *key) {
-    uint32_t key_index = key->word(3);
-    uint16_t tag = (uint16_t) key->word(1);
+  void set_in_progress(CryptoHash *key) {
+    uint32_t key_index = key->slice32(3);
+    uint16_t tag = static_cast<uint16_t>(key->slice32(1));
     unsigned int hash_index = (uint32_t) (key_index % hash_size);
 
     uint32_t index = hash[hash_index];
@@ -248,9 +248,9 @@ struct AccessHistory {
     }
   }
 
-  void set_not_in_progress(INK_MD5 *key) {
-    uint32_t key_index = key->word(3);
-    uint16_t tag = (uint16_t) key->word(1);
+  void set_not_in_progress(CryptoHash *key) {
+    uint32_t key_index = key->slice32(3);
+    uint16_t tag = static_cast<uint16_t>(key->slice32(1));
     unsigned int hash_index = (uint32_t) (key_index % hash_size);
 
     uint32_t index = hash[hash_index];
@@ -260,9 +260,9 @@ struct AccessHistory {
     }
   }
 
-  void put_key(INK_MD5 *key) {
-    uint32_t key_index = key->word(3);
-    uint16_t tag = (uint16_t) key->word(1);
+  void put_key(CryptoHash *key) {
+    uint32_t key_index = key->slice32(3);
+    uint16_t tag = static_cast<uint16_t>(key->slice32(1));
     unsigned int hash_index = (uint32_t) (key_index % hash_size);
 
     uint32_t index = hash[hash_index];
@@ -292,11 +292,11 @@ struct AccessHistory {
     }
   }
 
-  bool remove_key(INK_MD5 *key) {
-    unsigned int hash_index = (uint32_t) (key->word(3) % hash_size);
+  bool remove_key(CryptoHash *key) {
+    unsigned int hash_index = static_cast<uint32_t>(key->slice32(3) % hash_size);
     uint32_t index = hash[hash_index];
     AccessEntry *entry = &base[index];
-    if (index != 0 && entry->item.tag == (uint16_t)key->word(1) && entry->item.index == key->word(3)) {
+    if (index != 0 && entry->item.tag == static_cast<uint16_t>(key->slice32(1)) && entry->item.index == key->slice32(3)) {
       remove(entry);
       freeEntry(entry);
       return true;
@@ -304,9 +304,9 @@ struct AccessHistory {
     return false;
   }
 
-  bool is_hot(INK_MD5 *key) {
-    uint32_t key_index = key->word(3);
-    uint16_t tag = (uint16_t) key->word(1);
+  bool is_hot(CryptoHash *key) {
+    uint32_t key_index = key->slice32(3);
+    uint16_t tag = (uint16_t) key->slice32(1);
     unsigned int hash_index = (uint32_t) (key_index % hash_size);
 
     uint32_t index = hash[hash_index];
@@ -414,8 +414,8 @@ void dir_clean_interimvol(InterimCacheVol *d);
 struct Vol: public Continuation
 {
   char *path;
-  char *hash_id;
-  INK_MD5 hash_id_md5;
+  char *hash_text;
+  CryptoHash hash_id;
   int fd;
 
   char *raw_dir;
@@ -477,7 +477,7 @@ struct Vol: public Continuation
 
 
   bool migrate_probe(CacheKey *key, MigrateToInterimCache **result) {
-    uint32_t indx = key->word(3) % MIGRATE_BUCKETS;
+    uint32_t indx = key->slice32(3) % MIGRATE_BUCKETS;
     MigrateToInterimCache *m = mig_hash[indx].head;
     while (m != NULL && !(m->key == *key)) {
       m = mig_hash[indx].next(m);
@@ -516,8 +516,8 @@ struct Vol: public Continuation
   int begin_read_lock(CacheVC *cont);
   // unused read-write interlock code
   // currently http handles a write-lock failure by retrying the read
-  OpenDirEntry *open_read(INK_MD5 *key);
-  OpenDirEntry *open_read_lock(INK_MD5 *key, EThread *t);
+  OpenDirEntry *open_read(CryptoHash *key);
+  OpenDirEntry *open_read_lock(CryptoHash *key, EThread *t);
   int close_read(CacheVC *cont);
   int close_read_lock(CacheVC *cont);
 
@@ -625,8 +625,8 @@ struct Doc
   uint32_t magic;         // DOC_MAGIC
   uint32_t len;           // length of this segment (including hlen, flen & sizeof(Doc), unrounded)
   uint64_t total_len;     // total length of document
-  INK_MD5 first_key;    // first key in document (http: vector)
-  INK_MD5 key;
+  CryptoHash first_key;    // first key in document (http: vector)
+  CryptoHash key;
   uint32_t hlen;          // header length
   uint32_t ftype:8;       // fragment type CACHE_FRAG_TYPE_XX
   uint32_t _flen:24;       // fragment table length [amc] NOT USED
@@ -849,7 +849,7 @@ free_EvacuationBlock(EvacuationBlock *b, EThread *t)
 }
 
 TS_INLINE OpenDirEntry *
-Vol::open_read(INK_MD5 *key)
+Vol::open_read(CryptoHash *key)
 {
   return open_dir.open_read(key);
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/iocore/cache/RamCacheCLFUS.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/RamCacheCLFUS.cc b/iocore/cache/RamCacheCLFUS.cc
index bcdfc98..f7781de 100644
--- a/iocore/cache/RamCacheCLFUS.cc
+++ b/iocore/cache/RamCacheCLFUS.cc
@@ -156,7 +156,7 @@ RamCacheCLFUS::resize_hashtable()
     for (int64_t i = 0; i < nbuckets; i++) {
       RamCacheCLFUSEntry *e = 0;
       while ((e = bucket[i].pop()))
-        new_bucket[e->key.word(3) % anbuckets].push(e);
+        new_bucket[e->key.slice32(3) % anbuckets].push(e);
     }
     ats_free(bucket);
   }
@@ -204,7 +204,7 @@ RamCacheCLFUS::get(INK_MD5 *key, Ptr<IOBufferData> *ret_data, uint32_t auxkey1,
 {
   if (!max_bytes)
     return 0;
-  int64_t i = key->word(3) % nbuckets;
+  int64_t i = key->slice32(3) % nbuckets;
   RamCacheCLFUSEntry *e = bucket[i].head;
   char *b = 0;
   while (e) {
@@ -264,25 +264,25 @@ RamCacheCLFUS::get(INK_MD5 *key, Ptr<IOBufferData> *ret_data, uint32_t auxkey1,
           (*ret_data) = data;
         }
         CACHE_SUM_DYN_STAT_THREAD(cache_ram_cache_hits_stat, 1);
-        DDebug("ram_cache", "get %X %d %d size %d HIT", key->word(3), auxkey1, auxkey2, e->size);
+        DDebug("ram_cache", "get %X %d %d size %d HIT", key->slice32(3), auxkey1, auxkey2, e->size);
         return 1;
       } else {
         CACHE_SUM_DYN_STAT_THREAD(cache_ram_cache_misses_stat, 1);
-        DDebug("ram_cache", "get %X %d %d HISTORY", key->word(3), auxkey1, auxkey2);
+        DDebug("ram_cache", "get %X %d %d HISTORY", key->slice32(3), auxkey1, auxkey2);
         return 0;
       }
     }
     assert(e != e->hash_link.next);
     e = e->hash_link.next;
   }
-  DDebug("ram_cache", "get %X %d %d MISS", key->word(3), auxkey1, auxkey2);
+  DDebug("ram_cache", "get %X %d %d MISS", key->slice32(3), auxkey1, auxkey2);
 Lerror:
   CACHE_SUM_DYN_STAT_THREAD(cache_ram_cache_misses_stat, 1);
   return 0;
 Lfailed:
   ats_free(b);
   destroy(e);
-  DDebug("ram_cache", "get %X %d %d Z_ERR", key->word(3), auxkey1, auxkey2);
+  DDebug("ram_cache", "get %X %d %d Z_ERR", key->slice32(3), auxkey1, auxkey2);
   goto Lerror;
 }
 
@@ -302,9 +302,9 @@ void RamCacheCLFUS::tick() {
 Lfree:
   e->flag_bits.lru = 0;
   history--;
-  uint32_t b = e->key.word(3) % nbuckets;
+  uint32_t b = e->key.slice32(3) % nbuckets;
   bucket[b].remove(e);
-  DDebug("ram_cache", "put %X %d %d size %d FREED", e->key.word(3), e->auxkey1, e->auxkey2, e->size);
+  DDebug("ram_cache", "put %X %d %d size %d FREED", e->key.slice32(3), e->auxkey1, e->auxkey2, e->size);
   THREAD_FREE(e, ramCacheCLFUSEntryAllocator, this_thread());
 }
 
@@ -312,7 +312,7 @@ void
 RamCacheCLFUS::victimize(RamCacheCLFUSEntry *e)
 {
   objects--;
-  DDebug("ram_cache", "put %X %d %d size %d VICTIMIZED", e->key.word(3), e->auxkey1, e->auxkey2, e->size);
+  DDebug("ram_cache", "put %X %d %d size %d VICTIMIZED", e->key.slice32(3), e->auxkey1, e->auxkey2, e->size);
   e->data = NULL;
   e->flag_bits.lru = 1;
   lru[1].enqueue(e);
@@ -345,9 +345,9 @@ RamCacheCLFUS::destroy(RamCacheCLFUSEntry *e)
     e->data = NULL;
   } else
     history--;
-  uint32_t b = e->key.word(3) % nbuckets;
+  uint32_t b = e->key.slice32(3) % nbuckets;
   bucket[b].remove(e);
-  DDebug("ram_cache", "put %X %d %d DESTROYED", e->key.word(3), e->auxkey1, e->auxkey2);
+  DDebug("ram_cache", "put %X %d %d DESTROYED", e->key.slice32(3), e->auxkey1, e->auxkey2);
   THREAD_FREE(e, ramCacheCLFUSEntryAllocator, this_thread());
   return ret;
 }
@@ -424,7 +424,7 @@ RamCacheCLFUS::compress_entries(EThread *thread, int do_at_most)
       MUTEX_TAKE_LOCK(vol->mutex, thread);
       // see if the entry is till around
       {
-        uint32_t i = key.word(3) % nbuckets;
+        uint32_t i = key.slice32(3) % nbuckets;
         RamCacheCLFUSEntry *ee = bucket[i].head;
         while (ee) {
           if (ee->key == key && ee->data == edata) break;
@@ -472,7 +472,7 @@ RamCacheCLFUS::compress_entries(EThread *thread, int do_at_most)
     e->flag_bits.incompressible = 1;
   Lcontinue:;
     DDebug("ram_cache", "compress %X %d %d %d %d %d %d %d",
-           e->key.word(3), e->auxkey1, e->auxkey2,
+           e->key.slice32(3), e->auxkey1, e->auxkey2,
            e->flag_bits.incompressible, e->flag_bits.compressed,
            e->len, e->compressed_len, ncompressed);
     if (!e->lru_link.next)
@@ -501,7 +501,7 @@ RamCacheCLFUS::put(INK_MD5 *key, IOBufferData *data, uint32_t len, bool copy, ui
 {
   if (!max_bytes)
     return 0;
-  uint32_t i = key->word(3) % nbuckets;
+  uint32_t i = key->slice32(3) % nbuckets;
   RamCacheCLFUSEntry *e = bucket[i].head;
   uint32_t size = copy ? len : data->block_size();
   while (e) {
@@ -537,7 +537,7 @@ RamCacheCLFUS::put(INK_MD5 *key, IOBufferData *data, uint32_t len, bool copy, ui
       check_accounting(this);
       e->flag_bits.copy = copy;
       e->flag_bits.compressed = 0;
-      DDebug("ram_cache", "put %X %d %d size %d HIT", key->word(3), auxkey1, auxkey2, e->size);
+      DDebug("ram_cache", "put %X %d %d size %d HIT", key->slice32(3), auxkey1, auxkey2, e->size);
       return 1;
     } else
       lru[1].remove(e);
@@ -548,12 +548,12 @@ RamCacheCLFUS::put(INK_MD5 *key, IOBufferData *data, uint32_t len, bool copy, ui
     if (bytes + size <= max_bytes)
       goto Linsert;
   if (!e && cache_config_ram_cache_use_seen_filter) {
-    uint32_t s = key->word(3) % bucket_sizes[ibuckets];
-    uint16_t k = key->word(3) >> 16;
+    uint32_t s = key->slice32(3) % bucket_sizes[ibuckets];
+    uint16_t k = key->slice32(3) >> 16;
     uint16_t kk = seen[s];
     seen[s] = k;
     if (history >= objects && kk != k) {
-      DDebug("ram_cache", "put %X %d %d size %d UNSEEN", key->word(3), auxkey1, auxkey2, size);
+      DDebug("ram_cache", "put %X %d %d size %d UNSEEN", key->slice32(3), auxkey1, auxkey2, size);
       return 0;
     }
   }
@@ -565,7 +565,7 @@ RamCacheCLFUS::put(INK_MD5 *key, IOBufferData *data, uint32_t len, bool copy, ui
       if (e)
         lru[1].enqueue(e);
       requeue_victims(this, victims);
-      DDebug("ram_cache", "put %X %d %d NO VICTIM", key->word(3), auxkey1, auxkey2);
+      DDebug("ram_cache", "put %X %d %d NO VICTIM", key->slice32(3), auxkey1, auxkey2);
       return 0;
     }
     bytes -= victim->size + ENTRY_OVERHEAD;
@@ -585,7 +585,7 @@ RamCacheCLFUS::put(INK_MD5 *key, IOBufferData *data, uint32_t len, bool copy, ui
         requeue_victims(this, victims);
         lru[1].enqueue(e);
         DDebug("ram_cache", "put %X %d %d size %d INC %" PRId64" HISTORY",
-               key->word(3), auxkey1, auxkey2, e->size, e->hits);
+               key->slice32(3), auxkey1, auxkey2, e->size, e->hits);
         return 0;
       }
     }
@@ -634,7 +634,7 @@ Linsert:
   lru[0].enqueue(e);
   e->len = len;
   check_accounting(this);
-  DDebug("ram_cache", "put %X %d %d size %d INSERTED", key->word(3), auxkey1, auxkey2, e->size);
+  DDebug("ram_cache", "put %X %d %d size %d INSERTED", key->slice32(3), auxkey1, auxkey2, e->size);
   return 1;
 Lhistory:
   requeue_victims(this, victims);
@@ -650,7 +650,7 @@ Lhistory:
   e->flag_bits.lru = 1;
   lru[1].enqueue(e);
   history++;
-  DDebug("ram_cache", "put %X %d %d HISTORY", key->word(3), auxkey1, auxkey2);
+  DDebug("ram_cache", "put %X %d %d HISTORY", key->slice32(3), auxkey1, auxkey2);
   return 0;
 }
 
@@ -660,7 +660,7 @@ RamCacheCLFUS::fixup(INK_MD5 * key, uint32_t old_auxkey1, uint32_t old_auxkey2,
 {
   if (!max_bytes)
     return 0;
-  uint32_t i = key->word(3) % nbuckets;
+  uint32_t i = key->slice32(3) % nbuckets;
   RamCacheCLFUSEntry *e = bucket[i].head;
   while (e) {
     if (e->key == *key && e->auxkey1 == old_auxkey1 && e->auxkey2 == old_auxkey2) {

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/iocore/cache/RamCacheLRU.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/RamCacheLRU.cc b/iocore/cache/RamCacheLRU.cc
index ddf7620..c85df38 100644
--- a/iocore/cache/RamCacheLRU.cc
+++ b/iocore/cache/RamCacheLRU.cc
@@ -76,7 +76,7 @@ void RamCacheLRU::resize_hashtable() {
     for (int64_t i = 0; i < nbuckets; i++) {
       RamCacheLRUEntry *e = 0;
       while ((e = bucket[i].pop()))
-        new_bucket[e->key.word(3) % anbuckets].push(e);
+        new_bucket[e->key.slice32(3) % anbuckets].push(e);
     }
     ats_free(bucket);
   }
@@ -104,32 +104,32 @@ int
 RamCacheLRU::get(INK_MD5 * key, Ptr<IOBufferData> *ret_data, uint32_t auxkey1, uint32_t auxkey2) {
   if (!max_bytes)
     return 0;
-  uint32_t i = key->word(3) % nbuckets;
+  uint32_t i = key->slice32(3) % nbuckets;
   RamCacheLRUEntry *e = bucket[i].head;
   while (e) {
     if (e->key == *key && e->auxkey1 == auxkey1 && e->auxkey2 == auxkey2) {
       lru.remove(e);
       lru.enqueue(e);
       (*ret_data) = e->data;
-      DDebug("ram_cache", "get %X %d %d HIT", key->word(3), auxkey1, auxkey2);
+      DDebug("ram_cache", "get %X %d %d HIT", key->slice32(3), auxkey1, auxkey2);
       CACHE_SUM_DYN_STAT_THREAD(cache_ram_cache_hits_stat, 1);
       return 1;
     }
     e = e->hash_link.next;
   }
-  DDebug("ram_cache", "get %X %d %d MISS", key->word(3), auxkey1, auxkey2);
+  DDebug("ram_cache", "get %X %d %d MISS", key->slice32(3), auxkey1, auxkey2);
   CACHE_SUM_DYN_STAT_THREAD(cache_ram_cache_misses_stat, 1);
   return 0;
 }
 
 RamCacheLRUEntry * RamCacheLRU::remove(RamCacheLRUEntry *e) {
   RamCacheLRUEntry *ret = e->hash_link.next;
-  uint32_t b = e->key.word(3) % nbuckets;
+  uint32_t b = e->key.slice32(3) % nbuckets;
   bucket[b].remove(e);
   lru.remove(e);
   bytes -= e->data->block_size();
   CACHE_SUM_DYN_STAT_THREAD(cache_ram_cache_bytes_stat, -e->data->block_size());
-  DDebug("ram_cache", "put %X %d %d FREED", e->key.word(3), e->auxkey1, e->auxkey2);
+  DDebug("ram_cache", "put %X %d %d FREED", e->key.slice32(3), e->auxkey1, e->auxkey2);
   e->data = NULL;
   THREAD_FREE(e, ramCacheLRUEntryAllocator, this_thread());
   objects--;
@@ -140,13 +140,13 @@ RamCacheLRUEntry * RamCacheLRU::remove(RamCacheLRUEntry *e) {
 int RamCacheLRU::put(INK_MD5 *key, IOBufferData *data, uint32_t len, bool, uint32_t auxkey1, uint32_t auxkey2) {
   if (!max_bytes)
     return 0;
-  uint32_t i = key->word(3) % nbuckets;
+  uint32_t i = key->slice32(3) % nbuckets;
   if (cache_config_ram_cache_use_seen_filter) {
-    uint16_t k = key->word(3) >> 16;
+    uint16_t k = key->slice32(3) >> 16;
     uint16_t kk = seen[i];
     seen[i] = k;
     if ((kk != (uint16_t)k)) {
-      DDebug("ram_cache", "put %X %d %d len %d UNSEEN", key->word(3), auxkey1, auxkey2, len);
+      DDebug("ram_cache", "put %X %d %d len %d UNSEEN", key->slice32(3), auxkey1, auxkey2, len);
       return 0;
     }
   }
@@ -181,7 +181,7 @@ int RamCacheLRU::put(INK_MD5 *key, IOBufferData *data, uint32_t len, bool, uint3
     else
       break;
   }
-  DDebug("ram_cache", "put %X %d %d INSERTED", key->word(3), auxkey1, auxkey2);
+  DDebug("ram_cache", "put %X %d %d INSERTED", key->slice32(3), auxkey1, auxkey2);
   if (objects > nbuckets) {
     ++ibuckets;
     resize_hashtable();
@@ -192,7 +192,7 @@ int RamCacheLRU::put(INK_MD5 *key, IOBufferData *data, uint32_t len, bool, uint3
 int RamCacheLRU::fixup(INK_MD5 * key, uint32_t old_auxkey1, uint32_t old_auxkey2, uint32_t new_auxkey1, uint32_t new_auxkey2) {
   if (!max_bytes)
     return 0;
-  uint32_t i = key->word(3) % nbuckets;
+  uint32_t i = key->slice32(3) % nbuckets;
   RamCacheLRUEntry *e = bucket[i].head;
   while (e) {
     if (e->key == *key && e->auxkey1 == old_auxkey1 && e->auxkey2 == old_auxkey2) {

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/iocore/hostdb/HostDB.cc
----------------------------------------------------------------------
diff --git a/iocore/hostdb/HostDB.cc b/iocore/hostdb/HostDB.cc
index 1b082ee..e295f7d 100644
--- a/iocore/hostdb/HostDB.cc
+++ b/iocore/hostdb/HostDB.cc
@@ -175,7 +175,8 @@ HostDBMD5::refresh() {
     memset(buff, 0, 2);
     memcpy(buff+2, ip._addr._byte, n);
     memset(buff + 2 + n , 0, 2);
-    hash.encodeBuffer(buff, n+4);
+    MD5Context().hash_immediate(hash, buff, n+4);
+//    hash.encodeBuffer(buff, n+4);
   }
 }
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2ac12c4a/lib/ts/CryptoHash.h
----------------------------------------------------------------------
diff --git a/lib/ts/CryptoHash.h b/lib/ts/CryptoHash.h
new file mode 100644
index 0000000..9dcec91
--- /dev/null
+++ b/lib/ts/CryptoHash.h
@@ -0,0 +1,124 @@
+# if ! defined CRYPTO_HASH_HEADER
+# define CRYPTO_HASH_HEADER
+
+/** @file
+    Protocol class for crypto hashes.
+
+    @section license License
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+ */
+
+/// Apache Traffic Server commons.
+namespace ats {
+  /// Crypto hash output.
+  union CryptoHash {
+    uint64_t b[2];   // Legacy placeholder
+    uint64_t u64[2];
+    uint32_t u32[4];
+    uint8_t  u8[16];
+
+    /// Default constructor - init to zero.
+    CryptoHash() {
+      u64[0] = 0;
+      u64[1] = 0;
+    }
+
+    /// Assignment - bitwise copy.
+    CryptoHash& operator = (CryptoHash const& that) {
+      u64[0] = that.u64[0];
+      u64[1] = that.u64[1];
+      return *this;
+    }
+
+    /// Equality - bitwise identical.
+    bool operator == (CryptoHash const& that) const {
+      return u64[0] == that.u64[0] && u64[1] == that.u64[1];
+    }
+
+    /// Equality - bitwise identical.
+    bool operator != (CryptoHash const& that) const {
+      return !(*this == that);
+    }
+
+    /// Reduce to 64 bit value.
+    uint64_t fold() const {
+      return u64[0] ^ u64[1];
+    }
+
+    /// Access 64 bit slice.
+    uint64_t operator [] (int i) const {
+      return u64[i];
+    }
+
+    /// Access 64 bit slice.
+    /// @note Identical to @ operator[] but included for symmetry.
+    uint64_t slice64(int i) const {
+      return u64[i];
+    }
+
+    /// Access 32 bit slice.
+    uint32_t slice32(int i) const {
+      return u32[i];
+    }
+
+    /// Fast conversion to hex in fixed sized string.
+    char *toHexStr(char buffer[33]) {
+      return ink_code_to_hex_str(buffer, u8);
+    }
+  };
+
+  extern CryptoHash const CRYPTO_HASH_ZERO;
+
+  /** Protocol class for a crypto hash context.
+
+      A hash of this type is used for strong hashing, such as for URLs.
+  */
+  class CryptoContext {
+    typedef CryptoContext self; ///< Self reference type.
+  public:
+
+    /// Destructor (force virtual)
+    virtual ~CryptoContext() { }
+
+    /// Update the hash with @a data of @a length bytes.
+    virtual bool update(void const* data, int length) = 0;
+    /// Finalize and extract the @a hash.
+    virtual bool finalize(CryptoHash& hash) = 0;
+
+    /// Convenience overload.
+    bool finalize(CryptoHash* hash);
+
+    /// Convenience - compute final @a hash for @a data.
+    /// @note This is just as fast as the previous style, as a new context must be initialized
+    /// everytime this is done.
+    virtual bool hash_immediate(CryptoHash& hash, void const* data, int length);
+  };
+
+  inline bool CryptoContext::hash_immediate(CryptoHash& hash, void const* data, int length) {
+    return this->update(data, length) && this->finalize(hash);
+  }
+  inline bool CryptoContext::finalize(CryptoHash* hash) { return this->finalize(*hash); }
+
+} // end namespace
+
+// Promote for the primitives who don't use namespaces...
+using ats::CryptoHash;
+using ats::CryptoContext;
+using ats::CRYPTO_HASH_ZERO;
+
+# endif // CRYPTO_HASH_HEADER