aboutsummaryrefslogtreecommitdiffstats
path: root/lib/842/842_decompress.c
diff options
context:
space:
mode:
authorHaren Myneni <haren@linux.vnet.ibm.com>2015-10-08 16:45:51 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-10-14 10:23:17 -0400
commitea0b3984c1cc8b28de27a3bec285102b4e366a4c (patch)
treeb0134466a5b790d4091dc16065257a00ea24bf00 /lib/842/842_decompress.c
parentf5128432b08c3e263e1a7ce709d686b1ded51131 (diff)
crypto: 842 - Add CRC and validation support
This patch adds CRC generation and validation support for nx-842. Add CRC flag so that nx842 coprocessor includes CRC during compression and validates during decompression. Also changes in 842 SW compression to append CRC value at the end of template and checks during decompression. Signed-off-by: Haren Myneni <haren@us.ibm.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'lib/842/842_decompress.c')
-rw-r--r--lib/842/842_decompress.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/842/842_decompress.c b/lib/842/842_decompress.c
index 5446ff0c9ba0..8881dad2a6a0 100644
--- a/lib/842/842_decompress.c
+++ b/lib/842/842_decompress.c
@@ -285,6 +285,7 @@ int sw842_decompress(const u8 *in, unsigned int ilen,
285 struct sw842_param p; 285 struct sw842_param p;
286 int ret; 286 int ret;
287 u64 op, rep, tmp, bytes, total; 287 u64 op, rep, tmp, bytes, total;
288 u64 crc;
288 289
289 p.in = (u8 *)in; 290 p.in = (u8 *)in;
290 p.bit = 0; 291 p.bit = 0;
@@ -375,6 +376,22 @@ int sw842_decompress(const u8 *in, unsigned int ilen,
375 } 376 }
376 } while (op != OP_END); 377 } while (op != OP_END);
377 378
379 /*
380 * crc(0:31) is saved in compressed data starting with the
381 * next bit after End of stream template.
382 */
383 ret = next_bits(&p, &crc, CRC_BITS);
384 if (ret)
385 return ret;
386
387 /*
388 * Validate CRC saved in compressed data.
389 */
390 if (crc != (u64)crc32_be(0, out, total - p.olen)) {
391 pr_debug("CRC mismatch for decompression\n");
392 return -EINVAL;
393 }
394
378 if (unlikely((total - p.olen) > UINT_MAX)) 395 if (unlikely((total - p.olen) > UINT_MAX))
379 return -ENOSPC; 396 return -ENOSPC;
380 397