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;
53 + wait_queue_head_t req_done;
76 + struct unlzma_buffer *buffers;
80 + u32 rep0, rep1, rep2, rep3;
89 +unlzma_should_stop(struct unlzma_ctx *ctx)
91 + return unlikely(kthread_should_stop() || ctx->cancel);
95 +get_buffer(struct unlzma_ctx *ctx)
97 + struct unlzma_buffer *bh;
99 + BUG_ON(ctx->n_buffers >= ctx->buffers_max);
100 + bh = &ctx->buffers[ctx->n_buffers++];
101 + bh->ptr = ctx->next_out;
102 + bh->offset = ctx->pos;
103 + bh->size = ctx->avail_out;
108 +unlzma_request_buffer(struct unlzma_ctx *ctx, int *avail)
111 + ctx->waiting = true;
112 + mutex_unlock(&ctx->mutex);
113 + wake_up(&ctx->req_done);
114 + if (wait_event_interruptible(ctx->next_req,
115 + unlzma_should_stop(ctx) || (*avail > 0)))
117 + mutex_lock(&ctx->mutex);
118 + } while (*avail <= 0 && !unlzma_should_stop(ctx));
120 + if (!unlzma_should_stop(ctx) && ctx->buf_full)
125 +rc_read(struct unlzma_ctx *ctx)
127 + if (unlikely(ctx->avail_in <= 0))
128 + unlzma_request_buffer(ctx, &ctx->avail_in);
130 + if (unlzma_should_stop(ctx))
134 + return *(ctx->next_in++);
139 +rc_get_code(struct unlzma_ctx *ctx)
141 + ctx->code = (ctx->code << 8) | rc_read(ctx);
145 +rc_normalize(struct unlzma_ctx *ctx)
147 + if (ctx->range < (1 << RC_TOP_BITS)) {
154 +rc_is_bit_0(struct unlzma_ctx *ctx, u16 *p)
157 + ctx->bound = *p * (ctx->range >> RC_MODEL_TOTAL_BITS);
158 + return ctx->code < ctx->bound;
162 +rc_update_bit_0(struct unlzma_ctx *ctx, u16 *p)
164 + ctx->range = ctx->bound;
165 + *p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
169 +rc_update_bit_1(struct unlzma_ctx *ctx, u16 *p)
171 + ctx->range -= ctx->bound;
172 + ctx->code -= ctx->bound;
173 + *p -= *p >> RC_MOVE_BITS;
177 +rc_get_bit(struct unlzma_ctx *ctx, u16 *p, int *symbol)
179 + if (rc_is_bit_0(ctx, p)) {
180 + rc_update_bit_0(ctx, p);
184 + rc_update_bit_1(ctx, p);
185 + *symbol = *symbol * 2 + 1;
191 +rc_direct_bit(struct unlzma_ctx *ctx)
195 + if (ctx->code >= ctx->range) {
196 + ctx->code -= ctx->range;
203 +rc_bit_tree_decode(struct unlzma_ctx *ctx, u16 *p, int num_levels, int *symbol)
205 + int i = num_levels;
209 + rc_get_bit(ctx, p + *symbol, symbol);
210 + *symbol -= 1 << num_levels;
214 +peek_old_byte(struct unlzma_ctx *ctx, u32 offs)
216 + struct unlzma_buffer *bh = &ctx->buffers[ctx->n_buffers - 1];
217 + int i = ctx->n_buffers;
220 + if (!ctx->n_buffers) {
221 + printk(KERN_ERR "unlzma/%s: no buffer\n", __func__);
225 + pos = ctx->pos - offs;
226 + if (unlikely(pos >= ctx->dict_size))
227 + pos = ~pos & (ctx->dict_size - 1);
229 + while (bh->offset > pos) {
233 + printk(KERN_ERR "unlzma/%s: position %d out of range\n", __func__, pos);
239 + if (pos >= bh->size) {
240 + printk(KERN_ERR "unlzma/%s: position %d out of range\n", __func__, pos);
244 + return bh->ptr[pos];
247 + ctx->cancel = true;
252 +write_byte(struct unlzma_ctx *ctx, u8 byte)
254 + if (unlikely(ctx->avail_out <= 0)) {
255 + unlzma_request_buffer(ctx, &ctx->avail_out);
258 + if (!ctx->avail_out)
261 + ctx->previous_byte = byte;
262 + *(ctx->next_out++) = byte;
264 + if (ctx->avail_out == 0)
271 +copy_byte(struct unlzma_ctx *ctx, u32 offs)
273 + write_byte(ctx, peek_old_byte(ctx, offs));
277 +copy_bytes(struct unlzma_ctx *ctx, u32 rep0, int len)
280 + copy_byte(ctx, rep0);
282 + if (unlzma_should_stop(ctx))
284 + } while (len != 0);
288 +process_bit0(struct unlzma_ctx *ctx, u16 *p, int pos_state, u16 *prob,
289 + int lc, u32 literal_pos_mask)
292 + rc_update_bit_0(ctx, prob);
293 + prob = (p + LZMA_LITERAL +
295 + * (((ctx->pos & literal_pos_mask) << lc)
296 + + (ctx->previous_byte >> (8 - lc))))
299 + if (ctx->state >= LZMA_NUM_LIT_STATES) {
300 + int match_byte = peek_old_byte(ctx, ctx->rep0);
306 + bit = match_byte & 0x100;
307 + prob_lit = prob + 0x100 + bit + mi;
308 + if (rc_get_bit(ctx, prob_lit, &mi) != !!bit)
310 + } while (mi < 0x100);
312 + while (mi < 0x100) {
313 + u16 *prob_lit = prob + mi;
314 + rc_get_bit(ctx, prob_lit, &mi);
316 + write_byte(ctx, mi);
317 + if (ctx->state < 4)
319 + else if (ctx->state < 10)
326 +process_bit1(struct unlzma_ctx *ctx, u16 *p, int pos_state, u16 *prob)
333 + rc_update_bit_1(ctx, prob);
334 + prob = p + LZMA_IS_REP + ctx->state;
335 + if (rc_is_bit_0(ctx, prob)) {
336 + rc_update_bit_0(ctx, prob);
337 + ctx->rep3 = ctx->rep2;
338 + ctx->rep2 = ctx->rep1;
339 + ctx->rep1 = ctx->rep0;
340 + ctx->state = ctx->state < LZMA_NUM_LIT_STATES ? 0 : 3;
341 + prob = p + LZMA_LEN_CODER;
343 + rc_update_bit_1(ctx, prob);
344 + prob = p + LZMA_IS_REP_G0 + ctx->state;
345 + if (rc_is_bit_0(ctx, prob)) {
346 + rc_update_bit_0(ctx, prob);
347 + prob = (p + LZMA_IS_REP_0_LONG
349 + LZMA_NUM_POS_BITS_MAX) +
351 + if (rc_is_bit_0(ctx, prob)) {
352 + rc_update_bit_0(ctx, prob);
354 + ctx->state = ctx->state < LZMA_NUM_LIT_STATES ?
356 + copy_byte(ctx, ctx->rep0);
359 + rc_update_bit_1(ctx, prob);
364 + rc_update_bit_1(ctx, prob);
365 + prob = p + LZMA_IS_REP_G1 + ctx->state;
366 + if (rc_is_bit_0(ctx, prob)) {
367 + rc_update_bit_0(ctx, prob);
368 + distance = ctx->rep1;
370 + rc_update_bit_1(ctx, prob);
371 + prob = p + LZMA_IS_REP_G2 + ctx->state;
372 + if (rc_is_bit_0(ctx, prob)) {
373 + rc_update_bit_0(ctx, prob);
374 + distance = ctx->rep2;
376 + rc_update_bit_1(ctx, prob);
377 + distance = ctx->rep3;
378 + ctx->rep3 = ctx->rep2;
380 + ctx->rep2 = ctx->rep1;
382 + ctx->rep1 = ctx->rep0;
383 + ctx->rep0 = distance;
385 + ctx->state = ctx->state < LZMA_NUM_LIT_STATES ? 8 : 11;
386 + prob = p + LZMA_REP_LEN_CODER;
389 + prob_len = prob + LZMA_LEN_CHOICE;
390 + if (rc_is_bit_0(ctx, prob_len)) {
391 + rc_update_bit_0(ctx, prob_len);
392 + prob_len = (prob + LZMA_LEN_LOW
394 + LZMA_LEN_NUM_LOW_BITS));
396 + num_bits = LZMA_LEN_NUM_LOW_BITS;
398 + rc_update_bit_1(ctx, prob_len);
399 + prob_len = prob + LZMA_LEN_CHOICE_2;
400 + if (rc_is_bit_0(ctx, prob_len)) {
401 + rc_update_bit_0(ctx, prob_len);
402 + prob_len = (prob + LZMA_LEN_MID
404 + LZMA_LEN_NUM_MID_BITS));
405 + offset = 1 << LZMA_LEN_NUM_LOW_BITS;
406 + num_bits = LZMA_LEN_NUM_MID_BITS;
408 + rc_update_bit_1(ctx, prob_len);
409 + prob_len = prob + LZMA_LEN_HIGH;
410 + offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
411 + + (1 << LZMA_LEN_NUM_MID_BITS));
412 + num_bits = LZMA_LEN_NUM_HIGH_BITS;
416 + rc_bit_tree_decode(ctx, prob_len, num_bits, &len);
419 + if (ctx->state < 4) {
422 + ctx->state += LZMA_NUM_LIT_STATES;
424 + p + LZMA_POS_SLOT +
426 + LZMA_NUM_LEN_TO_POS_STATES ? len :
427 + LZMA_NUM_LEN_TO_POS_STATES - 1)
428 + << LZMA_NUM_POS_SLOT_BITS);
429 + rc_bit_tree_decode(ctx, prob,
430 + LZMA_NUM_POS_SLOT_BITS,
432 + if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
434 + num_bits = (pos_slot >> 1) - 1;
435 + ctx->rep0 = 2 | (pos_slot & 1);
436 + if (pos_slot < LZMA_END_POS_MODEL_INDEX) {
437 + ctx->rep0 <<= num_bits;
438 + prob = p + LZMA_SPEC_POS +
439 + ctx->rep0 - pos_slot - 1;
441 + num_bits -= LZMA_NUM_ALIGN_BITS;
443 + ctx->rep0 = (ctx->rep0 << 1) |
444 + rc_direct_bit(ctx);
445 + prob = p + LZMA_ALIGN;
446 + ctx->rep0 <<= LZMA_NUM_ALIGN_BITS;
447 + num_bits = LZMA_NUM_ALIGN_BITS;
451 + while (num_bits--) {
452 + if (rc_get_bit(ctx, prob + mi, &mi))
457 + ctx->rep0 = pos_slot;
458 + if (++(ctx->rep0) == 0)
462 + len += LZMA_MATCH_MIN_LEN;
464 + copy_bytes(ctx, ctx->rep0, len);
469 +do_unlzma(struct unlzma_ctx *ctx)
471 + u8 hdr_buf[sizeof(struct lzma_header)];
472 + struct lzma_header *header = (struct lzma_header *)hdr_buf;
473 + u32 pos_state_mask;
474 + u32 literal_pos_mask;
480 + for (i = 0; i < sizeof(struct lzma_header); i++) {
481 + hdr_buf[i] = rc_read(ctx);
484 + ctx->n_buffers = 0;
487 + ctx->active = true;
489 + ctx->rep0 = ctx->rep1 = ctx->rep2 = ctx->rep3 = 1;
491 + ctx->previous_byte = 0;
493 + ctx->range = 0xFFFFFFFF;
495 + ctx->dict_size = le32_to_cpu(header->dict_size);
497 + if (header->pos >= (9 * 5 * 5))
512 + pos_state_mask = (1 << pb) - 1;
513 + literal_pos_mask = (1 << lp) - 1;
515 + if (ctx->dict_size == 0)
516 + ctx->dict_size = 1;
518 + num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
519 + if (ctx->workspace_size < num_probs * sizeof(*p)) {
520 + if (ctx->workspace)
521 + vfree(ctx->workspace);
522 + ctx->workspace_size = num_probs * sizeof(*p);
523 + ctx->workspace = vmalloc(ctx->workspace_size);
525 + p = (u16 *) ctx->workspace;
529 + num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp));
530 + for (i = 0; i < num_probs; i++)
531 + p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
533 + for (i = 0; i < 5; i++)
537 + int pos_state = ctx->pos & pos_state_mask;
538 + u16 *prob = p + LZMA_IS_MATCH +
539 + (ctx->state << LZMA_NUM_POS_BITS_MAX) + pos_state;
540 + if (rc_is_bit_0(ctx, prob))
541 + process_bit0(ctx, p, pos_state, prob,
542 + lc, literal_pos_mask);
544 + process_bit1(ctx, p, pos_state, prob);
545 + if (ctx->rep0 == 0)
548 + if (unlzma_should_stop(ctx))
551 + if (likely(!unlzma_should_stop(ctx)))
559 +unlzma_reset_buf(struct unlzma_ctx *ctx)
562 + ctx->next_in = NULL;
563 + ctx->avail_out = 0;
564 + ctx->next_out = NULL;
568 +unlzma_thread(void *data)
570 + struct unlzma_ctx *ctx = data;
572 + mutex_lock(&ctx->mutex);
574 + if (do_unlzma(ctx) < 0)
576 + unlzma_reset_buf(ctx);
577 + ctx->cancel = false;
578 + ctx->active = false;
579 + } while (!kthread_should_stop());
580 + mutex_unlock(&ctx->mutex);
586 +unlzma_init(struct crypto_tfm *tfm)
592 +unlzma_cancel(struct unlzma_ctx *ctx)
594 + unlzma_reset_buf(ctx);
599 + ctx->cancel = true;
601 + mutex_unlock(&ctx->mutex);
602 + wake_up(&ctx->next_req);
604 + mutex_lock(&ctx->mutex);
605 + } while (ctx->cancel);
610 +unlzma_exit(struct crypto_tfm *tfm)
612 + struct unlzma_ctx *ctx = crypto_tfm_ctx(tfm);
615 + unlzma_cancel(ctx);
616 + kthread_stop(ctx->thread);
617 + ctx->thread = NULL;
619 + kfree(ctx->buffers);
620 + ctx->buffers_max = 0;
621 + ctx->buffers = NULL;
626 +unlzma_decompress_setup(struct crypto_pcomp *tfm, void *p, unsigned int len)
628 + struct unlzma_ctx *ctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
629 + struct nlattr *tb[UNLZMA_DECOMP_MAX + 1];
638 + ret = nla_parse(tb, UNLZMA_DECOMP_MAX, p, len, NULL);
642 + if (!tb[UNLZMA_DECOMP_OUT_BUFFERS])
645 + if (ctx->buffers_max && (ctx->buffers_max <
646 + nla_get_u32(tb[UNLZMA_DECOMP_OUT_BUFFERS]))) {
647 + kfree(ctx->buffers);
648 + ctx->buffers_max = 0;
649 + ctx->buffers = NULL;
651 + if (!ctx->buffers) {
652 + ctx->buffers_max = nla_get_u32(tb[UNLZMA_DECOMP_OUT_BUFFERS]);
653 + ctx->buffers = kzalloc(sizeof(struct unlzma_buffer) * ctx->buffers_max, GFP_KERNEL);
658 + ctx->waiting = false;
659 + mutex_init(&ctx->mutex);
660 + init_waitqueue_head(&ctx->next_req);
661 + init_waitqueue_head(&ctx->req_done);
662 + ctx->thread = kthread_run(unlzma_thread, ctx, "unlzma/%d", instance++);
663 + if (IS_ERR(ctx->thread)) {
664 + ret = PTR_ERR(ctx->thread);
665 + ctx->thread = NULL;
672 +unlzma_decompress_init(struct crypto_pcomp *tfm)
678 +unlzma_wait_complete(struct unlzma_ctx *ctx, bool finish)
680 + DEFINE_WAIT(__wait);
683 + wake_up(&ctx->next_req);
684 + prepare_to_wait(&ctx->req_done, &__wait, TASK_INTERRUPTIBLE);
685 + mutex_unlock(&ctx->mutex);
687 + mutex_lock(&ctx->mutex);
688 + } while (!ctx->waiting && ctx->active);
689 + finish_wait(&ctx->req_done, &__wait);
693 +unlzma_decompress_update(struct crypto_pcomp *tfm, struct comp_request *req)
695 + struct unlzma_ctx *ctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
698 + mutex_lock(&ctx->mutex);
699 + if (!ctx->active && !req->avail_in)
703 + ctx->waiting = false;
704 + ctx->next_in = req->next_in;
705 + ctx->avail_in = req->avail_in;
706 + ctx->next_out = req->next_out;
707 + ctx->avail_out = req->avail_out;
709 + unlzma_wait_complete(ctx, false);
711 + req->next_in = ctx->next_in;
712 + req->avail_in = ctx->avail_in;
713 + req->next_out = ctx->next_out;
714 + req->avail_out = ctx->avail_out;
717 + pos = ctx->pos - pos;
720 + mutex_unlock(&ctx->mutex);
728 +unlzma_decompress_final(struct crypto_pcomp *tfm, struct comp_request *req)
730 + struct unlzma_ctx *ctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
733 + /* cancel pending operation */
734 + mutex_lock(&ctx->mutex);
737 + unlzma_cancel(ctx);
740 + mutex_unlock(&ctx->mutex);
745 +static struct pcomp_alg unlzma_alg = {
746 + .decompress_setup = unlzma_decompress_setup,
747 + .decompress_init = unlzma_decompress_init,
748 + .decompress_update = unlzma_decompress_update,
749 + .decompress_final = unlzma_decompress_final,
752 + .cra_name = "lzma",
753 + .cra_flags = CRYPTO_ALG_TYPE_PCOMPRESS,
754 + .cra_ctxsize = sizeof(struct unlzma_ctx),
755 + .cra_module = THIS_MODULE,
756 + .cra_init = unlzma_init,
757 + .cra_exit = unlzma_exit,
762 +unlzma_mod_init(void)
764 + return crypto_register_pcomp(&unlzma_alg);
768 +unlzma_mod_exit(void)
770 + crypto_unregister_pcomp(&unlzma_alg);
773 +module_init(unlzma_mod_init);
774 +module_exit(unlzma_mod_exit);
776 +MODULE_LICENSE("GPL");
777 +MODULE_DESCRIPTION("LZMA Decompression Algorithm");
778 +MODULE_AUTHOR("Felix Fietkau <nbd@openwrt.org>");
781 @@ -768,6 +768,12 @@ config CRYPTO_ZLIB
783 This is the zlib algorithm.
785 +config CRYPTO_UNLZMA
786 + tristate "LZMA decompression"
787 + select CRYPTO_PCOMP
789 + This is the lzma decompression module.
792 tristate "LZO compression algorithm"
794 --- a/crypto/Makefile
795 +++ b/crypto/Makefile
796 @@ -75,6 +75,7 @@ obj-$(CONFIG_CRYPTO_SEED) += seed.o
797 obj-$(CONFIG_CRYPTO_SALSA20) += salsa20_generic.o
798 obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o
799 obj-$(CONFIG_CRYPTO_ZLIB) += zlib.o
800 +obj-$(CONFIG_CRYPTO_UNLZMA) += unlzma.o
801 obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
802 obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o
803 obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o
805 +++ b/crypto/unlzma.h
807 +/* LZMA uncompresion module for pcomp
808 + * Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
811 + * Initial Linux kernel adaptation
812 + * Copyright (C) 2006 Alain < alain@knaff.lu >
814 + * Based on small lzma deflate implementation/Small range coder
815 + * implementation for lzma.
816 + * Copyright (C) 2006 Aurelien Jacobs < aurel@gnuage.org >
818 + * Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/)
819 + * Copyright (C) 1999-2005 Igor Pavlov
821 + * This program is free software; you can redistribute it and/or modify it
822 + * under the terms of the GNU General Public License version 2 as published
823 + * by the Free Software Foundation.
828 +struct lzma_header {
831 +} __attribute__ ((packed)) ;
834 +#define RC_TOP_BITS 24
835 +#define RC_MOVE_BITS 5
836 +#define RC_MODEL_TOTAL_BITS 11
838 +#define LZMA_BASE_SIZE 1846
839 +#define LZMA_LIT_SIZE 768
841 +#define LZMA_NUM_POS_BITS_MAX 4
843 +#define LZMA_LEN_NUM_LOW_BITS 3
844 +#define LZMA_LEN_NUM_MID_BITS 3
845 +#define LZMA_LEN_NUM_HIGH_BITS 8
847 +#define LZMA_LEN_CHOICE 0
848 +#define LZMA_LEN_CHOICE_2 (LZMA_LEN_CHOICE + 1)
849 +#define LZMA_LEN_LOW (LZMA_LEN_CHOICE_2 + 1)
850 +#define LZMA_LEN_MID (LZMA_LEN_LOW \
851 + + (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_LOW_BITS)))
852 +#define LZMA_LEN_HIGH (LZMA_LEN_MID \
853 + +(1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_MID_BITS)))
854 +#define LZMA_NUM_LEN_PROBS (LZMA_LEN_HIGH + (1 << LZMA_LEN_NUM_HIGH_BITS))
856 +#define LZMA_NUM_STATES 12
857 +#define LZMA_NUM_LIT_STATES 7
859 +#define LZMA_START_POS_MODEL_INDEX 4
860 +#define LZMA_END_POS_MODEL_INDEX 14
861 +#define LZMA_NUM_FULL_DISTANCES (1 << (LZMA_END_POS_MODEL_INDEX >> 1))
863 +#define LZMA_NUM_POS_SLOT_BITS 6
864 +#define LZMA_NUM_LEN_TO_POS_STATES 4
866 +#define LZMA_NUM_ALIGN_BITS 4
868 +#define LZMA_MATCH_MIN_LEN 2
870 +#define LZMA_IS_MATCH 0
871 +#define LZMA_IS_REP (LZMA_IS_MATCH + (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX))
872 +#define LZMA_IS_REP_G0 (LZMA_IS_REP + LZMA_NUM_STATES)
873 +#define LZMA_IS_REP_G1 (LZMA_IS_REP_G0 + LZMA_NUM_STATES)
874 +#define LZMA_IS_REP_G2 (LZMA_IS_REP_G1 + LZMA_NUM_STATES)
875 +#define LZMA_IS_REP_0_LONG (LZMA_IS_REP_G2 + LZMA_NUM_STATES)
876 +#define LZMA_POS_SLOT (LZMA_IS_REP_0_LONG \
877 + + (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX))
878 +#define LZMA_SPEC_POS (LZMA_POS_SLOT \
879 + +(LZMA_NUM_LEN_TO_POS_STATES << LZMA_NUM_POS_SLOT_BITS))
880 +#define LZMA_ALIGN (LZMA_SPEC_POS \
881 + + LZMA_NUM_FULL_DISTANCES - LZMA_END_POS_MODEL_INDEX)
882 +#define LZMA_LEN_CODER (LZMA_ALIGN + (1 << LZMA_NUM_ALIGN_BITS))
883 +#define LZMA_REP_LEN_CODER (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS)
884 +#define LZMA_LITERAL (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS)
887 --- a/include/crypto/compress.h
888 +++ b/include/crypto/compress.h
889 @@ -49,6 +49,12 @@ enum zlib_decomp_params {
891 #define ZLIB_DECOMP_MAX (__ZLIB_DECOMP_MAX - 1)
893 +enum unlzma_decomp_params {
894 + UNLZMA_DECOMP_OUT_BUFFERS = 1, /* naximum number of output buffers */
895 + __UNLZMA_DECOMP_MAX,
897 +#define UNLZMA_DECOMP_MAX (__UNLZMA_DECOMP_MAX - 1)
900 struct crypto_pcomp {
901 struct crypto_tfm base;