Linux Audio

Check our new training course

Loading...
v5.4
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * Cryptographic API for the 842 software compression algorithm.
  4 *
 
 
 
 
 
 
 
 
 
 
  5 * Copyright (C) IBM Corporation, 2011-2015
  6 *
  7 * Original Authors: Robert Jennings <rcj@linux.vnet.ibm.com>
  8 *                   Seth Jennings <sjenning@linux.vnet.ibm.com>
  9 *
 10 * Rewrite: Dan Streetman <ddstreet@ieee.org>
 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 <linux/init.h>
 22#include <linux/module.h>
 23#include <linux/crypto.h>
 24#include <linux/sw842.h>
 25#include <crypto/internal/scompress.h>
 26
 27struct crypto842_ctx {
 28	void *wmem;	/* working memory for compress */
 29};
 30
 31static void *crypto842_alloc_ctx(struct crypto_scomp *tfm)
 32{
 33	void *ctx;
 34
 35	ctx = kmalloc(SW842_MEM_COMPRESS, GFP_KERNEL);
 36	if (!ctx)
 37		return ERR_PTR(-ENOMEM);
 38
 39	return ctx;
 40}
 41
 42static int crypto842_init(struct crypto_tfm *tfm)
 43{
 44	struct crypto842_ctx *ctx = crypto_tfm_ctx(tfm);
 45
 46	ctx->wmem = crypto842_alloc_ctx(NULL);
 47	if (IS_ERR(ctx->wmem))
 48		return -ENOMEM;
 49
 50	return 0;
 51}
 52
 53static void crypto842_free_ctx(struct crypto_scomp *tfm, void *ctx)
 54{
 55	kfree(ctx);
 56}
 57
 58static void crypto842_exit(struct crypto_tfm *tfm)
 59{
 60	struct crypto842_ctx *ctx = crypto_tfm_ctx(tfm);
 61
 62	crypto842_free_ctx(NULL, ctx->wmem);
 63}
 64
 65static int crypto842_compress(struct crypto_tfm *tfm,
 66			      const u8 *src, unsigned int slen,
 67			      u8 *dst, unsigned int *dlen)
 68{
 69	struct crypto842_ctx *ctx = crypto_tfm_ctx(tfm);
 70
 71	return sw842_compress(src, slen, dst, dlen, ctx->wmem);
 72}
 73
 74static int crypto842_scompress(struct crypto_scomp *tfm,
 75			       const u8 *src, unsigned int slen,
 76			       u8 *dst, unsigned int *dlen, void *ctx)
 77{
 78	return sw842_compress(src, slen, dst, dlen, ctx);
 79}
 80
 81static int crypto842_decompress(struct crypto_tfm *tfm,
 82				const u8 *src, unsigned int slen,
 83				u8 *dst, unsigned int *dlen)
 84{
 85	return sw842_decompress(src, slen, dst, dlen);
 86}
 87
 88static int crypto842_sdecompress(struct crypto_scomp *tfm,
 89				 const u8 *src, unsigned int slen,
 90				 u8 *dst, unsigned int *dlen, void *ctx)
 91{
 92	return sw842_decompress(src, slen, dst, dlen);
 93}
 94
 95static struct crypto_alg alg = {
 96	.cra_name		= "842",
 97	.cra_driver_name	= "842-generic",
 98	.cra_priority		= 100,
 99	.cra_flags		= CRYPTO_ALG_TYPE_COMPRESS,
100	.cra_ctxsize		= sizeof(struct crypto842_ctx),
101	.cra_module		= THIS_MODULE,
102	.cra_init		= crypto842_init,
103	.cra_exit		= crypto842_exit,
104	.cra_u			= { .compress = {
105	.coa_compress		= crypto842_compress,
106	.coa_decompress		= crypto842_decompress } }
107};
108
109static struct scomp_alg scomp = {
110	.alloc_ctx		= crypto842_alloc_ctx,
111	.free_ctx		= crypto842_free_ctx,
112	.compress		= crypto842_scompress,
113	.decompress		= crypto842_sdecompress,
114	.base			= {
115		.cra_name	= "842",
116		.cra_driver_name = "842-scomp",
117		.cra_priority	 = 100,
118		.cra_module	 = THIS_MODULE,
119	}
120};
121
122static int __init crypto842_mod_init(void)
123{
124	int ret;
125
126	ret = crypto_register_alg(&alg);
127	if (ret)
128		return ret;
129
130	ret = crypto_register_scomp(&scomp);
131	if (ret) {
132		crypto_unregister_alg(&alg);
133		return ret;
134	}
135
136	return ret;
137}
138subsys_initcall(crypto842_mod_init);
139
140static void __exit crypto842_mod_exit(void)
141{
142	crypto_unregister_alg(&alg);
143	crypto_unregister_scomp(&scomp);
144}
145module_exit(crypto842_mod_exit);
146
147MODULE_LICENSE("GPL");
148MODULE_DESCRIPTION("842 Software Compression Algorithm");
149MODULE_ALIAS_CRYPTO("842");
150MODULE_ALIAS_CRYPTO("842-generic");
151MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>");
v4.17
 
  1/*
  2 * Cryptographic API for the 842 software compression algorithm.
  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 *
 14 * Copyright (C) IBM Corporation, 2011-2015
 15 *
 16 * Original Authors: Robert Jennings <rcj@linux.vnet.ibm.com>
 17 *                   Seth Jennings <sjenning@linux.vnet.ibm.com>
 18 *
 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
 28 */
 29
 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>
 35
 36struct crypto842_ctx {
 37	void *wmem;	/* working memory for compress */
 38};
 39
 40static void *crypto842_alloc_ctx(struct crypto_scomp *tfm)
 41{
 42	void *ctx;
 43
 44	ctx = kmalloc(SW842_MEM_COMPRESS, GFP_KERNEL);
 45	if (!ctx)
 46		return ERR_PTR(-ENOMEM);
 47
 48	return ctx;
 49}
 50
 51static int crypto842_init(struct crypto_tfm *tfm)
 52{
 53	struct crypto842_ctx *ctx = crypto_tfm_ctx(tfm);
 54
 55	ctx->wmem = crypto842_alloc_ctx(NULL);
 56	if (IS_ERR(ctx->wmem))
 57		return -ENOMEM;
 58
 59	return 0;
 60}
 61
 62static void crypto842_free_ctx(struct crypto_scomp *tfm, void *ctx)
 63{
 64	kfree(ctx);
 65}
 66
 67static void crypto842_exit(struct crypto_tfm *tfm)
 68{
 69	struct crypto842_ctx *ctx = crypto_tfm_ctx(tfm);
 70
 71	crypto842_free_ctx(NULL, ctx->wmem);
 72}
 73
 74static int crypto842_compress(struct crypto_tfm *tfm,
 75			      const u8 *src, unsigned int slen,
 76			      u8 *dst, unsigned int *dlen)
 77{
 78	struct crypto842_ctx *ctx = crypto_tfm_ctx(tfm);
 79
 80	return sw842_compress(src, slen, dst, dlen, ctx->wmem);
 81}
 82
 83static int crypto842_scompress(struct crypto_scomp *tfm,
 84			       const u8 *src, unsigned int slen,
 85			       u8 *dst, unsigned int *dlen, void *ctx)
 86{
 87	return sw842_compress(src, slen, dst, dlen, ctx);
 88}
 89
 90static int crypto842_decompress(struct crypto_tfm *tfm,
 91				const u8 *src, unsigned int slen,
 92				u8 *dst, unsigned int *dlen)
 93{
 94	return sw842_decompress(src, slen, dst, dlen);
 95}
 96
 97static int crypto842_sdecompress(struct crypto_scomp *tfm,
 98				 const u8 *src, unsigned int slen,
 99				 u8 *dst, unsigned int *dlen, void *ctx)
100{
101	return sw842_decompress(src, slen, dst, dlen);
102}
103
104static struct crypto_alg alg = {
105	.cra_name		= "842",
106	.cra_driver_name	= "842-generic",
107	.cra_priority		= 100,
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 } }
116};
117
118static struct scomp_alg scomp = {
119	.alloc_ctx		= crypto842_alloc_ctx,
120	.free_ctx		= crypto842_free_ctx,
121	.compress		= crypto842_scompress,
122	.decompress		= crypto842_sdecompress,
123	.base			= {
124		.cra_name	= "842",
125		.cra_driver_name = "842-scomp",
126		.cra_priority	 = 100,
127		.cra_module	 = THIS_MODULE,
128	}
129};
130
131static int __init crypto842_mod_init(void)
132{
133	int ret;
134
135	ret = crypto_register_alg(&alg);
136	if (ret)
137		return ret;
138
139	ret = crypto_register_scomp(&scomp);
140	if (ret) {
141		crypto_unregister_alg(&alg);
142		return ret;
143	}
144
145	return ret;
146}
147module_init(crypto842_mod_init);
148
149static void __exit crypto842_mod_exit(void)
150{
151	crypto_unregister_alg(&alg);
152	crypto_unregister_scomp(&scomp);
153}
154module_exit(crypto842_mod_exit);
155
156MODULE_LICENSE("GPL");
157MODULE_DESCRIPTION("842 Software Compression Algorithm");
158MODULE_ALIAS_CRYPTO("842");
159MODULE_ALIAS_CRYPTO("842-generic");
160MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>");