From 3ffe95d46ec6ac2625e6fed49c356699513a3cbf Mon Sep 17 00:00:00 2001 From: Robert Spalek Date: Fri, 16 Jul 2004 10:25:49 +0000 Subject: [PATCH] added adler32 functions --- lib/lizard-safe.c | 21 +++++++++++++++++++++ lib/lizard.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/lib/lizard-safe.c b/lib/lizard-safe.c index 88e9aebd..40a5aa3d 100644 --- a/lib/lizard-safe.c +++ b/lib/lizard-safe.c @@ -103,3 +103,24 @@ lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length) signal_handler[SIGSEGV] = old_handler; return ptr; } + +#define BASE 65521 /* largest prime smaller than 65536 */ + +inline uns +update_adler32(uns adler, byte *ptr, uns len) + /* taken from RFC1950 */ +{ + uns s1 = adler & 0xffff; + uns s2 = (adler >> 16) & 0xffff; + for (uns n = 0; n < len; n++) { + s1 = (s1 + ptr[n]) % BASE; + s2 = (s2 + s1) % BASE; + } + return (s2 << 16) + s1; +} + +uns +adler32(byte *ptr, uns len) +{ + return update_adler32(1, ptr, len); +} diff --git a/lib/lizard.h b/lib/lizard.h index 51f46bad..838d683f 100644 --- a/lib/lizard.h +++ b/lib/lizard.h @@ -37,4 +37,7 @@ struct lizard_buffer *lizard_alloc(void); void lizard_free(struct lizard_buffer *buf); byte *lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length); +uns update_adler32(uns adler, byte *ptr, uns len); +uns adler32(byte *ptr, uns len); + #endif -- 2.39.5