X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=ucw%2Fcrc.c;h=2f818840b3c1d29832eca1e3d6b0ef5ffde3ad53;hb=ec6703bb4d58e504fde8ea8429f9b26ab6632696;hp=2c03ccdb39ac1236d4d7ba910e5dba3ff4e147f5;hpb=497d58b96ab7e962dd53527ae0ed07c52680fea4;p=libucw.git diff --git a/ucw/crc.c b/ucw/crc.c index 2c03ccdb..2f818840 100644 --- a/ucw/crc.c +++ b/ucw/crc.c @@ -20,7 +20,7 @@ #include #include -static void crc32_update_by1(crc32_context *ctx, const byte *buf, uns len) +static void crc32_update_by1(crc32_context *ctx, const byte *buf, uint len) { u32 crc = ctx->state; while (len--) @@ -28,9 +28,9 @@ static void crc32_update_by1(crc32_context *ctx, const byte *buf, uns len) ctx->state = crc; } -static void crc32_update_by4(crc32_context *ctx, const byte *buf, uns len) +static void crc32_update_by4(crc32_context *ctx, const byte *buf, uint len) { - uns init_bytes, words; + uint init_bytes, words; u32 crc = ctx->state; u32 term1, term2, *buf32; @@ -66,9 +66,9 @@ static void crc32_update_by4(crc32_context *ctx, const byte *buf, uns len) ctx->state = crc; } -static void crc32_update_by8(crc32_context *ctx, const byte *buf, uns len) +static void crc32_update_by8(crc32_context *ctx, const byte *buf, uint len) { - uns init_bytes, quads; + uint init_bytes, quads; u32 crc = ctx->state; u32 term1, term2, *buf32; @@ -115,7 +115,7 @@ static void crc32_update_by8(crc32_context *ctx, const byte *buf, uns len) } void -crc32_init(crc32_context *ctx, uns crc_mode) +crc32_init(crc32_context *ctx, uint crc_mode) { ctx->state = 0xffffffff; switch (crc_mode) @@ -134,6 +134,15 @@ crc32_init(crc32_context *ctx, uns crc_mode) } } +u32 +crc32_hash_buffer(const byte *buf, uint len) +{ + crc32_context ctx; + crc32_init(&ctx, CRC_MODE_DEFAULT); + crc32_update(&ctx, buf, len); + return crc32_final(&ctx); +} + #ifdef TEST #include @@ -143,28 +152,28 @@ int main(int argc, char **argv) { if (argc != 5) die("Usage: crc-t "); - uns alg = atoi(argv[1]); - uns len = atoi(argv[2]); - uns block = atoi(argv[3]); - uns iters = atoi(argv[4]); + uint alg = atoi(argv[1]); + uint len = atoi(argv[2]); + uint block = atoi(argv[3]); + uint iters = atoi(argv[4]); byte *buf = xmalloc(len); - for (uns i=0; i> 5) ^ (i >> 11); - for (uns i=0; i