/** * \file * * * \brief Rotating Hash algorithm. * * This is a simple yet powerfull checksum algorithm. * Instead of just xor-ing the data, rotating hash * circular shift the checksum 4 place left before xoring. * This is a bit more stronger than simply sum the data. * * * \author Francesco Sacchi * * $WIZ$ module_name = "rotating_hash" */ #ifndef ALGO_ROTATING_H #define ALGO_ROTATING_H #include typedef uint16_t rotating_t; /** * Init rotating checksum. */ INLINE void rotating_init(rotating_t *rot) { *rot = 0; } /** * Update checksum pointed by \c rot with \c c data. */ INLINE void rotating_update1(uint8_t c, rotating_t *rot) { *rot = (*rot << 4) ^ (*rot >> 12) ^ c; } /** * Update checksum pointed by \c rot with data supplied in \c buf. */ INLINE void rotating_update(const void *_buf, size_t len, rotating_t *rot) { const uint8_t *buf = (const uint8_t *)_buf; while (len--) rotating_update1(*buf++, rot); } #endif // ALGO_ROTATING_H