Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/crypto/842.c
26131 views
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 <[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
.alloc_ctx = crypto842_alloc_ctx,
58
.free_ctx = crypto842_free_ctx,
59
.compress = crypto842_scompress,
60
.decompress = crypto842_sdecompress,
61
.base = {
62
.cra_name = "842",
63
.cra_driver_name = "842-scomp",
64
.cra_priority = 100,
65
.cra_module = THIS_MODULE,
66
}
67
};
68
69
static int __init crypto842_mod_init(void)
70
{
71
return crypto_register_scomp(&scomp);
72
}
73
module_init(crypto842_mod_init);
74
75
static void __exit crypto842_mod_exit(void)
76
{
77
crypto_unregister_scomp(&scomp);
78
}
79
module_exit(crypto842_mod_exit);
80
81
MODULE_LICENSE("GPL");
82
MODULE_DESCRIPTION("842 Software Compression Algorithm");
83
MODULE_ALIAS_CRYPTO("842");
84
MODULE_ALIAS_CRYPTO("842-generic");
85
MODULE_AUTHOR("Dan Streetman <[email protected]>");
86
87