1139815Simp/**
275332Sbp * \file        lzma/index_hash.h
375332Sbp * \brief       Validate Index by using a hash function
475332Sbp *
575332Sbp * Hashing makes it possible to use constant amount of memory to validate
675332Sbp * Index of arbitrary size.
775332Sbp */
875332Sbp
975332Sbp/*
1075332Sbp * Author: Lasse Collin
1175332Sbp *
1275332Sbp * This file has been put into the public domain.
1375332Sbp * You can do whatever you want with this file.
1475332Sbp *
1575332Sbp * See ../lzma.h for information about liblzma as a whole.
1675332Sbp */
1775332Sbp
1875332Sbp#ifndef LZMA_H_INTERNAL
1975332Sbp#	error Never include this file directly. Use <lzma.h> instead.
2075332Sbp#endif
2175332Sbp
2275332Sbp/**
2375332Sbp * \brief       Opaque data type to hold the Index hash
2475332Sbp */
2575332Sbptypedef struct lzma_index_hash_s lzma_index_hash;
2675332Sbp
2775332Sbp
2875332Sbp/**
2975332Sbp * \brief       Allocate and initialize a new lzma_index_hash structure
3075332Sbp *
3175332Sbp * If index_hash is NULL, a new lzma_index_hash structure is allocated,
3275332Sbp * initialized, and a pointer to it returned. If allocation fails, NULL
3375332Sbp * is returned.
3475332Sbp *
3575332Sbp * If index_hash is non-NULL, it is reinitialized and the same pointer
3675332Sbp * returned. In this case, return value cannot be NULL or a different
3775332Sbp * pointer than the index_hash that was given as an argument.
3875332Sbp */
3975332Sbpextern LZMA_API(lzma_index_hash *) lzma_index_hash_init(
4075332Sbp		lzma_index_hash *index_hash, lzma_allocator *allocator)
4175332Sbp		lzma_nothrow lzma_attr_warn_unused_result;
4275332Sbp
4375332Sbp
4475332Sbp/**
4575332Sbp * \brief       Deallocate lzma_index_hash structure
4675332Sbp */
4775332Sbpextern LZMA_API(void) lzma_index_hash_end(
4875332Sbp		lzma_index_hash *index_hash, lzma_allocator *allocator)
4975332Sbp		lzma_nothrow;
5075332Sbp
5175332Sbp
5275332Sbp/**
5375332Sbp * \brief       Add a new Record to an Index hash
5475332Sbp *
5575332Sbp * \param       index             Pointer to a lzma_index_hash structure
56120492Sfjoe * \param       unpadded_size     Unpadded Size of a Block
57120492Sfjoe * \param       uncompressed_size Uncompressed Size of a Block
5875332Sbp *
5975332Sbp * \return      - LZMA_OK
6075332Sbp *              - LZMA_DATA_ERROR: Compressed or uncompressed size of the
6175332Sbp *                Stream or size of the Index field would grow too big.
6275332Sbp *              - LZMA_PROG_ERROR: Invalid arguments or this function is being
6375332Sbp *                used when lzma_index_hash_decode() has already been used.
64194665Sdelphij */
6575332Sbpextern LZMA_API(lzma_ret) lzma_index_hash_append(lzma_index_hash *index_hash,
6675332Sbp		lzma_vli unpadded_size, lzma_vli uncompressed_size)
6775332Sbp		lzma_nothrow lzma_attr_warn_unused_result;
6875332Sbp
6975332Sbp
7075332Sbp/**
71194638Sdelphij * \brief       Decode and validate the Index field
72194638Sdelphij *
73194638Sdelphij * After telling the sizes of all Blocks with lzma_index_hash_append(),
74194638Sdelphij * the actual Index field is decoded with this function. Specifically,
75194638Sdelphij * once decoding of the Index field has been started, no more Records
76194638Sdelphij * can be added using lzma_index_hash_append().
77194638Sdelphij *
78194638Sdelphij * This function doesn't use lzma_stream structure to pass the input data.
79194638Sdelphij * Instead, the input buffer is specified using three arguments. This is
80194638Sdelphij * because it matches better the internal APIs of liblzma.
81 *
82 * \param       index_hash      Pointer to a lzma_index_hash structure
83 * \param       in              Pointer to the beginning of the input buffer
84 * \param       in_pos          in[*in_pos] is the next byte to process
85 * \param       in_size         in[in_size] is the first byte not to process
86 *
87 * \return      - LZMA_OK: So far good, but more input is needed.
88 *              - LZMA_STREAM_END: Index decoded successfully and it matches
89 *                the Records given with lzma_index_hash_append().
90 *              - LZMA_DATA_ERROR: Index is corrupt or doesn't match the
91 *                information given with lzma_index_hash_append().
92 *              - LZMA_BUF_ERROR: Cannot progress because *in_pos >= in_size.
93 *              - LZMA_PROG_ERROR
94 */
95extern LZMA_API(lzma_ret) lzma_index_hash_decode(lzma_index_hash *index_hash,
96		const uint8_t *in, size_t *in_pos, size_t in_size)
97		lzma_nothrow lzma_attr_warn_unused_result;
98
99
100/**
101 * \brief       Get the size of the Index field as bytes
102 *
103 * This is needed to verify the Backward Size field in the Stream Footer.
104 */
105extern LZMA_API(lzma_vli) lzma_index_hash_size(
106		const lzma_index_hash *index_hash)
107		lzma_nothrow lzma_attr_pure;
108