diff --git a/crypto/crct10dif_common.c b/crypto/crct10dif_common.c index 4eb1c50c3688..bf5fab98aebb 100644 --- a/crypto/crct10dif_common.c +++ b/crypto/crct10dif_common.c @@ -591,23 +591,30 @@ __u16 crc_t10dif_generic(__u16 crc, const unsigned char *buffer, size_t len) { const u8 *ptr = (const __u8 *)buffer; const u8 *ptr_end = ptr + len; + const u16 *flat_tbl = (const u16 *)t10dif_crc_table; #if CONFIG_CRYPTO_CRCT10DIF_TABLE_SIZE > 1 size_t tablesize = 1 << (CONFIG_CRYPTO_CRCT10DIF_TABLE_SIZE - 1); const u8 *ptr_last = ptr + (len / tablesize * tablesize); + /* + * t10dif_crc_table is two dimensional but access as vector via + * flat_tbl for speed. t[k][j] is equivalent to tt[k*num_cols + j]. + * num_cols in this case is 256 allowing tt[k<<8 + j]. Perhaps + * there should be a compile time assert that num_cols==256 . + */ while (ptr < ptr_last) { size_t index = tablesize; __u16 t; - t = t10dif_crc_table[--index][*ptr++ ^ (u8)(crc >> 8)]; - t ^= t10dif_crc_table[--index][*ptr++ ^ (u8)crc]; + t = flat_tbl[(--index << 8) + (*ptr++ ^ (u8)(crc >> 8))]; + t ^= flat_tbl[(--index << 8) + (*ptr++ ^ (u8)crc)]; crc = t; while (index > 0) - crc ^= t10dif_crc_table[--index][*ptr++]; + crc ^= flat_tbl[(--index << 8) + *ptr++]; } #endif while (ptr < ptr_end) - crc = t10dif_crc_table[0][*ptr++ ^ (u8)(crc >> 8)] ^ (crc << 8); + crc = flat_tbl[*ptr++ ^ (u8)(crc >> 8)] ^ (crc << 8); return crc; }