diff --git a/crc32.c b/crc32.c index 40fcf1f..0fa6b56 100644 --- a/crc32.c +++ b/crc32.c @@ -24,20 +24,23 @@ AARU_EXPORT crc32_ctx* AARU_CALL crc32_init(void) { + int i, j; crc32_ctx* ctx = (crc32_ctx*)malloc(sizeof(crc32_ctx)); if(!ctx) return NULL; ctx->crc = CRC32_ISO_SEED; - for(int i = 0; i < 256; i++) + for(i = 0; i < 256; i++) { uint32_t entry = (uint32_t)i; - for(int j = 0; j < 8; j++) - if(entry & 1) ctx->table[i] = (entry >> 1) ^ CRC32_ISO_POLY; + for(j = 0; j < 8; j++) + if(entry & 1) entry = (entry >> 1) ^ CRC32_ISO_POLY; else - ctx->table[i] >>= 1; + entry >>= 1; + + ctx->table[i] = entry; } return ctx; @@ -45,9 +48,10 @@ AARU_EXPORT crc32_ctx* AARU_CALL crc32_init(void) AARU_EXPORT int AARU_CALL crc32_update(crc32_ctx* ctx, const uint8_t* data, uint32_t len) { + uint32_t i; if(!ctx || !data) return -1; - for(uint32_t i = 0; i < len; i++) ctx->crc = (ctx->crc >> 8) ^ ctx->table[data[i] ^ (ctx->crc & 0xff)]; + for( i = 0; i < len; i++) ctx->crc = (ctx->crc >> 8) ^ ctx->table[data[i] ^ (ctx->crc & 0xff)]; return 0; } diff --git a/crc64.c b/crc64.c index 8248dce..736ad44 100644 --- a/crc64.c +++ b/crc64.c @@ -24,20 +24,23 @@ AARU_EXPORT crc64_ctx* AARU_CALL crc64_init(void) { + int i, j; crc64_ctx* ctx = (crc64_ctx*)malloc(sizeof(crc64_ctx)); if(!ctx) return NULL; ctx->crc = CRC64_ECMA_SEED; - for(int i = 0; i < 256; i++) + for(i = 0; i < 256; i++) { uint64_t entry = (uint64_t)i; - for(int j = 0; j < 8; j++) - if(entry & 1) ctx->table[i] = (entry >> 1) ^ CRC64_ECMA_POLY; + for(j = 0; j < 8; j++) + if(entry & 1) entry = (entry >> 1) ^ CRC64_ECMA_POLY; else - ctx->table[i] >>= 1; + entry >>= 1; + + ctx->table[i]=entry; } return ctx; @@ -45,9 +48,10 @@ AARU_EXPORT crc64_ctx* AARU_CALL crc64_init(void) AARU_EXPORT int AARU_CALL crc64_update(crc64_ctx* ctx, const uint8_t* data, uint32_t len) { + uint32_t i; if(!ctx || !data) return -1; - for(uint32_t i = 0; i < len; i++) ctx->crc = (ctx->crc >> 8) ^ ctx->table[data[i] ^ (ctx->crc & 0xff)]; + for( i = 0; i < len; i++) ctx->crc = (ctx->crc >> 8) ^ ctx->table[data[i] ^ (ctx->crc & 0xff)]; return 0; }