From a59bb00a2733c721f18e4ef4b9c4a8dd3c0a8549 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sat, 23 Jun 2012 11:59:47 -0300 Subject: [PATCH] fw/hash.[ch]: new function hash_merge_progmem to read from Flash instead of RAM --- fw/hash.c | 15 +++++++++++++++ fw/hash.h | 1 + 2 files changed, 16 insertions(+) diff --git a/fw/hash.c b/fw/hash.c index e962f0c..b876598 100644 --- a/fw/hash.c +++ b/fw/hash.c @@ -15,6 +15,8 @@ #include #include +#include + #include "hash.h" @@ -39,6 +41,19 @@ void hash_merge(const uint8_t *buf, uint8_t len) } +#ifdef __AVR__ + +void hash_merge_progmem(const uint8_t *buf, uint8_t len) +{ + uint8_t i; + + for (i = 0; i != len; i++) + hash[i & (HASH_SIZE-1)] ^= pgm_read_byte(buf+i); +} + +#endif /* __AVR__ */ + + void hash_end(void) { } diff --git a/fw/hash.h b/fw/hash.h index 253b9db..bd20695 100644 --- a/fw/hash.h +++ b/fw/hash.h @@ -19,6 +19,7 @@ void hash_init(void); void hash_merge(const uint8_t *buf, uint8_t len); +void hash_merge_progmem(const uint8_t *buf, uint8_t len); void hash_end(void); bool hash_eq(const uint8_t *buf, uint8_t len, uint8_t off); void hash_cp(uint8_t *buf, uint8_t len, uint8_t off);