Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 1 | /* |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 2 | * Cryptographic API for the 842 software compression algorithm. |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 14 | * Copyright (C) IBM Corporation, 2011-2015 |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 15 | * |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 16 | * Original Authors: Robert Jennings <rcj@linux.vnet.ibm.com> |
| 17 | * Seth Jennings <sjenning@linux.vnet.ibm.com> |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 18 | * |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 19 | * Rewrite: Dan Streetman <ddstreet@ieee.org> |
| 20 | * |
| 21 | * This is the software implementation of compression and decompression using |
| 22 | * the 842 format. This uses the software 842 library at lib/842/ which is |
| 23 | * only a reference implementation, and is very, very slow as compared to other |
| 24 | * software compressors. You probably do not want to use this software |
| 25 | * compression. If you have access to the PowerPC 842 compression hardware, you |
| 26 | * want to use the 842 hardware compression interface, which is at: |
| 27 | * drivers/crypto/nx/nx-842-crypto.c |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 28 | */ |
| 29 | |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/crypto.h> |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 33 | #include <linux/sw842.h> |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 34 | |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 35 | struct crypto842_ctx { |
| 36 | char wmem[SW842_MEM_COMPRESS]; /* working memory for compress */ |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 37 | }; |
| 38 | |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 39 | static int crypto842_compress(struct crypto_tfm *tfm, |
| 40 | const u8 *src, unsigned int slen, |
| 41 | u8 *dst, unsigned int *dlen) |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 42 | { |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 43 | struct crypto842_ctx *ctx = crypto_tfm_ctx(tfm); |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 44 | |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 45 | return sw842_compress(src, slen, dst, dlen, ctx->wmem); |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 46 | } |
| 47 | |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 48 | static int crypto842_decompress(struct crypto_tfm *tfm, |
| 49 | const u8 *src, unsigned int slen, |
| 50 | u8 *dst, unsigned int *dlen) |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 51 | { |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 52 | return sw842_decompress(src, slen, dst, dlen); |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static struct crypto_alg alg = { |
| 56 | .cra_name = "842", |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 57 | .cra_driver_name = "842-generic", |
| 58 | .cra_priority = 100, |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 59 | .cra_flags = CRYPTO_ALG_TYPE_COMPRESS, |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 60 | .cra_ctxsize = sizeof(struct crypto842_ctx), |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 61 | .cra_module = THIS_MODULE, |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 62 | .cra_u = { .compress = { |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 63 | .coa_compress = crypto842_compress, |
| 64 | .coa_decompress = crypto842_decompress } } |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 65 | }; |
| 66 | |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 67 | static int __init crypto842_mod_init(void) |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 68 | { |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 69 | return crypto_register_alg(&alg); |
| 70 | } |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 71 | module_init(crypto842_mod_init); |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 72 | |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 73 | static void __exit crypto842_mod_exit(void) |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 74 | { |
| 75 | crypto_unregister_alg(&alg); |
| 76 | } |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 77 | module_exit(crypto842_mod_exit); |
Seth Jennings | 35a1fc1 | 2012-07-19 09:42:41 -0500 | [diff] [blame] | 78 | |
| 79 | MODULE_LICENSE("GPL"); |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 80 | MODULE_DESCRIPTION("842 Software Compression Algorithm"); |
Kees Cook | 5d26a10 | 2014-11-20 17:05:53 -0800 | [diff] [blame] | 81 | MODULE_ALIAS_CRYPTO("842"); |
Dan Streetman | 2062c5b | 2015-05-07 13:49:15 -0400 | [diff] [blame^] | 82 | MODULE_ALIAS_CRYPTO("842-generic"); |
| 83 | MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>"); |