meta-bsp/common: rename to meta-dreambox
[opendreambox.git] / meta-dreambox / recipes-kernel / linux / linux-dreambox-3.2 / 0002-add-crypto-api-xz-support.patch
1 From bab979da0ea46cb7f4cb384069f6de3f6a3070bc Mon Sep 17 00:00:00 2001
2 From: Andreas Monzner <andreas.monzner@dream-property.net>
3 Date: Tue, 12 Mar 2013 10:44:02 +0100
4 Subject: [PATCH 02/17] add crypto api xz support
5
6 ---
7  crypto/Kconfig  |   7 ++++
8  crypto/Makefile |   1 +
9  crypto/xz.c     | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10  3 files changed, 125 insertions(+)
11  create mode 100644 crypto/xz.c
12
13 diff --git a/crypto/Kconfig b/crypto/Kconfig
14 index 527a857..348aef4 100644
15 --- a/crypto/Kconfig
16 +++ b/crypto/Kconfig
17 @@ -886,6 +886,13 @@ config CRYPTO_LZO
18         help
19           This is the LZO algorithm.
20  
21 +config CRYPTO_XZ
22 +       tristate "XZ compression algorithm"
23 +       select CRYPTO_ALGAPI
24 +       select XZ_DEC
25 +       help
26 +         This is the XZ algorithm. Only decompression is supported for now.
27 +
28  comment "Random Number Generation"
29  
30  config CRYPTO_ANSI_CPRNG
31 diff --git a/crypto/Makefile b/crypto/Makefile
32 index 9e6eee2..12b60ae 100644
33 --- a/crypto/Makefile
34 +++ b/crypto/Makefile
35 @@ -82,6 +82,7 @@ obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
36  obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o
37  obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o
38  obj-$(CONFIG_CRYPTO_LZO) += lzo.o
39 +obj-$(CONFIG_CRYPTO_XZ) += xz.o
40  obj-$(CONFIG_CRYPTO_RNG2) += rng.o
41  obj-$(CONFIG_CRYPTO_RNG2) += krng.o
42  obj-$(CONFIG_CRYPTO_ANSI_CPRNG) += ansi_cprng.o
43 diff --git a/crypto/xz.c b/crypto/xz.c
44 new file mode 100644
45 index 0000000..2c00cfd
46 --- /dev/null
47 +++ b/crypto/xz.c
48 @@ -0,0 +1,117 @@
49 +/*
50 + * Cryptographic API.
51 + *
52 + * XZ decompression support.
53 + *
54 + * Copyright (c) 2012 Gabor Juhos <juhosg@openwrt.org>
55 + *
56 + * This program is free software; you can redistribute it and/or modify it
57 + * under the terms of the GNU General Public License version 2 as published by
58 + * the Free Software Foundation.
59 + *
60 + */
61 +#include <linux/init.h>
62 +#include <linux/module.h>
63 +#include <linux/crypto.h>
64 +#include <linux/xz.h>
65 +#include <linux/interrupt.h>
66 +#include <linux/mm.h>
67 +#include <linux/net.h>
68 +
69 +struct xz_comp_ctx {
70 +       struct xz_dec   *decomp_state;
71 +       struct xz_buf   decomp_buf;
72 +};
73 +
74 +static int crypto_xz_decomp_init(struct xz_comp_ctx *ctx)
75 +{
76 +       ctx->decomp_state = xz_dec_init(XZ_SINGLE, 0);
77 +       if (!ctx->decomp_state)
78 +               return -ENOMEM;
79 +
80 +       return 0;
81 +}
82 +
83 +static void crypto_xz_decomp_exit(struct xz_comp_ctx *ctx)
84 +{
85 +       xz_dec_end(ctx->decomp_state);
86 +}
87 +
88 +static int crypto_xz_init(struct crypto_tfm *tfm)
89 +{
90 +       struct xz_comp_ctx *ctx = crypto_tfm_ctx(tfm);
91 +
92 +       return crypto_xz_decomp_init(ctx);
93 +}
94 +
95 +static void crypto_xz_exit(struct crypto_tfm *tfm)
96 +{
97 +       struct xz_comp_ctx *ctx = crypto_tfm_ctx(tfm);
98 +
99 +       crypto_xz_decomp_exit(ctx);
100 +}
101 +
102 +static int crypto_xz_compress(struct crypto_tfm *tfm, const u8 *src,
103 +                             unsigned int slen, u8 *dst, unsigned int *dlen)
104 +{
105 +       return -EOPNOTSUPP;
106 +}
107 +
108 +static int crypto_xz_decompress(struct crypto_tfm *tfm, const u8 *src,
109 +                               unsigned int slen, u8 *dst, unsigned int *dlen)
110 +{
111 +       struct xz_comp_ctx *dctx = crypto_tfm_ctx(tfm);
112 +       struct xz_buf *xz_buf = &dctx->decomp_buf;
113 +       int ret;
114 +
115 +       memset(xz_buf, '\0', sizeof(struct xz_buf));
116 +
117 +       xz_buf->in = (u8 *) src;
118 +       xz_buf->in_pos = 0;
119 +       xz_buf->in_size = slen;
120 +       xz_buf->out = (u8 *) dst;
121 +       xz_buf->out_pos = 0;
122 +       xz_buf->out_size = *dlen;
123 +
124 +       ret = xz_dec_run(dctx->decomp_state, xz_buf);
125 +       if (ret != XZ_STREAM_END) {
126 +               ret = -EINVAL;
127 +               goto out;
128 +       }
129 +
130 +       *dlen = xz_buf->out_pos;
131 +       ret = 0;
132 +
133 +out:
134 +       return ret;
135 +}
136 +
137 +static struct crypto_alg crypto_xz_alg = {
138 +       .cra_name               = "xz",
139 +       .cra_flags              = CRYPTO_ALG_TYPE_COMPRESS,
140 +       .cra_ctxsize            = sizeof(struct xz_comp_ctx),
141 +       .cra_module             = THIS_MODULE,
142 +       .cra_list               = LIST_HEAD_INIT(crypto_xz_alg.cra_list),
143 +       .cra_init               = crypto_xz_init,
144 +       .cra_exit               = crypto_xz_exit,
145 +       .cra_u                  = { .compress = {
146 +       .coa_compress           = crypto_xz_compress,
147 +       .coa_decompress         = crypto_xz_decompress } }
148 +};
149 +
150 +static int __init crypto_xz_mod_init(void)
151 +{
152 +       return crypto_register_alg(&crypto_xz_alg);
153 +}
154 +
155 +static void __exit crypto_xz_mod_exit(void)
156 +{
157 +       crypto_unregister_alg(&crypto_xz_alg);
158 +}
159 +
160 +module_init(crypto_xz_mod_init);
161 +module_exit(crypto_xz_mod_exit);
162 +
163 +MODULE_LICENSE("GPL v2");
164 +MODULE_DESCRIPTION("Crypto XZ decompression support");
165 +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
166 -- 
167 1.8.1.2
168