Bug 803692 - Make SHA1Sum::update() take a void* instead of a uint8_t*. r=waldo
--- a/mfbt/SHA1.cpp
+++ b/mfbt/SHA1.cpp
@@ -94,50 +94,52 @@ SHA1Sum::SHA1Sum()
*/
#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)
+SHA1Sum::update(const void* dataIn, uint32_t len)
{
MOZ_ASSERT(!mDone, "SHA1Sum can only be used to compute a single hash.");
+ const uint8_t* data = static_cast<const uint8_t*>(dataIn);
+
if (len == 0)
return;
/* Accumulate the byte count. */
unsigned int lenB = static_cast<unsigned int>(size) & 63U;
size += len;
/* Read the data into W and process blocks as they get full. */
unsigned int togo;
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], reinterpret_cast<const uint32_t*>(dataIn));
- dataIn += 64U;
+ shaCompress(&H[H2X], reinterpret_cast<const uint32_t*>(data));
+ data += 64U;
}
if (len > 0)
- memcpy(u.b, dataIn, len);
+ memcpy(u.b, data, len);
}
/*
* SHA: Generate hash value
*/
void
SHA1Sum::finish(SHA1Sum::Hash& hashOut)
--- a/mfbt/SHA1.h
+++ b/mfbt/SHA1.h
@@ -44,17 +44,17 @@ class SHA1Sum
public:
SHA1Sum();
static const size_t HashSize = 20;
typedef uint8_t Hash[HashSize];
/* Add len bytes of dataIn to the data sequence being hashed. */
- void update(const uint8_t* dataIn, uint32_t len);
+ void update(const void* dataIn, uint32_t len);
/* Compute the final hash of all data into hashOut. */
void finish(SHA1Sum::Hash& hashOut);
};
} /* namespace mozilla */
#endif /* mozilla_SHA1_h_ */