CRC without knowing the data type or size I wrote a function to calculate an 8-bit CRC/checksum for unknown data types. The only restriction is the data type must be at most 4bytes/32bits.

uint8_t crc(void* _crc, ssize_t len, uint8_t _crc_seed) {
    void* _crc_cpy = malloc(len);
    memcpy(_crc_cpy, _crc, len);
    uint32_t* _crc_cpy_pointer = static_cast&lt;uint32_t*&gt;(_crc_cpy);
    uint8_t _crc_u[len];
    for(int i = len; i &gt; 0; i--) {
        _crc_u[len-i] = ((*_crc_cpy_pointer)&amp;(0xff &lt;&lt; 8*(i-1))) &gt;&gt; (8*(i-1));
    }
    uint8_t crc_seed = _crc_seed;
    uint8_t crc_u;
    for(int i = 0; i &lt; len; i++) {
        crc_u = _crc_u[i] ^= crc_seed;
        for(int i = 0; i &lt; 8; i++) {
            crc_u = (crc_u &amp; 0x80) ? 0x7 ^ (crc_u &lt;&lt; 1) : (crc_u &lt;&lt; 1);
        }
        crc_seed = crc_u;
    }
    return crc_u;
}


How can I do this better? What are things that I did incorrectly?
Its always informative to comment the specific crc polynomial. An 8 bit crcs is only marginally better than 8 bit checksum.

First, remove the malloc() and memcpy(). A crc is a calculation that does not affect the input data. There is no need to allocate and copy the input data. Also, your code has a memory leak because its not releasing the allocated memory. 

Second, just read each byte and update the crc calculation. There is nothing to gain with an arbitrary restriction on the input data size.

Third, replace the bit by bit calculation loop with a byte wide calculation.