5 + * LZMA uncompresion module for pcomp
6 + * Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
9 + * Initial Linux kernel adaptation
10 + * Copyright (C) 2006 Alain < alain@knaff.lu >
12 + * Based on small lzma deflate implementation/Small range coder
13 + * implementation for lzma.
14 + * Copyright (C) 2006 Aurelien Jacobs < aurel@gnuage.org >
16 + * Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/)
17 + * Copyright (C) 1999-2005 Igor Pavlov
19 + * This program is free software; you can redistribute it and/or modify it
20 + * under the terms of the GNU General Public License version 2 as published
21 + * by the Free Software Foundation.
23 + * FIXME: the current implementation assumes that the caller will
24 + * not free any output buffers until the whole decompression has been
25 + * completed. This is necessary, because LZMA looks back at old output
26 + * instead of doing a separate dictionary allocation, which saves RAM.
29 +#include <linux/init.h>
30 +#include <linux/module.h>
31 +#include <linux/vmalloc.h>
32 +#include <linux/interrupt.h>
33 +#include <linux/mm.h>
34 +#include <linux/net.h>
35 +#include <linux/slab.h>
36 +#include <linux/kthread.h>
38 +#include <crypto/internal/compress.h>
39 +#include <net/netlink.h>
42 +static int instance = 0;
44 +struct unlzma_buffer {
51 + struct task_struct *thread;
52 + wait_queue_head_t next_req;
74 + struct unlzma_buffer *buffers;
78 + u32 rep0, rep1, rep2, rep3;
87 +unlzma_should_stop(struct unlzma_ctx *ctx)
89 + return unlikely(kthread_should_stop() || ctx->cancel);
93 +get_buffer(struct unlzma_ctx *ctx)
95 + struct unlzma_buffer *bh;
97 + BUG_ON(ctx->n_buffers >= ctx->buffers_max);
98 + bh = &ctx->buffers[ctx->n_buffers++];
99 + bh->ptr = ctx->next_out;
100 + bh->offset = ctx->pos;
101 + bh->size = ctx->avail_out;
106 +unlzma_request_buffer(struct unlzma_ctx *ctx, int *avail)
109 + mutex_unlock(&ctx->mutex);
110 + if (wait_event_interruptible(ctx->next_req,
111 + unlzma_should_stop(ctx) || (*avail > 0)))
113 + mutex_lock(&ctx->mutex);
114 + } while (*avail <= 0 && !unlzma_should_stop(ctx));
116 + if (!unlzma_should_stop(ctx) && ctx->buf_full)
121 +rc_read(struct unlzma_ctx *ctx)
123 + if (unlikely(ctx->avail_in <= 0))
124 + unlzma_request_buffer(ctx, &ctx->avail_in);
126 + if (unlzma_should_stop(ctx))
130 + return *(ctx->next_in++);
135 +rc_get_code(struct unlzma_ctx *ctx)
137 + ctx->code = (ctx->code << 8) | rc_read(ctx);
141 +rc_normalize(struct unlzma_ctx *ctx)
143 + if (ctx->range < (1 << RC_TOP_BITS)) {
150 +rc_is_bit_0(struct unlzma_ctx *ctx, u16 *p)
153 + ctx->bound = *p * (ctx->range >> RC_MODEL_TOTAL_BITS);
154 + return ctx->code < ctx->bound;
158 +rc_update_bit_0(struct unlzma_ctx *ctx, u16 *p)
160 + ctx->range = ctx->bound;
161 + *p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
165 +rc_update_bit_1(struct unlzma_ctx *ctx, u16 *p)
167 + ctx->range -= ctx->bound;
168 + ctx->code -= ctx->bound;
169 + *p -= *p >> RC_MOVE_BITS;
173 +rc_get_bit(struct unlzma_ctx *ctx, u16 *p, int *symbol)
175 + if (rc_is_bit_0(ctx, p)) {
176 + rc_update_bit_0(ctx, p);
180 + rc_update_bit_1(ctx, p);
181 + *symbol = *symbol * 2 + 1;
187 +rc_direct_bit(struct unlzma_ctx *ctx)
191 + if (ctx->code >= ctx->range) {
192 + ctx->code -= ctx->range;
199 +rc_bit_tree_decode(struct unlzma_ctx *ctx, u16 *p, int num_levels, int *symbol)
201 + int i = num_levels;
205 + rc_get_bit(ctx, p + *symbol, symbol);
206 + *symbol -= 1 << num_levels;
210 +peek_old_byte(struct unlzma_ctx *ctx, u32 offs)
212 + struct unlzma_buffer *bh = &ctx->buffers[ctx->n_buffers - 1];
213 + int i = ctx->n_buffers;
216 + BUG_ON(!ctx->n_buffers);
217 + pos = ctx->pos - offs;
218 + if (pos >= ctx->dict_size) {
219 + pos = (~pos % ctx->dict_size);
222 + while (bh->offset > pos) {
229 + BUG_ON(pos >= bh->size);
231 + return bh->ptr[pos];
235 +write_byte(struct unlzma_ctx *ctx, u8 byte)
237 + if (unlikely(ctx->avail_out <= 0)) {
238 + unlzma_request_buffer(ctx, &ctx->avail_out);
241 + if (!ctx->avail_out)
244 + ctx->previous_byte = byte;
245 + *(ctx->next_out++) = byte;
247 + if (ctx->avail_out == 0)
254 +copy_byte(struct unlzma_ctx *ctx, u32 offs)
256 + write_byte(ctx, peek_old_byte(ctx, offs));
260 +copy_bytes(struct unlzma_ctx *ctx, u32 rep0, int len)
263 + copy_byte(ctx, rep0);
265 + if (unlzma_should_stop(ctx))
267 + } while (len != 0);
271 +process_bit0(struct unlzma_ctx *ctx, u16 *p, int pos_state, u16 *prob,
272 + int lc, u32 literal_pos_mask)
275 + rc_update_bit_0(ctx, prob);
276 + prob = (p + LZMA_LITERAL +
278 + * (((ctx->pos & literal_pos_mask) << lc)
279 + + (ctx->previous_byte >> (8 - lc))))
282 + if (ctx->state >= LZMA_NUM_LIT_STATES) {
283 + int match_byte = peek_old_byte(ctx, ctx->rep0);
289 + bit = match_byte & 0x100;
290 + prob_lit = prob + 0x100 + bit + mi;
291 + if (rc_get_bit(ctx, prob_lit, &mi) != !!bit)
293 + } while (mi < 0x100);
295 + while (mi < 0x100) {
296 + u16 *prob_lit = prob + mi;
297 + rc_get_bit(ctx, prob_lit, &mi);
299 + write_byte(ctx, mi);
300 + if (ctx->state < 4)
302 + else if (ctx->state < 10)
309 +process_bit1(struct unlzma_ctx *ctx, u16 *p, int pos_state, u16 *prob)
316 + rc_update_bit_1(ctx, prob);
317 + prob = p + LZMA_IS_REP + ctx->state;
318 + if (rc_is_bit_0(ctx, prob)) {
319 + rc_update_bit_0(ctx, prob);
320 + ctx->rep3 = ctx->rep2;
321 + ctx->rep2 = ctx->rep1;
322 + ctx->rep1 = ctx->rep0;
323 + ctx->state = ctx->state < LZMA_NUM_LIT_STATES ? 0 : 3;
324 + prob = p + LZMA_LEN_CODER;
326 + rc_update_bit_1(ctx, prob);
327 + prob = p + LZMA_IS_REP_G0 + ctx->state;
328 + if (rc_is_bit_0(ctx, prob)) {
329 + rc_update_bit_0(ctx, prob);
330 + prob = (p + LZMA_IS_REP_0_LONG
332 + LZMA_NUM_POS_BITS_MAX) +
334 + if (rc_is_bit_0(ctx, prob)) {
335 + rc_update_bit_0(ctx, prob);
337 + ctx->state = ctx->state < LZMA_NUM_LIT_STATES ?
339 + copy_byte(ctx, ctx->rep0);
342 + rc_update_bit_1(ctx, prob);
347 + rc_update_bit_1(ctx, prob);
348 + prob = p + LZMA_IS_REP_G1 + ctx->state;
349 + if (rc_is_bit_0(ctx, prob)) {
350 + rc_update_bit_0(ctx, prob);
351 + distance = ctx->rep1;
353 + rc_update_bit_1(ctx, prob);
354 + prob = p + LZMA_IS_REP_G2 + ctx->state;
355 + if (rc_is_bit_0(ctx, prob)) {
356 + rc_update_bit_0(ctx, prob);
357 + distance = ctx->rep2;
359 + rc_update_bit_1(ctx, prob);
360 + distance = ctx->rep3;
361 + ctx->rep3 = ctx->rep2;
363 + ctx->rep2 = ctx->rep1;
365 + ctx->rep1 = ctx->rep0;
366 + ctx->rep0 = distance;
368 + ctx->state = ctx->state < LZMA_NUM_LIT_STATES ? 8 : 11;
369 + prob = p + LZMA_REP_LEN_CODER;
372 + prob_len = prob + LZMA_LEN_CHOICE;
373 + if (rc_is_bit_0(ctx, prob_len)) {
374 + rc_update_bit_0(ctx, prob_len);
375 + prob_len = (prob + LZMA_LEN_LOW
377 + LZMA_LEN_NUM_LOW_BITS));
379 + num_bits = LZMA_LEN_NUM_LOW_BITS;
381 + rc_update_bit_1(ctx, prob_len);
382 + prob_len = prob + LZMA_LEN_CHOICE_2;
383 + if (rc_is_bit_0(ctx, prob_len)) {
384 + rc_update_bit_0(ctx, prob_len);
385 + prob_len = (prob + LZMA_LEN_MID
387 + LZMA_LEN_NUM_MID_BITS));
388 + offset = 1 << LZMA_LEN_NUM_LOW_BITS;
389 + num_bits = LZMA_LEN_NUM_MID_BITS;
391 + rc_update_bit_1(ctx, prob_len);
392 + prob_len = prob + LZMA_LEN_HIGH;
393 + offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
394 + + (1 << LZMA_LEN_NUM_MID_BITS));
395 + num_bits = LZMA_LEN_NUM_HIGH_BITS;
399 + rc_bit_tree_decode(ctx, prob_len, num_bits, &len);
402 + if (ctx->state < 4) {
405 + ctx->state += LZMA_NUM_LIT_STATES;
407 + p + LZMA_POS_SLOT +
409 + LZMA_NUM_LEN_TO_POS_STATES ? len :
410 + LZMA_NUM_LEN_TO_POS_STATES - 1)
411 + << LZMA_NUM_POS_SLOT_BITS);
412 + rc_bit_tree_decode(ctx, prob,
413 + LZMA_NUM_POS_SLOT_BITS,
415 + if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
417 + num_bits = (pos_slot >> 1) - 1;
418 + ctx->rep0 = 2 | (pos_slot & 1);
419 + if (pos_slot < LZMA_END_POS_MODEL_INDEX) {
420 + ctx->rep0 <<= num_bits;
421 + prob = p + LZMA_SPEC_POS +
422 + ctx->rep0 - pos_slot - 1;
424 + num_bits -= LZMA_NUM_ALIGN_BITS;
426 + ctx->rep0 = (ctx->rep0 << 1) |
427 + rc_direct_bit(ctx);
428 + prob = p + LZMA_ALIGN;
429 + ctx->rep0 <<= LZMA_NUM_ALIGN_BITS;
430 + num_bits = LZMA_NUM_ALIGN_BITS;
434 + while (num_bits--) {
435 + if (rc_get_bit(ctx, prob + mi, &mi))
440 + ctx->rep0 = pos_slot;
441 + if (++(ctx->rep0) == 0)
445 + len += LZMA_MATCH_MIN_LEN;
447 + copy_bytes(ctx, ctx->rep0, len);
452 +do_unlzma(struct unlzma_ctx *ctx)
454 + u8 hdr_buf[sizeof(struct lzma_header)];
455 + struct lzma_header *header = (struct lzma_header *)hdr_buf;
456 + u32 pos_state_mask;
457 + u32 literal_pos_mask;
463 + for (i = 0; i < sizeof(struct lzma_header); i++) {
464 + hdr_buf[i] = rc_read(ctx);
467 + ctx->n_buffers = 0;
470 + ctx->active = true;
472 + ctx->rep0 = ctx->rep1 = ctx->rep2 = ctx->rep3 = 1;
474 + ctx->previous_byte = 0;
476 + ctx->range = 0xFFFFFFFF;
478 + ctx->dict_size = le32_to_cpu(header->dict_size);
480 + if (header->pos >= (9 * 5 * 5))
495 + pos_state_mask = (1 << pb) - 1;
496 + literal_pos_mask = (1 << lp) - 1;
498 + if (ctx->dict_size == 0)
499 + ctx->dict_size = 1;
501 + num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
502 + if (ctx->workspace_size < num_probs * sizeof(*p)) {
503 + if (ctx->workspace)
504 + vfree(ctx->workspace);
505 + ctx->workspace_size = num_probs * sizeof(*p);
506 + ctx->workspace = vmalloc(ctx->workspace_size);
508 + p = (u16 *) ctx->workspace;
512 + num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp));
513 + for (i = 0; i < num_probs; i++)
514 + p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
516 + for (i = 0; i < 5; i++)
520 + int pos_state = ctx->pos & pos_state_mask;
521 + u16 *prob = p + LZMA_IS_MATCH +
522 + (ctx->state << LZMA_NUM_POS_BITS_MAX) + pos_state;
523 + if (rc_is_bit_0(ctx, prob))
524 + process_bit0(ctx, p, pos_state, prob,
525 + lc, literal_pos_mask);
527 + process_bit1(ctx, p, pos_state, prob);
528 + if (ctx->rep0 == 0)
531 + if (unlzma_should_stop(ctx))
534 + if (likely(!unlzma_should_stop(ctx)))
542 +unlzma_reset_buf(struct unlzma_ctx *ctx)
545 + ctx->next_in = NULL;
546 + ctx->avail_out = 0;
547 + ctx->next_out = NULL;
551 +unlzma_thread(void *data)
553 + struct unlzma_ctx *ctx = data;
555 + mutex_lock(&ctx->mutex);
557 + if (do_unlzma(ctx) < 0)
559 + unlzma_reset_buf(ctx);
560 + ctx->cancel = false;
561 + ctx->active = false;
562 + } while (!kthread_should_stop());
563 + mutex_unlock(&ctx->mutex);
569 +unlzma_init(struct crypto_tfm *tfm)
575 +unlzma_cancel(struct unlzma_ctx *ctx)
577 + unlzma_reset_buf(ctx);
582 + ctx->cancel = true;
584 + mutex_unlock(&ctx->mutex);
585 + wake_up(&ctx->next_req);
587 + mutex_lock(&ctx->mutex);
588 + } while (ctx->cancel);
593 +unlzma_exit(struct crypto_tfm *tfm)
595 + struct unlzma_ctx *ctx = crypto_tfm_ctx(tfm);
598 + unlzma_cancel(ctx);
599 + kthread_stop(ctx->thread);
600 + ctx->thread = NULL;
602 + kfree(ctx->buffers);
603 + ctx->buffers_max = 0;
604 + ctx->buffers = NULL;
609 +unlzma_decompress_setup(struct crypto_pcomp *tfm, void *p, unsigned int len)
611 + struct unlzma_ctx *ctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
612 + struct nlattr *tb[UNLZMA_DECOMP_MAX + 1];
621 + ret = nla_parse(tb, UNLZMA_DECOMP_MAX, p, len, NULL);
622 + if (!tb[UNLZMA_DECOMP_OUT_BUFFERS])
625 + if (ctx->buffers_max && (ctx->buffers_max <
626 + nla_get_u32(tb[UNLZMA_DECOMP_OUT_BUFFERS]))) {
627 + kfree(ctx->buffers);
628 + ctx->buffers_max = 0;
629 + ctx->buffers = NULL;
631 + if (!ctx->buffers) {
632 + ctx->buffers_max = nla_get_u32(tb[UNLZMA_DECOMP_OUT_BUFFERS]);
633 + ctx->buffers = kzalloc(sizeof(struct unlzma_buffer) * ctx->buffers_max, GFP_KERNEL);
638 + mutex_init(&ctx->mutex);
639 + init_waitqueue_head(&ctx->next_req);
640 + ctx->thread = kthread_run(unlzma_thread, ctx, "unlzma/%d", instance++);
641 + if (IS_ERR(ctx->thread)) {
642 + ret = PTR_ERR(ctx->thread);
643 + ctx->thread = NULL;
650 +unlzma_decompress_init(struct crypto_pcomp *tfm)
652 + struct unlzma_ctx *ctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
659 +unlzma_wait_complete(struct unlzma_ctx *ctx, bool finish)
662 + mutex_unlock(&ctx->mutex);
663 + wake_up(&ctx->next_req);
665 + mutex_lock(&ctx->mutex);
666 + } while (ctx->active && (ctx->avail_in > 0) && (ctx->avail_out > 0));
670 +unlzma_decompress_update(struct crypto_pcomp *tfm, struct comp_request *req)
672 + struct unlzma_ctx *ctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
675 + mutex_lock(&ctx->mutex);
676 + if (!ctx->active && !req->avail_in)
680 + ctx->next_in = req->next_in;
681 + ctx->avail_in = req->avail_in;
682 + ctx->next_out = req->next_out;
683 + ctx->avail_out = req->avail_out;
685 + unlzma_wait_complete(ctx, false);
687 + req->next_in = ctx->next_in;
688 + req->avail_in = ctx->avail_in;
689 + req->next_out = ctx->next_out;
690 + req->avail_out = ctx->avail_out;
693 + pos = ctx->pos - pos;
696 + mutex_unlock(&ctx->mutex);
701 +unlzma_decompress_final(struct crypto_pcomp *tfm, struct comp_request *req)
703 + struct unlzma_ctx *ctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
706 + /* cancel pending operation */
707 + mutex_lock(&ctx->mutex);
710 + unlzma_cancel(ctx);
713 + mutex_unlock(&ctx->mutex);
718 +static struct pcomp_alg unlzma_alg = {
719 + .decompress_setup = unlzma_decompress_setup,
720 + .decompress_init = unlzma_decompress_init,
721 + .decompress_update = unlzma_decompress_update,
722 + .decompress_final = unlzma_decompress_final,
725 + .cra_name = "lzma",
726 + .cra_flags = CRYPTO_ALG_TYPE_PCOMPRESS,
727 + .cra_ctxsize = sizeof(struct unlzma_ctx),
728 + .cra_module = THIS_MODULE,
729 + .cra_init = unlzma_init,
730 + .cra_exit = unlzma_exit,
735 +unlzma_mod_init(void)
737 + return crypto_register_pcomp(&unlzma_alg);
741 +unlzma_mod_exit(void)
743 + crypto_unregister_pcomp(&unlzma_alg);
746 +module_init(unlzma_mod_init);
747 +module_exit(unlzma_mod_exit);
749 +MODULE_LICENSE("GPL");
750 +MODULE_DESCRIPTION("LZMA Decompression Algorithm");
751 +MODULE_AUTHOR("Felix Fietkau <nbd@openwrt.org>");
754 @@ -758,6 +758,12 @@ config CRYPTO_ZLIB
756 This is the zlib algorithm.
758 +config CRYPTO_UNLZMA
759 + tristate "LZMA decompression"
760 + select CRYPTO_PCOMP
762 + This is the lzma decompression module.
765 tristate "LZO compression algorithm"
767 --- a/crypto/Makefile
768 +++ b/crypto/Makefile
769 @@ -75,6 +75,7 @@ obj-$(CONFIG_CRYPTO_SEED) += seed.o
770 obj-$(CONFIG_CRYPTO_SALSA20) += salsa20_generic.o
771 obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o
772 obj-$(CONFIG_CRYPTO_ZLIB) += zlib.o
773 +obj-$(CONFIG_CRYPTO_UNLZMA) += unlzma.o
774 obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
775 obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o
776 obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o
778 +++ b/crypto/unlzma.h
780 +/* LZMA uncompresion module for pcomp
781 + * Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
784 + * Initial Linux kernel adaptation
785 + * Copyright (C) 2006 Alain < alain@knaff.lu >
787 + * Based on small lzma deflate implementation/Small range coder
788 + * implementation for lzma.
789 + * Copyright (C) 2006 Aurelien Jacobs < aurel@gnuage.org >
791 + * Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/)
792 + * Copyright (C) 1999-2005 Igor Pavlov
794 + * This program is free software; you can redistribute it and/or modify it
795 + * under the terms of the GNU General Public License version 2 as published
796 + * by the Free Software Foundation.
801 +struct lzma_header {
804 +} __attribute__ ((packed)) ;
807 +#define RC_TOP_BITS 24
808 +#define RC_MOVE_BITS 5
809 +#define RC_MODEL_TOTAL_BITS 11
811 +#define LZMA_BASE_SIZE 1846
812 +#define LZMA_LIT_SIZE 768
814 +#define LZMA_NUM_POS_BITS_MAX 4
816 +#define LZMA_LEN_NUM_LOW_BITS 3
817 +#define LZMA_LEN_NUM_MID_BITS 3
818 +#define LZMA_LEN_NUM_HIGH_BITS 8
820 +#define LZMA_LEN_CHOICE 0
821 +#define LZMA_LEN_CHOICE_2 (LZMA_LEN_CHOICE + 1)
822 +#define LZMA_LEN_LOW (LZMA_LEN_CHOICE_2 + 1)
823 +#define LZMA_LEN_MID (LZMA_LEN_LOW \
824 + + (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_LOW_BITS)))
825 +#define LZMA_LEN_HIGH (LZMA_LEN_MID \
826 + +(1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_MID_BITS)))
827 +#define LZMA_NUM_LEN_PROBS (LZMA_LEN_HIGH + (1 << LZMA_LEN_NUM_HIGH_BITS))
829 +#define LZMA_NUM_STATES 12
830 +#define LZMA_NUM_LIT_STATES 7
832 +#define LZMA_START_POS_MODEL_INDEX 4
833 +#define LZMA_END_POS_MODEL_INDEX 14
834 +#define LZMA_NUM_FULL_DISTANCES (1 << (LZMA_END_POS_MODEL_INDEX >> 1))
836 +#define LZMA_NUM_POS_SLOT_BITS 6
837 +#define LZMA_NUM_LEN_TO_POS_STATES 4
839 +#define LZMA_NUM_ALIGN_BITS 4
841 +#define LZMA_MATCH_MIN_LEN 2
843 +#define LZMA_IS_MATCH 0
844 +#define LZMA_IS_REP (LZMA_IS_MATCH + (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX))
845 +#define LZMA_IS_REP_G0 (LZMA_IS_REP + LZMA_NUM_STATES)
846 +#define LZMA_IS_REP_G1 (LZMA_IS_REP_G0 + LZMA_NUM_STATES)
847 +#define LZMA_IS_REP_G2 (LZMA_IS_REP_G1 + LZMA_NUM_STATES)
848 +#define LZMA_IS_REP_0_LONG (LZMA_IS_REP_G2 + LZMA_NUM_STATES)
849 +#define LZMA_POS_SLOT (LZMA_IS_REP_0_LONG \
850 + + (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX))
851 +#define LZMA_SPEC_POS (LZMA_POS_SLOT \
852 + +(LZMA_NUM_LEN_TO_POS_STATES << LZMA_NUM_POS_SLOT_BITS))
853 +#define LZMA_ALIGN (LZMA_SPEC_POS \
854 + + LZMA_NUM_FULL_DISTANCES - LZMA_END_POS_MODEL_INDEX)
855 +#define LZMA_LEN_CODER (LZMA_ALIGN + (1 << LZMA_NUM_ALIGN_BITS))
856 +#define LZMA_REP_LEN_CODER (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS)
857 +#define LZMA_LITERAL (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS)
860 --- a/include/crypto/compress.h
861 +++ b/include/crypto/compress.h
862 @@ -49,6 +49,12 @@ enum zlib_decomp_params {
864 #define ZLIB_DECOMP_MAX (__ZLIB_DECOMP_MAX - 1)
866 +enum unlzma_decomp_params {
867 + UNLZMA_DECOMP_OUT_BUFFERS = 1, /* naximum number of output buffers */
868 + __UNLZMA_DECOMP_MAX,
870 +#define UNLZMA_DECOMP_MAX (__UNLZMA_DECOMP_MAX - 1)
873 struct crypto_pcomp {
874 struct crypto_tfm base;