aboutsummaryrefslogtreecommitdiffstats
path: root/linux/lib/xz
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2014-03-04 23:23:55 +0000
committerXin LI <delphij@FreeBSD.org>2014-03-04 23:23:55 +0000
commit442b7425c6da3ee6e0a16d65b5458a795dcc47d1 (patch)
tree3349fe96bd5cf94db21a768ba361dc35fefbf7d6 /linux/lib/xz
parent38f44a8c7c3367df45180852ee34d7d0a81b4ed7 (diff)
downloadsrc-vendor/xz-embedded.tar.gz
src-vendor/xz-embedded.zip
This is from commit hash '6a8a2364434763a033781f6b2a605ace9a021013'.
Notes
Notes: svn path=/vendor/xz-embedded/dist/; revision=262756 svn path=/vendor/xz-embedded/6a8a2364434763a033781f6b2a605ace9a021013/; revision=262757; tag=vendor/xz-embedded/6a8a2364434763a033781f6b2a605ace9a021013
Diffstat (limited to 'linux/lib/xz')
-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
3 files changed, 113 insertions, 39 deletions
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;