From f22fe2e1dde82925771f4ef565ba8c09cfc458c0 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 18 Mar 2012 23:08:01 +0100 Subject: [PATCH] CRC: Added crc32_hash_buffer() --- ucw/crc.c | 9 +++++++++ ucw/crc.h | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/ucw/crc.c b/ucw/crc.c index 2c03ccdb..73fd2e69 100644 --- 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 diff --git a/ucw/crc.h b/ucw/crc.h index 28d59acf..a5134267 100644 --- 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); -- 2.39.5