From: Martin Mares Date: Sun, 18 Mar 2012 22:08:01 +0000 (+0100) Subject: CRC: Added crc32_hash_buffer() X-Git-Tag: v5.99~184 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=f22fe2e1dde82925771f4ef565ba8c09cfc458c0;p=libucw.git CRC: Added crc32_hash_buffer() --- 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);