| 1 | |
| 2 | |
| 3 | * Cryptographic API for the 842 software compression algorithm.
|
| 4 | *
|
| 5 | * Copyright (C) IBM Corporation, 2011-2015
|
| 6 | *
|
| 7 | * Original Authors: Robert Jennings <[email protected]>
|
| 8 | * Seth Jennings <[email protected]>
|
| 9 | *
|
| 10 | * Rewrite: Dan Streetman <[email protected]>
|
| 11 | *
|
| 12 | * This is the software implementation of compression and decompression using
|
| 13 | * the 842 format. This uses the software 842 library at lib/842/ which is
|
| 14 | * only a reference implementation, and is very, very slow as compared to other
|
| 15 | * software compressors. You probably do not want to use this software
|
| 16 | * compression. If you have access to the PowerPC 842 compression hardware, you
|
| 17 | * want to use the 842 hardware compression interface, which is at:
|
| 18 | * drivers/crypto/nx/nx-842-crypto.c
|
| 19 |
|
| 20 |
|
| 21 | #include <crypto/internal/scompress.h>
|
| 22 | #include <linux/init.h>
|
| 23 | #include <linux/module.h>
|
| 24 | #include <linux/sw842.h>
|
| 25 |
|
| 26 | static void *crypto842_alloc_ctx(void)
|
| 27 | {
|
| 28 | void *ctx;
|
| 29 |
|
| 30 | ctx = kmalloc(SW842_MEM_COMPRESS, GFP_KERNEL);
|
| 31 | if (!ctx)
|
| 32 | return ERR_PTR(-ENOMEM);
|
| 33 |
|
| 34 | return ctx;
|
| 35 | }
|
| 36 |
|
| 37 | static void crypto842_free_ctx(void *ctx)
|
| 38 | {
|
| 39 | kfree(ctx);
|
| 40 | }
|
| 41 |
|
| 42 | static int crypto842_scompress(struct crypto_scomp *tfm,
|
| 43 | const u8 *src, unsigned int slen,
|
| 44 | u8 *dst, unsigned int *dlen, void *ctx)
|
| 45 | {
|
| 46 | return sw842_compress(src, slen, dst, dlen, ctx);
|
| 47 | }
|
| 48 |
|
| 49 | static int crypto842_sdecompress(struct crypto_scomp *tfm,
|
| 50 | const u8 *src, unsigned int slen,
|
| 51 | u8 *dst, unsigned int *dlen, void *ctx)
|
| 52 | {
|
| 53 | return sw842_decompress(src, slen, dst, dlen);
|
| 54 | }
|
| 55 |
|
| 56 | static struct scomp_alg scomp = {
|
| 57 | .streams = {
|
| 58 | .alloc_ctx = crypto842_alloc_ctx,
|
| 59 | .free_ctx = crypto842_free_ctx,
|
| 60 | },
|
| 61 | .compress = crypto842_scompress,
|
| 62 | .decompress = crypto842_sdecompress,
|
| 63 | .base = {
|
| 64 | .cra_name = "842",
|
| 65 | .cra_driver_name = "842-scomp",
|
| 66 | .cra_priority = 100,
|
| 67 | .cra_module = THIS_MODULE,
|
| 68 | }
|
| 69 | };
|
| 70 |
|
| 71 | static int __init crypto842_mod_init(void)
|
| 72 | {
|
| 73 | return crypto_register_scomp(&scomp);
|
| 74 | }
|
| 75 | module_init(crypto842_mod_init);
|
| 76 |
|
| 77 | static void __exit crypto842_mod_exit(void)
|
| 78 | {
|
| 79 | crypto_unregister_scomp(&scomp);
|
| 80 | }
|
| 81 | module_exit(crypto842_mod_exit);
|
| 82 |
|
| 83 | MODULE_LICENSE("GPL");
|
| 84 | MODULE_DESCRIPTION("842 Software Compression Algorithm");
|
| 85 | MODULE_ALIAS_CRYPTO("842");
|
| 86 | MODULE_ALIAS_CRYPTO("842-generic");
|
| 87 | MODULE_AUTHOR("Dan Streetman <[email protected]>");
|