Bug 803692 - Make SHA1Sum::update() take a void* instead of a uint8_t*. r=waldo, a=blocking-basecamp
authorJustin Lebar <justin.lebar@gmail.com>
Mon, 22 Oct 2012 16:32:34 -0400
changeset 116294 237ca1852d59f6c6b2ff242b91af0b15bc7f66c8
parent 116293 cc90d089743cf49e674982c9e3cf73bde17b9f90
child 116295 64a4e851104e83ecd7421ad9028ea79f0d5433d7
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo, blocking-basecamp
bugs803692
milestone18.0a2
Bug 803692 - Make SHA1Sum::update() take a void* instead of a uint8_t*. r=waldo, a=blocking-basecamp
mfbt/SHA1.cpp
mfbt/SHA1.h
--- a/mfbt/SHA1.cpp
+++ b/mfbt/SHA1.cpp
@@ -86,19 +86,22 @@ SHA1Sum::SHA1Sum() : size(0), mDone(fals
  * higher.  This results in much bigger and slower code.
  */
 #define H2X 11 /* X[0] is H[11], and H[0] is X[-11] */
 #define W2X  6 /* X[0] is W[6],  and W[0] is X[-6]  */
 
 /*
  *  SHA: Add data to context.
  */
-void SHA1Sum::update(const uint8_t *dataIn, uint32_t len)
+void SHA1Sum::update(const void *dataIn, uint32_t len)
 {
   MOZ_ASSERT(!mDone);
+
+  const uint8_t* data = static_cast<const uint8_t*>(dataIn);
+
   register unsigned int lenB;
   register unsigned int togo;
 
   if (!len)
     return;
 
   /* accumulate the byte count. */
   lenB = (unsigned int)(size) & 63U;
@@ -107,31 +110,31 @@ void SHA1Sum::update(const uint8_t *data
 
   /*
    *  Read the data into W and process blocks as they get full
    */
   if (lenB > 0) {
     togo = 64U - lenB;
     if (len < togo)
       togo = len;
-    memcpy(u.b + lenB, dataIn, togo);
+    memcpy(u.b + lenB, data, togo);
     len    -= togo;
-    dataIn += togo;
+    data += togo;
     lenB    = (lenB + togo) & 63U;
     if (!lenB) {
       shaCompress(&H[H2X], u.w);
     }
   }
   while (len >= 64U) {
     len    -= 64U;
-    shaCompress(&H[H2X], (uint32_t *)dataIn);
-    dataIn += 64U;
+    shaCompress(&H[H2X], (uint32_t *)data);
+    data += 64U;
   }
   if (len) {
-    memcpy(u.b, dataIn, len);
+    memcpy(u.b, data, len);
   }
 }
 
 
 /*
  *  SHA: Generate hash value
  */
 void SHA1Sum::finish(uint8_t hashout[20])
--- a/mfbt/SHA1.h
+++ b/mfbt/SHA1.h
@@ -33,14 +33,14 @@ class SHA1Sum {
   } u;
   uint64_t size;            /* count of hashed bytes. */
   unsigned H[22];           /* 5 state variables, 16 tmp values, 1 extra */
   bool mDone;
 
 public:
   static const unsigned int HashSize = 20;
   SHA1Sum();
-  void update(const uint8_t *dataIn, uint32_t len);
+  void update(const void* dataIn, uint32_t len);
   void finish(uint8_t hashout[20]);
 };
 }
 
 #endif /* mozilla_SHA1_h_ */