示例#1
0
/*******************************************************************************
 * Description:
 *   This function is to get total number of real entries that an entry given by
 *   <key> is compressed from.
 * Parameters:
 *   entropy - The entropy of the IPTD table.
 *   bits    - The bit size of the IPTD table
 *   key     - The key of the entry.
 * Return:
 *   The number of real entries the entry is compressed from.
 ******************************************************************************/
int _rundelta_get_entry_count(uint32_t entropy, int bits, int key)
{
	int count, code, block_size, bindex, eindex;

	if (entropy == 0)
		return 1;

	block_size = 1 << (bits - 4);
	count = 0;
	bindex = key >> (bits - 4);
	eindex = key & (block_size - 1);
	while (bindex < RUNDELTA_BLOCK_NUM) {
		code = entropy_get(entropy, 30 - (bindex) * 2);
		if (code == ENTROPY_NONE || code == ENTROPY_SINGLE) {
			bindex++;
			eindex = 0;
			count += block_size;
			if (code == ENTROPY_SINGLE)
				break;

		} else if (code == ENTROPY_HALF) {
			if (eindex == 0)
				count += block_size / 2 + 1;
			else
				count++;
			if (++eindex == block_size / 2) {
				eindex = 0;
				bindex++;
			}
			break;
		} else {
			/* ENTROPY_FULL */
			count++;
			if (++eindex == block_size) {
				eindex = 0;
				bindex++;
			}
			break;
		}
	}
	return count;
}
示例#2
0
uint32_t salt_generate() {
    uint32_t salt;
    entropy_get(&salt, sizeof(salt));
    return salt;
}