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.2 2007/10/01 10:46:33 batt
23 *#* Add rotating hash init function.
25 *#* Revision 1.1 2007/06/07 09:11:17 batt
26 *#* Add rotating hash algorithm.
28 *#* Revision 1.1 2007/01/12 20:30:49 batt
29 *#* Add right Rotating hash file.
33 #ifndef ALGOS_ROTATING_H
34 #define ALGOS_ROTATING_H
36 #include <cfg/compiler.h>
38 typedef uint16_t rotating_t;
42 * Init rotating checksum.
44 INLINE void rotating_init(rotating_t *rot)
50 * Update checksum pointed by \c rot with \c c data.
52 INLINE void rotating_update1(uint8_t c, rotating_t *rot)
54 *rot = (*rot << 4) ^ (*rot >> 12) ^ c;
58 * Update checksum pointed by \c rot with data supplied in \c buf.
60 INLINE void rotating_update(const void *_buf, size_t len, rotating_t *rot)
62 const uint8_t *buf = (const uint8_t *)_buf;
65 rotating_update1(*buf++, rot);
69 #endif // ALGOS_ROTATING_H