/**
 * \file
 * Functions and types for CRC checks.
 *
 * Generated on Sun Jan 26 14:11:51 2025
 * by pycrc v0.10.0, https://pycrc.org
 * using the configuration:
 *  - Width         = 32
 *  - Poly          = 0x1edc6f41
 *  - XorIn         = 0xffffffff
 *  - ReflectIn     = True
 *  - XorOut        = 0xffffffff
 *  - ReflectOut    = True
 *  - Algorithm     = bit-by-bit-fast
 */
#include "crc-32c.h"     /* include the header file generated with pycrc */
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>



crc32c_t crc32c_reflect(crc32c_t data, size_t data_len)
{
    unsigned int i;
    crc32c_t ret;

    ret = data & 0x01;
    for (i = 1; i < data_len; i++) {
        data >>= 1;
        ret = (ret << 1) | (data & 0x01);
    }
    return ret;
}


crc32c_t crc32c_update(crc32c_t crc, const void *data, size_t data_len)
{
    const unsigned char *d = (const unsigned char *)data;
    unsigned int i;
    crc32c_t bit;
    unsigned char c;

    while (data_len--) {
        c = *d++;
        for (i = 0x01; i & 0xff; i <<= 1) {
            bit = (crc & 0x80000000) ^ ((c & i) ? 0x80000000 : 0);
            crc <<= 1;
            if (bit) {
                crc ^= 0x1edc6f41;
            }
        }
        crc &= 0xffffffff;
    }
    return crc & 0xffffffff;
}
