From: batt Date: Thu, 7 Jun 2007 09:11:17 +0000 (+0000) Subject: Add rotating hash algorithm. X-Git-Tag: 1.0.0~448 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=8dc518b4bd7884157a6d6f1f510bac2583ffe502;p=bertos.git Add rotating hash algorithm. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@793 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/algos/rotating_hash.h b/algos/rotating_hash.h new file mode 100755 index 00000000..d307c5ca --- /dev/null +++ b/algos/rotating_hash.h @@ -0,0 +1,57 @@ +/** + * \file + * + * + * \brief Rotating Hash algorithm (interface). + * + * 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. + * + * \version $Id$ + * + * \author Francesco Sacchi + */ + +/*#* + *#* $Log$ + *#* Revision 1.1 2007/06/07 09:11:17 batt + *#* Add rotating hash algorithm. + *#* + *#* Revision 1.1 2007/01/12 20:30:49 batt + *#* Add right Rotating hash file. + *#* + *#*/ + +#ifndef ALGOS_ROTATING_H +#define ALGOS_ROTATING_H + +#include + +typedef uint16_t rotating_t; + +/** + * 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 // ALGOS_ROTATING_H