From 065dc6f8cd168e3ee6e71ddfb06f42a92abfabbd Mon Sep 17 00:00:00 2001 From: Martin Ebourne Date: Wed, 7 Dec 2005 16:24:49 +0000 Subject: Merged chromi/diffopt at r116 to trunk --- lib/crypto/RollingChecksum.cpp | 28 ++++++++++++++++++++++++++-- lib/crypto/RollingChecksum.h | 25 ++++++++++++++++++------- 2 files changed, 44 insertions(+), 9 deletions(-) (limited to 'lib/crypto') diff --git a/lib/crypto/RollingChecksum.cpp b/lib/crypto/RollingChecksum.cpp index 75bad7df..a2954e3a 100755 --- a/lib/crypto/RollingChecksum.cpp +++ b/lib/crypto/RollingChecksum.cpp @@ -20,11 +20,11 @@ // Created: 6/12/03 // // -------------------------------------------------------------------------- -RollingChecksum::RollingChecksum(const void *data, unsigned int Length) +RollingChecksum::RollingChecksum(const void * const data, const unsigned int Length) : a(0), b(0) { - uint8_t *block = (uint8_t *)data; + const uint8_t *block = (const uint8_t *)data; for(unsigned int x = Length; x >= 1; --x) { a += (*block); @@ -34,5 +34,29 @@ RollingChecksum::RollingChecksum(const void *data, unsigned int Length) } } +// -------------------------------------------------------------------------- +// +// Function +// Name: RollingChecksum::RollForwardSeveral(uint8_t*, uint8_t*, unsigned int, unsigned int) +// Purpose: Move the checksum forward a block, given a pointer to the first byte of the current block, +// and a pointer just after the last byte of the current block and the length of the block and of the skip. +// Created: 7/14/05 +// +// -------------------------------------------------------------------------- +void RollingChecksum::RollForwardSeveral(const uint8_t * const StartOfThisBlock, const uint8_t * const LastOfNextBlock, const unsigned int Length, const unsigned int Skip) +{ + // IMPLEMENTATION NOTE: Everything is implicitly mod 2^16 -- uint16_t's will overflow nicely. + unsigned int i; + uint16_t sumBegin=0, j,k; + for(i=0; i < Skip; i++) + { + j = StartOfThisBlock[i]; + k = LastOfNextBlock[i]; + sumBegin += j; + a += (k - j); + b += a; + } + b -= Length * sumBegin; +} diff --git a/lib/crypto/RollingChecksum.h b/lib/crypto/RollingChecksum.h index 99d116b9..be79c36f 100755 --- a/lib/crypto/RollingChecksum.h +++ b/lib/crypto/RollingChecksum.h @@ -24,7 +24,7 @@ class RollingChecksum { public: - RollingChecksum(const void *data, unsigned int Length); + RollingChecksum(const void * const data, const unsigned int Length); // -------------------------------------------------------------------------- // @@ -35,7 +35,7 @@ public: // Created: 6/12/03 // // -------------------------------------------------------------------------- - inline void RollForward(uint8_t StartOfThisBlock, uint8_t LastOfNextBlock, unsigned int Length) + inline void RollForward(const uint8_t StartOfThisBlock, const uint8_t LastOfNextBlock, const unsigned int Length) { // IMPLEMENTATION NOTE: Everything is implicitly mod 2^16 -- uint16_t's will overflow nicely. a -= StartOfThisBlock; @@ -44,6 +44,17 @@ public: b += a; } + // -------------------------------------------------------------------------- + // + // Function + // Name: RollingChecksum::RollForwardSeveral(uint8_t*, uint8_t*, unsigned int, unsigned int) + // Purpose: Move the checksum forward a block, given a pointer to the first byte of the current block, + // and a pointer just after the last byte of the current block and the length of the block and of the skip. + // Created: 7/14/05 + // + // -------------------------------------------------------------------------- + void RollForwardSeveral(const uint8_t * const StartOfThisBlock, const uint8_t * const LastOfNextBlock, const unsigned int Length, const unsigned int Skip); + // -------------------------------------------------------------------------- // // Function @@ -52,14 +63,14 @@ public: // Created: 6/12/03 // // -------------------------------------------------------------------------- - inline uint32_t GetChecksum() + inline uint32_t GetChecksum() const { return ((uint32_t)a) | (((uint32_t)b) << 16); } // Components, just in case they're handy - inline uint16_t GetComponent1() {return a;} - inline uint16_t GetComponent2() {return b;} + inline uint16_t GetComponent1() const {return a;} + inline uint16_t GetComponent2() const {return b;} // -------------------------------------------------------------------------- // @@ -69,7 +80,7 @@ public: // Created: 6/12/03 // // -------------------------------------------------------------------------- - inline uint16_t GetComponentForHashing() + inline uint16_t GetComponentForHashing() const { return b; } @@ -82,7 +93,7 @@ public: // Created: 14/1/04 // // -------------------------------------------------------------------------- - static inline uint16_t ExtractHashingComponent(uint32_t Checksum) + static inline uint16_t ExtractHashingComponent(const uint32_t Checksum) { return Checksum >> 16; } -- cgit v1.2.3