aboutsummaryrefslogtreecommitdiffstats
path: root/linux
diff options
context:
space:
mode:
Diffstat (limited to 'linux')
-rw-r--r--linux/include/linux/xz.h31
-rw-r--r--linux/lib/decompress_unxz.c2
-rw-r--r--linux/lib/xz/Kconfig34
-rw-r--r--linux/lib/xz/xz_crc64.c50
-rw-r--r--linux/lib/xz/xz_dec_stream.c68
-rwxr-xr-xlinux/scripts/xz_wrap.sh4
6 files changed, 147 insertions, 42 deletions
diff --git a/linux/include/linux/xz.h b/linux/include/linux/xz.h
index 810cb10a6357..0a4b38d33c2c 100644
--- a/linux/include/linux/xz.h
+++ b/linux/include/linux/xz.h
@@ -251,6 +251,22 @@ XZ_EXTERN void xz_dec_end(struct xz_dec *s);
# endif
#endif
+/*
+ * If CRC64 support has been enabled with XZ_USE_CRC64, a CRC64
+ * implementation is needed too.
+ */
+#ifndef XZ_USE_CRC64
+# undef XZ_INTERNAL_CRC64
+# define XZ_INTERNAL_CRC64 0
+#endif
+#ifndef XZ_INTERNAL_CRC64
+# ifdef __KERNEL__
+# error Using CRC64 in the kernel has not been implemented.
+# else
+# define XZ_INTERNAL_CRC64 1
+# endif
+#endif
+
#if XZ_INTERNAL_CRC32
/*
* This must be called before any other xz_* function to initialize
@@ -266,6 +282,21 @@ XZ_EXTERN void xz_crc32_init(void);
XZ_EXTERN uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc);
#endif
+#if XZ_INTERNAL_CRC64
+/*
+ * This must be called before any other xz_* function (except xz_crc32_init())
+ * to initialize the CRC64 lookup table.
+ */
+XZ_EXTERN void xz_crc64_init(void);
+
+/*
+ * Update CRC64 value using the polynomial from ECMA-182. To start a new
+ * calculation, the third argument must be zero. To continue the calculation,
+ * the previously returned value is passed as the third argument.
+ */
+XZ_EXTERN uint64_t xz_crc64(const uint8_t *buf, size_t size, uint64_t crc);
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/linux/lib/decompress_unxz.c b/linux/lib/decompress_unxz.c
index cecd23df2b9a..9f34eb56854d 100644
--- a/linux/lib/decompress_unxz.c
+++ b/linux/lib/decompress_unxz.c
@@ -83,7 +83,7 @@
* safety_margin = 128 + uncompressed_size * 8 / 32768 + 65536
* = 128 + (uncompressed_size >> 12) + 65536
*
- * For comparision, according to arch/x86/boot/compressed/misc.c, the
+ * For comparison, according to arch/x86/boot/compressed/misc.c, the
* equivalent formula for Deflate is this:
*
* safety_margin = 18 + (uncompressed_size >> 12) + 32768
diff --git a/linux/lib/xz/Kconfig b/linux/lib/xz/Kconfig
index 60a6088d0e5e..08837db52d94 100644
--- a/linux/lib/xz/Kconfig
+++ b/linux/lib/xz/Kconfig
@@ -6,42 +6,40 @@ config XZ_DEC
the .xz file format as the container. For integrity checking,
CRC32 is supported. See Documentation/xz.txt for more information.
+if XZ_DEC
+
config XZ_DEC_X86
- bool "x86 BCJ filter decoder" if EXPERT
- default y
- depends on XZ_DEC
+ bool "x86 BCJ filter decoder"
+ default y if X86
select XZ_DEC_BCJ
config XZ_DEC_POWERPC
- bool "PowerPC BCJ filter decoder" if EXPERT
- default y
- depends on XZ_DEC
+ bool "PowerPC BCJ filter decoder"
+ default y if PPC
select XZ_DEC_BCJ
config XZ_DEC_IA64
- bool "IA-64 BCJ filter decoder" if EXPERT
- default y
- depends on XZ_DEC
+ bool "IA-64 BCJ filter decoder"
+ default y if IA64
select XZ_DEC_BCJ
config XZ_DEC_ARM
- bool "ARM BCJ filter decoder" if EXPERT
- default y
- depends on XZ_DEC
+ bool "ARM BCJ filter decoder"
+ default y if ARM
select XZ_DEC_BCJ
config XZ_DEC_ARMTHUMB
- bool "ARM-Thumb BCJ filter decoder" if EXPERT
- default y
- depends on XZ_DEC
+ bool "ARM-Thumb BCJ filter decoder"
+ default y if (ARM && ARM_THUMB)
select XZ_DEC_BCJ
config XZ_DEC_SPARC
- bool "SPARC BCJ filter decoder" if EXPERT
- default y
- depends on XZ_DEC
+ bool "SPARC BCJ filter decoder"
+ default y if SPARC
select XZ_DEC_BCJ
+endif
+
config XZ_DEC_BCJ
bool
default n
diff --git a/linux/lib/xz/xz_crc64.c b/linux/lib/xz/xz_crc64.c
new file mode 100644
index 000000000000..ca1caee899ae
--- /dev/null
+++ b/linux/lib/xz/xz_crc64.c
@@ -0,0 +1,50 @@
+/*
+ * CRC64 using the polynomial from ECMA-182
+ *
+ * This file is similar to xz_crc32.c. See the comments there.
+ *
+ * Authors: Lasse Collin <lasse.collin@tukaani.org>
+ * Igor Pavlov <http://7-zip.org/>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#include "xz_private.h"
+
+#ifndef STATIC_RW_DATA
+# define STATIC_RW_DATA static
+#endif
+
+STATIC_RW_DATA uint64_t xz_crc64_table[256];
+
+XZ_EXTERN void xz_crc64_init(void)
+{
+ const uint64_t poly = 0xC96C5795D7870F42;
+
+ uint32_t i;
+ uint32_t j;
+ uint64_t r;
+
+ for (i = 0; i < 256; ++i) {
+ r = i;
+ for (j = 0; j < 8; ++j)
+ r = (r >> 1) ^ (poly & ~((r & 1) - 1));
+
+ xz_crc64_table[i] = r;
+ }
+
+ return;
+}
+
+XZ_EXTERN uint64_t xz_crc64(const uint8_t *buf, size_t size, uint64_t crc)
+{
+ crc = ~crc;
+
+ while (size != 0) {
+ crc = xz_crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
+ --size;
+ }
+
+ return ~crc;
+}
diff --git a/linux/lib/xz/xz_dec_stream.c b/linux/lib/xz/xz_dec_stream.c
index ac809b1e64f7..d6525506a1ed 100644
--- a/linux/lib/xz/xz_dec_stream.c
+++ b/linux/lib/xz/xz_dec_stream.c
@@ -10,6 +10,12 @@
#include "xz_private.h"
#include "xz_stream.h"
+#ifdef XZ_USE_CRC64
+# define IS_CRC64(check_type) ((check_type) == XZ_CHECK_CRC64)
+#else
+# define IS_CRC64(check_type) false
+#endif
+
/* Hash used to validate the Index field */
struct xz_dec_hash {
vli_type unpadded;
@@ -42,8 +48,13 @@ struct xz_dec {
size_t in_start;
size_t out_start;
+#ifdef XZ_USE_CRC64
+ /* CRC32 or CRC64 value in Block or CRC32 value in Index */
+ uint64_t crc;
+#else
/* CRC32 value in Block or Index */
- uint32_t crc32;
+ uint32_t crc;
+#endif
/* Type of the integrity check calculated from uncompressed data */
enum xz_check check_type;
@@ -208,8 +219,8 @@ static enum xz_ret dec_vli(struct xz_dec *s, const uint8_t *in,
* the observed compressed and uncompressed sizes of the Block so that
* they don't exceed the values possibly stored in the Block Header
* (validation assumes that no integer overflow occurs, since vli_type
- * is normally uint64_t). Update the CRC32 if presence of the CRC32
- * field was indicated in Stream Header.
+ * is normally uint64_t). Update the CRC32 or CRC64 value if presence of
+ * the CRC32 or CRC64 field was indicated in Stream Header.
*
* Once the decoding is finished, validate that the observed sizes match
* the sizes possibly stored in the Block Header. Update the hash and
@@ -242,8 +253,13 @@ static enum xz_ret dec_block(struct xz_dec *s, struct xz_buf *b)
return XZ_DATA_ERROR;
if (s->check_type == XZ_CHECK_CRC32)
- s->crc32 = xz_crc32(b->out + s->out_start,
- b->out_pos - s->out_start, s->crc32);
+ s->crc = xz_crc32(b->out + s->out_start,
+ b->out_pos - s->out_start, s->crc);
+#ifdef XZ_USE_CRC64
+ else if (s->check_type == XZ_CHECK_CRC64)
+ s->crc = xz_crc64(b->out + s->out_start,
+ b->out_pos - s->out_start, s->crc);
+#endif
if (ret == XZ_STREAM_END) {
if (s->block_header.compressed != VLI_UNKNOWN
@@ -264,6 +280,8 @@ static enum xz_ret dec_block(struct xz_dec *s, struct xz_buf *b)
#else
if (s->check_type == XZ_CHECK_CRC32)
s->block.hash.unpadded += 4;
+ else if (IS_CRC64(s->check_type))
+ s->block.hash.unpadded += 8;
#endif
s->block.hash.uncompressed += s->block.uncompressed;
@@ -282,7 +300,7 @@ static void index_update(struct xz_dec *s, const struct xz_buf *b)
{
size_t in_used = b->in_pos - s->in_start;
s->index.size += in_used;
- s->crc32 = xz_crc32(b->in + s->in_start, in_used, s->crc32);
+ s->crc = xz_crc32(b->in + s->in_start, in_used, s->crc);
}
/*
@@ -340,23 +358,25 @@ static enum xz_ret dec_index(struct xz_dec *s, struct xz_buf *b)
}
/*
- * Validate that the next four input bytes match the value of s->crc32.
- * s->pos must be zero when starting to validate the first byte.
+ * Validate that the next four or eight input bytes match the value
+ * of s->crc. s->pos must be zero when starting to validate the first byte.
+ * The "bits" argument allows using the same code for both CRC32 and CRC64.
*/
-static enum xz_ret crc32_validate(struct xz_dec *s, struct xz_buf *b)
+static enum xz_ret crc_validate(struct xz_dec *s, struct xz_buf *b,
+ uint32_t bits)
{
do {
if (b->in_pos == b->in_size)
return XZ_OK;
- if (((s->crc32 >> s->pos) & 0xFF) != b->in[b->in_pos++])
+ if (((s->crc >> s->pos) & 0xFF) != b->in[b->in_pos++])
return XZ_DATA_ERROR;
s->pos += 8;
- } while (s->pos < 32);
+ } while (s->pos < bits);
- s->crc32 = 0;
+ s->crc = 0;
s->pos = 0;
return XZ_STREAM_END;
@@ -397,10 +417,11 @@ static enum xz_ret dec_stream_header(struct xz_dec *s)
return XZ_OPTIONS_ERROR;
/*
- * Of integrity checks, we support only none (Check ID = 0) and
- * CRC32 (Check ID = 1). However, if XZ_DEC_ANY_CHECK is defined,
- * we will accept other check types too, but then the check won't
- * be verified and a warning (XZ_UNSUPPORTED_CHECK) will be given.
+ * Of integrity checks, we support none (Check ID = 0),
+ * CRC32 (Check ID = 1), and optionally CRC64 (Check ID = 4).
+ * However, if XZ_DEC_ANY_CHECK is defined, we will accept other
+ * check types too, but then the check won't be verified and
+ * a warning (XZ_UNSUPPORTED_CHECK) will be given.
*/
s->check_type = s->temp.buf[HEADER_MAGIC_SIZE + 1];
@@ -408,10 +429,10 @@ static enum xz_ret dec_stream_header(struct xz_dec *s)
if (s->check_type > XZ_CHECK_MAX)
return XZ_OPTIONS_ERROR;
- if (s->check_type > XZ_CHECK_CRC32)
+ if (s->check_type > XZ_CHECK_CRC32 && !IS_CRC64(s->check_type))
return XZ_UNSUPPORTED_CHECK;
#else
- if (s->check_type > XZ_CHECK_CRC32)
+ if (s->check_type > XZ_CHECK_CRC32 && !IS_CRC64(s->check_type))
return XZ_OPTIONS_ERROR;
#endif
@@ -645,7 +666,12 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b)
case SEQ_BLOCK_CHECK:
if (s->check_type == XZ_CHECK_CRC32) {
- ret = crc32_validate(s, b);
+ ret = crc_validate(s, b, 32);
+ if (ret != XZ_STREAM_END)
+ return ret;
+ }
+ else if (IS_CRC64(s->check_type)) {
+ ret = crc_validate(s, b, 64);
if (ret != XZ_STREAM_END)
return ret;
}
@@ -688,7 +714,7 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b)
s->sequence = SEQ_INDEX_CRC32;
case SEQ_INDEX_CRC32:
- ret = crc32_validate(s, b);
+ ret = crc_validate(s, b, 32);
if (ret != XZ_STREAM_END)
return ret;
@@ -802,7 +828,7 @@ XZ_EXTERN void xz_dec_reset(struct xz_dec *s)
s->sequence = SEQ_STREAM_HEADER;
s->allow_buf_error = false;
s->pos = 0;
- s->crc32 = 0;
+ s->crc = 0;
memzero(&s->block, sizeof(s->block));
memzero(&s->index, sizeof(s->index));
s->temp.pos = 0;
diff --git a/linux/scripts/xz_wrap.sh b/linux/scripts/xz_wrap.sh
index 17a5798c29da..7a2d372f4885 100755
--- a/linux/scripts/xz_wrap.sh
+++ b/linux/scripts/xz_wrap.sh
@@ -12,8 +12,8 @@
BCJ=
LZMA2OPTS=
-case $ARCH in
- x86|x86_64) BCJ=--x86 ;;
+case $SRCARCH in
+ x86) BCJ=--x86 ;;
powerpc) BCJ=--powerpc ;;
ia64) BCJ=--ia64; LZMA2OPTS=pb=4 ;;
arm) BCJ=--arm ;;