]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - crypto/842.c
2 * Cryptographic API for the 842 software compression algorithm.
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.
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.
14 * Copyright (C) IBM Corporation, 2011-2015
16 * Original Authors: Robert Jennings <rcj@linux.vnet.ibm.com>
17 * Seth Jennings <sjenning@linux.vnet.ibm.com>
19 * Rewrite: Dan Streetman <ddstreet@ieee.org>
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
30 #include <linux/init.h>
31 #include <linux/module.h>
32 #include <linux/crypto.h>
33 #include <linux/sw842.h>
34 #include <crypto/internal/scompress.h>
36 struct crypto842_ctx
{
37 void *wmem
; /* working memory for compress */
40 static void *crypto842_alloc_ctx(struct crypto_scomp
*tfm
)
44 ctx
= kmalloc(SW842_MEM_COMPRESS
, GFP_KERNEL
);
46 return ERR_PTR(-ENOMEM
);
51 static int crypto842_init(struct crypto_tfm
*tfm
)
53 struct crypto842_ctx
*ctx
= crypto_tfm_ctx(tfm
);
55 ctx
->wmem
= crypto842_alloc_ctx(NULL
);
56 if (IS_ERR(ctx
->wmem
))
62 static void crypto842_free_ctx(struct crypto_scomp
*tfm
, void *ctx
)
67 static void crypto842_exit(struct crypto_tfm
*tfm
)
69 struct crypto842_ctx
*ctx
= crypto_tfm_ctx(tfm
);
71 crypto842_free_ctx(NULL
, ctx
->wmem
);
74 static int crypto842_compress(struct crypto_tfm
*tfm
,
75 const u8
*src
, unsigned int slen
,
76 u8
*dst
, unsigned int *dlen
)
78 struct crypto842_ctx
*ctx
= crypto_tfm_ctx(tfm
);
80 return sw842_compress(src
, slen
, dst
, dlen
, ctx
->wmem
);
83 static int crypto842_scompress(struct crypto_scomp
*tfm
,
84 const u8
*src
, unsigned int slen
,
85 u8
*dst
, unsigned int *dlen
, void *ctx
)
87 return sw842_compress(src
, slen
, dst
, dlen
, ctx
);
90 static int crypto842_decompress(struct crypto_tfm
*tfm
,
91 const u8
*src
, unsigned int slen
,
92 u8
*dst
, unsigned int *dlen
)
94 return sw842_decompress(src
, slen
, dst
, dlen
);
97 static int crypto842_sdecompress(struct crypto_scomp
*tfm
,
98 const u8
*src
, unsigned int slen
,
99 u8
*dst
, unsigned int *dlen
, void *ctx
)
101 return sw842_decompress(src
, slen
, dst
, dlen
);
104 static struct crypto_alg alg
= {
106 .cra_driver_name
= "842-generic",
108 .cra_flags
= CRYPTO_ALG_TYPE_COMPRESS
,
109 .cra_ctxsize
= sizeof(struct crypto842_ctx
),
110 .cra_module
= THIS_MODULE
,
111 .cra_init
= crypto842_init
,
112 .cra_exit
= crypto842_exit
,
113 .cra_u
= { .compress
= {
114 .coa_compress
= crypto842_compress
,
115 .coa_decompress
= crypto842_decompress
} }
118 static struct scomp_alg scomp
= {
119 .alloc_ctx
= crypto842_alloc_ctx
,
120 .free_ctx
= crypto842_free_ctx
,
121 .compress
= crypto842_scompress
,
122 .decompress
= crypto842_sdecompress
,
125 .cra_driver_name
= "842-scomp",
127 .cra_module
= THIS_MODULE
,
131 static int __init
crypto842_mod_init(void)
135 ret
= crypto_register_alg(&alg
);
139 ret
= crypto_register_scomp(&scomp
);
141 crypto_unregister_alg(&alg
);
147 module_init(crypto842_mod_init
);
149 static void __exit
crypto842_mod_exit(void)
151 crypto_unregister_alg(&alg
);
152 crypto_unregister_scomp(&scomp
);
154 module_exit(crypto842_mod_exit
);
156 MODULE_LICENSE("GPL");
157 MODULE_DESCRIPTION("842 Software Compression Algorithm");
158 MODULE_ALIAS_CRYPTO("842");
159 MODULE_ALIAS_CRYPTO("842-generic");
160 MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>");