Fix (stupid) crc32 keyfile endianess bug.
authorMilan Broz <gmazyland@gmail.com>
Sat, 1 Dec 2012 13:32:01 +0000 (14:32 +0100)
committerMilan Broz <gmazyland@gmail.com>
Sat, 1 Dec 2012 13:32:01 +0000 (14:32 +0100)
lib/tcrypt/tcrypt.c

index 801f68e..4d6d4aa 100644 (file)
@@ -428,7 +428,6 @@ static int pool_keyfile(struct crypt_device *cd,
        unsigned char data[TCRYPT_KEYFILE_LEN];
        int i, j, fd, data_size;
        uint32_t crc;
        unsigned char data[TCRYPT_KEYFILE_LEN];
        int i, j, fd, data_size;
        uint32_t crc;
-       unsigned char *crc_c = (unsigned char*)&crc;
 
        log_dbg("TCRYPT: using keyfile %s.", keyfile);
 
 
        log_dbg("TCRYPT: using keyfile %s.", keyfile);
 
@@ -448,10 +447,10 @@ static int pool_keyfile(struct crypt_device *cd,
 
        for (i = 0, j = 0, crc = ~0U; i < data_size; i++) {
                crc = crypt_crc32(crc, &data[i], 1);
 
        for (i = 0, j = 0, crc = ~0U; i < data_size; i++) {
                crc = crypt_crc32(crc, &data[i], 1);
-               pool[j++] += crc_c[3];
-               pool[j++] += crc_c[2];
-               pool[j++] += crc_c[1];
-               pool[j++] += crc_c[0];
+               pool[j++] += (unsigned char)(crc >> 24);
+               pool[j++] += (unsigned char)(crc >> 16);
+               pool[j++] += (unsigned char)(crc >>  8);
+               pool[j++] += (unsigned char)(crc);
                j %= TCRYPT_KEY_POOL_LEN;
        }
 
                j %= TCRYPT_KEY_POOL_LEN;
        }