hash: add xxhash64 algorithm (#6098)
This commit is contained in:
parent
1b18421d73
commit
ca2fd3b954
5 changed files with 97 additions and 1 deletions
|
|
@ -84,6 +84,7 @@ hash_plugins_list = [
|
|||
'xor8',
|
||||
'xor16',
|
||||
'xxhash32',
|
||||
'xxhash64',
|
||||
'ssdeep',
|
||||
'parity',
|
||||
'entropy',
|
||||
|
|
@ -132,6 +133,7 @@ rz_hash_sources = [
|
|||
'p/algo_xor8.c',
|
||||
'p/algo_xor16.c',
|
||||
'p/algo_xxhash32.c',
|
||||
'p/algo_xxhash64.c',
|
||||
'p/algo_ssdeep.c',
|
||||
'p/algo_parity.c',
|
||||
'p/algo_entropy.c',
|
||||
|
|
|
|||
88
librz/hash/p/algo_xxhash64.c
Normal file
88
librz/hash/p/algo_xxhash64.c
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
// SPDX-FileCopyrightText: 2026 cheese-cakee
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
|
||||
#include <rz_hash.h>
|
||||
#include <rz_util/rz_assert.h>
|
||||
#include <xxhash.h>
|
||||
|
||||
#define RZ_HASH_XXHASH64_DIGEST_SIZE 8
|
||||
#define RZ_HASH_XXHASH64_BLOCK_LENGTH 0
|
||||
|
||||
static void *plugin_xxhash64_context_new() {
|
||||
return XXH64_createState();
|
||||
}
|
||||
|
||||
static void plugin_xxhash64_context_free(void *context) {
|
||||
XXH64_freeState((XXH64_state_t *)context);
|
||||
}
|
||||
|
||||
static RzHashSize plugin_xxhash64_digest_size(void *context) {
|
||||
return RZ_HASH_XXHASH64_DIGEST_SIZE;
|
||||
}
|
||||
|
||||
static RzHashSize plugin_xxhash64_block_size(void *context) {
|
||||
return RZ_HASH_XXHASH64_BLOCK_LENGTH;
|
||||
}
|
||||
|
||||
static bool plugin_xxhash64_init(void *context) {
|
||||
rz_return_val_if_fail(context, false);
|
||||
|
||||
XXH64_reset((XXH64_state_t *)context, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool plugin_xxhash64_update(void *context, const ut8 *data, ut64 size) {
|
||||
rz_return_val_if_fail(context && data, false);
|
||||
|
||||
XXH64_update((XXH64_state_t *)context, data, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool plugin_xxhash64_final(void *context, ut8 *digest) {
|
||||
rz_return_val_if_fail(context && digest, false);
|
||||
|
||||
ut64 dgst = XXH64_digest((XXH64_state_t *)context);
|
||||
rz_write_be64(digest, dgst);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool plugin_xxhash64_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
|
||||
rz_return_val_if_fail(data && digest, false);
|
||||
ut8 *dgst = malloc(RZ_HASH_XXHASH64_DIGEST_SIZE);
|
||||
if (!dgst) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ut64 result = XXH64(data, size, 0);
|
||||
rz_write_be64(dgst, result);
|
||||
|
||||
*digest = dgst;
|
||||
if (digest_size) {
|
||||
*digest_size = RZ_HASH_XXHASH64_DIGEST_SIZE;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
RzHashPlugin rz_hash_plugin_xxhash64 = {
|
||||
.name = "xxhash64",
|
||||
.license = "LGPL3",
|
||||
.author = "cheese-cakee",
|
||||
.description = "xxHash64 non-cryptographic hash",
|
||||
.support_hmac = false,
|
||||
.context_new = plugin_xxhash64_context_new,
|
||||
.context_free = plugin_xxhash64_context_free,
|
||||
.digest_size = plugin_xxhash64_digest_size,
|
||||
.block_size = plugin_xxhash64_block_size,
|
||||
.init = plugin_xxhash64_init,
|
||||
.update = plugin_xxhash64_update,
|
||||
.final = plugin_xxhash64_final,
|
||||
.small_block = plugin_xxhash64_small_block,
|
||||
};
|
||||
|
||||
#ifndef RZ_PLUGIN_INCORE
|
||||
RZ_API RzLibStruct rizin_plugin = {
|
||||
.type = RZ_LIB_TYPE_HASH,
|
||||
.data = &rz_hash_plugin_xxhash64,
|
||||
.version = RZ_VERSION
|
||||
};
|
||||
#endif
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -298,6 +298,7 @@ ____h_ temperature LGPL3 Seva Binary temperatu
|
|||
____h_ xor16 LGPL3 deroad XOR-16 checksum
|
||||
____h_ xor8 LGPL3 deroad XOR-8 checksum
|
||||
____h_ xxhash32 LGPL3 deroad xxHash32 non-cryptographic hash
|
||||
____h_ xxhash64 LGPL3 cheese-cakee xxHash64 non-cryptographic hash
|
||||
_D____ ror LGPL-3 pancake Rotate Right symmetric-key block cipher
|
||||
__ed__ base85 LGPL-3 Ahmed Ibrahim Base85 encoder/decoder
|
||||
E_____ rol LGPL-3 pancake Rotate Left symmetric-key block cipher
|
||||
|
|
@ -774,6 +775,7 @@ string: 0x00000000-0x00000005 temperature: computed hash doesn't match the expec
|
|||
string: 0x00000000-0x00000005 xor16: computed hash doesn't match the expected one
|
||||
string: 0x00000000-0x00000005 xor8: computed hash doesn't match the expected one
|
||||
string: 0x00000000-0x00000005 xxhash32: computed hash doesn't match the expected one
|
||||
string: 0x00000000-0x00000005 xxhash64: computed hash doesn't match the expected one
|
||||
EOF
|
||||
RUN
|
||||
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@ static hash_data_t hashes_to_test[] = {
|
|||
{ INDATA("password"), .algo = "xor8", .expected = "1f" },
|
||||
{ INDATA("password"), .algo = "xor16", .expected = "740f" },
|
||||
{ INDATA("password"), .algo = "xxhash32", .expected = "ed6c6c10" },
|
||||
{ INDATA("password"), .algo = "xxhash64", .expected = "90007daf3980ef1f" },
|
||||
{ INDATA("password"), .algo = "parity", .expected = "01" },
|
||||
{ INDATA("password"), .algo = "entropy", .expected = "2.75000000" },
|
||||
{ INDATA("password"), .algo = "entropy_fract", .expected = "0.91666667" },
|
||||
|
|
|
|||
Loading…
Reference in a new issue