xref: /linux/crypto/842.c (revision 01b944fe1cd4e21a2a9ed51adbdbafe2d5e905ba)
135a1fc18SSeth Jennings /*
22062c5b6SDan Streetman  * Cryptographic API for the 842 software compression algorithm.
335a1fc18SSeth Jennings  *
435a1fc18SSeth Jennings  * This program is free software; you can redistribute it and/or modify
535a1fc18SSeth Jennings  * it under the terms of the GNU General Public License as published by
635a1fc18SSeth Jennings  * the Free Software Foundation; either version 2 of the License, or
735a1fc18SSeth Jennings  * (at your option) any later version.
835a1fc18SSeth Jennings  *
935a1fc18SSeth Jennings  * This program is distributed in the hope that it will be useful,
1035a1fc18SSeth Jennings  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1135a1fc18SSeth Jennings  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1235a1fc18SSeth Jennings  * GNU General Public License for more details.
1335a1fc18SSeth Jennings  *
142062c5b6SDan Streetman  * Copyright (C) IBM Corporation, 2011-2015
1535a1fc18SSeth Jennings  *
162062c5b6SDan Streetman  * Original Authors: Robert Jennings <rcj@linux.vnet.ibm.com>
1735a1fc18SSeth Jennings  *                   Seth Jennings <sjenning@linux.vnet.ibm.com>
182062c5b6SDan Streetman  *
192062c5b6SDan Streetman  * Rewrite: Dan Streetman <ddstreet@ieee.org>
202062c5b6SDan Streetman  *
212062c5b6SDan Streetman  * This is the software implementation of compression and decompression using
222062c5b6SDan Streetman  * the 842 format.  This uses the software 842 library at lib/842/ which is
232062c5b6SDan Streetman  * only a reference implementation, and is very, very slow as compared to other
242062c5b6SDan Streetman  * software compressors.  You probably do not want to use this software
252062c5b6SDan Streetman  * compression.  If you have access to the PowerPC 842 compression hardware, you
262062c5b6SDan Streetman  * want to use the 842 hardware compression interface, which is at:
272062c5b6SDan Streetman  * drivers/crypto/nx/nx-842-crypto.c
2835a1fc18SSeth Jennings  */
2935a1fc18SSeth Jennings 
3035a1fc18SSeth Jennings #include <linux/init.h>
3135a1fc18SSeth Jennings #include <linux/module.h>
3235a1fc18SSeth Jennings #include <linux/crypto.h>
332062c5b6SDan Streetman #include <linux/sw842.h>
3435a1fc18SSeth Jennings 
352062c5b6SDan Streetman struct crypto842_ctx {
362062c5b6SDan Streetman 	char wmem[SW842_MEM_COMPRESS];	/* working memory for compress */
3735a1fc18SSeth Jennings };
3835a1fc18SSeth Jennings 
392062c5b6SDan Streetman static int crypto842_compress(struct crypto_tfm *tfm,
402062c5b6SDan Streetman 			      const u8 *src, unsigned int slen,
412062c5b6SDan Streetman 			      u8 *dst, unsigned int *dlen)
4235a1fc18SSeth Jennings {
432062c5b6SDan Streetman 	struct crypto842_ctx *ctx = crypto_tfm_ctx(tfm);
4435a1fc18SSeth Jennings 
452062c5b6SDan Streetman 	return sw842_compress(src, slen, dst, dlen, ctx->wmem);
4635a1fc18SSeth Jennings }
4735a1fc18SSeth Jennings 
482062c5b6SDan Streetman static int crypto842_decompress(struct crypto_tfm *tfm,
492062c5b6SDan Streetman 				const u8 *src, unsigned int slen,
502062c5b6SDan Streetman 				u8 *dst, unsigned int *dlen)
5135a1fc18SSeth Jennings {
522062c5b6SDan Streetman 	return sw842_decompress(src, slen, dst, dlen);
5335a1fc18SSeth Jennings }
5435a1fc18SSeth Jennings 
5535a1fc18SSeth Jennings static struct crypto_alg alg = {
5635a1fc18SSeth Jennings 	.cra_name		= "842",
572062c5b6SDan Streetman 	.cra_driver_name	= "842-generic",
582062c5b6SDan Streetman 	.cra_priority		= 100,
5935a1fc18SSeth Jennings 	.cra_flags		= CRYPTO_ALG_TYPE_COMPRESS,
602062c5b6SDan Streetman 	.cra_ctxsize		= sizeof(struct crypto842_ctx),
6135a1fc18SSeth Jennings 	.cra_module		= THIS_MODULE,
6235a1fc18SSeth Jennings 	.cra_u			= { .compress = {
632062c5b6SDan Streetman 	.coa_compress		= crypto842_compress,
642062c5b6SDan Streetman 	.coa_decompress		= crypto842_decompress } }
6535a1fc18SSeth Jennings };
6635a1fc18SSeth Jennings 
672062c5b6SDan Streetman static int __init crypto842_mod_init(void)
6835a1fc18SSeth Jennings {
6935a1fc18SSeth Jennings 	return crypto_register_alg(&alg);
7035a1fc18SSeth Jennings }
712062c5b6SDan Streetman module_init(crypto842_mod_init);
7235a1fc18SSeth Jennings 
732062c5b6SDan Streetman static void __exit crypto842_mod_exit(void)
7435a1fc18SSeth Jennings {
7535a1fc18SSeth Jennings 	crypto_unregister_alg(&alg);
7635a1fc18SSeth Jennings }
772062c5b6SDan Streetman module_exit(crypto842_mod_exit);
7835a1fc18SSeth Jennings 
7935a1fc18SSeth Jennings MODULE_LICENSE("GPL");
802062c5b6SDan Streetman MODULE_DESCRIPTION("842 Software Compression Algorithm");
815d26a105SKees Cook MODULE_ALIAS_CRYPTO("842");
822062c5b6SDan Streetman MODULE_ALIAS_CRYPTO("842-generic");
832062c5b6SDan Streetman MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>");
84