]> mj.ucw.cz Git - libucw.git/commitdiff
CRC: Added crc32_hash_buffer()
authorMartin Mares <mj@ucw.cz>
Sun, 18 Mar 2012 22:08:01 +0000 (23:08 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 18 Mar 2012 22:08:01 +0000 (23:08 +0100)
ucw/crc.c
ucw/crc.h

index 2c03ccdb39ac1236d4d7ba910e5dba3ff4e147f5..73fd2e69eb7a5b4aee371097c18ae8071792f488 100644 (file)
--- a/ucw/crc.c
+++ b/ucw/crc.c
@@ -134,6 +134,15 @@ crc32_init(crc32_context *ctx, uns crc_mode)
     }
 }
 
+u32
+crc32_hash_buffer(const byte *buf, uns len)
+{
+  crc32_context ctx;
+  crc32_init(&ctx, CRC_MODE_DEFAULT);
+  crc32_update(&ctx, buf, len);
+  return crc32_final(&ctx);
+}
+
 #ifdef TEST
 
 #include <stdio.h>
index 28d59acf6eba1997f511194ebb33b8af5a8b5c23..a5134267cf1e5e0bffc18bca0eafc63f167e2328 100644 (file)
--- a/ucw/crc.h
+++ b/ucw/crc.h
@@ -54,3 +54,14 @@ static inline u32 crc32_final(crc32_context *ctx)
 {
   return ctx->state ^ 0xffffffff;
 }
+
+/**
+ * A convenience one-shot function for CRC.
+ * It is equivalent to this snippet of code:
+ *
+ *  crc32_context ctx;
+ *  crc32_init(&ctx, CRC_MODE_DEFAULT);
+ *  crc32_update(&ctx, buf, len);
+ *  return crc32_final(&ctx);
+ */
+u32 crc32_hash_buffer(const byte *buf, uns len);