4 * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
8 * \brief Rotating Hash algorithm (interface).
10 * This is a simple yet powerfull checksum algorithm.
11 * Instead of just xor-ing the data, rotating hash
12 * circular shift the checksum 4 place left before xoring.
13 * This is a bit more stronger than simply sum the data.
17 * \author Francesco Sacchi <batt@develer.com>
22 *#* Revision 1.1 2007/06/07 09:11:17 batt
23 *#* Add rotating hash algorithm.
25 *#* Revision 1.1 2007/01/12 20:30:49 batt
26 *#* Add right Rotating hash file.
30 #ifndef ALGOS_ROTATING_H
31 #define ALGOS_ROTATING_H
33 #include <cfg/compiler.h>
35 typedef uint16_t rotating_t;
38 * Update checksum pointed by \c rot with \c c data.
40 INLINE void rotating_update1(uint8_t c, rotating_t *rot)
42 *rot = (*rot << 4) ^ (*rot >> 12) ^ c;
46 * Update checksum pointed by \c rot with data supplied in \c buf.
48 INLINE void rotating_update(const void *_buf, size_t len, rotating_t *rot)
50 const uint8_t *buf = (const uint8_t *)_buf;
53 rotating_update1(*buf++, rot);
57 #endif // ALGOS_ROTATING_H