]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - lib/842/842_compress.c
crypto: 842 - Add CRC and validation support
[karo-tx-linux.git] / lib / 842 / 842_compress.c
index 7ce68948e68c84d41c796c70a726895e65c68d78..4051339bdfbda6e6869d7f7c669672ba65f3d3f1 100644 (file)
@@ -490,6 +490,7 @@ int sw842_compress(const u8 *in, unsigned int ilen,
        int ret;
        u64 last, next, pad, total;
        u8 repeat_count = 0;
+       u32 crc;
 
        BUILD_BUG_ON(sizeof(*p) > SW842_MEM_COMPRESS);
 
@@ -580,6 +581,18 @@ skip_comp:
        if (ret)
                return ret;
 
+       /*
+        * crc(0:31) is appended to target data starting with the next
+        * bit after End of stream template.
+        * nx842 calculates CRC for data in big-endian format. So doing
+        * same here so that sw842 decompression can be used for both
+        * compressed data.
+        */
+       crc = crc32_be(0, in, ilen);
+       ret = add_bits(p, crc, CRC_BITS);
+       if (ret)
+               return ret;
+
        if (p->bit) {
                p->out++;
                p->olen--;