Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
slash
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
slash
Commits
3f236b4b
Unverified
Commit
3f236b4b
authored
Oct 02, 2023
by
Nils Goroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor hash function implementation in preparation of tabularization
parent
86ef2a16
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
14 deletions
+29
-14
fellow_hash.c
src/fellow_hash.c
+29
-14
No files found.
src/fellow_hash.c
View file @
3f236b4b
...
@@ -77,26 +77,32 @@ fh_assert_lengths(void)
...
@@ -77,26 +77,32 @@ fh_assert_lengths(void)
#endif
#endif
}
}
#define FH_H_SHA256(d, p, l) sha256(d, p, l)
#define FH_H_XXH32(d, p, l) do { (d) = XXH32(p, l, 0); } while(0)
#define FH_H_XXH3_64(d, p, l) do { (d) = XXH3_64bits(p, l); } while(0)
#define FH_H_XXH3_128(d, p, l) do { \
XXH128_hash_t h = XXH3_128bits(p, l); \
memcpy(d, &h, sizeof d); \
} while (0);
void
void
fh
(
uint8_t
fht
,
union
fh
*
fhh
,
const
void
*
p
,
size_t
l
)
fh
(
uint8_t
fht
,
union
fh
*
fhh
,
const
void
*
p
,
size_t
l
)
{
{
//lint --e{779,506} == NULL comparison with constant
//lint --e{779,506} == NULL comparison with constant
switch
(
fht
)
{
switch
(
fht
)
{
case
FH_SHA256
:
case
FH_SHA256
:
sha
256
(
fhh
->
sha256
,
p
,
l
);
FH_H_SHA
256
(
fhh
->
sha256
,
p
,
l
);
break
;
break
;
#ifdef HAVE_XXHASH_H
#ifdef HAVE_XXHASH_H
case
FH_XXH32
:
case
FH_XXH32
:
fhh
->
xxh32
=
XXH32
(
p
,
l
,
0
);
FH_H_XXH32
(
fhh
->
xxh32
,
p
,
l
);
break
;
break
;
case
FH_XXH3_64
:
case
FH_XXH3_64
:
fhh
->
xxh64
=
XXH3_64bits
(
p
,
l
);
FH_H_XXH3_64
(
fhh
->
xxh64
,
p
,
l
);
break
;
break
;
case
FH_XXH3_128
:
{
case
FH_XXH3_128
:
XXH128_hash_t
h
=
XXH3_128bits
(
p
,
l
);
FH_H_XXH3_128
(
fhh
->
xxh128
,
p
,
l
);
memcpy
(
fhh
->
xxh128
,
&
h
,
sizeof
fhh
->
xxh128
);
break
;
break
;
}
#else
#else
case
FH_XXH32
:
case
FH_XXH32
:
case
FH_XXH3_64
:
case
FH_XXH3_64
:
...
@@ -108,23 +114,32 @@ fh(uint8_t fht, union fh *fhh, const void *p, size_t l)
...
@@ -108,23 +114,32 @@ fh(uint8_t fht, union fh *fhh, const void *p, size_t l)
}
}
}
}
static
inline
int
xxh3_128_cmp
(
const
uint8_t
v
[
16
],
const
void
*
p
,
size_t
l
)
{
XXH128_hash_t
h
=
XXH3_128bits
(
p
,
l
);
return
(
memcmp
(
v
,
&
h
,
sizeof
h
));
}
#define FH_C_SHA256(v, p, l) sha256cmp(v, p, l)
#define FH_C_XXH32(v, p, l) ((v) != XXH32(p, l, 0))
#define FH_C_XXH3_64(v, p, l) ((v) != XXH3_64bits(p, l))
#define FH_C_XXH3_128(v, p, l) xxh3_128_cmp(v, p, l)
int
int
fhcmp
(
uint8_t
fht
,
const
union
fh
*
fhh
,
const
void
*
p
,
size_t
l
)
fhcmp
(
uint8_t
fht
,
const
union
fh
*
fhh
,
const
void
*
p
,
size_t
l
)
{
{
//lint --e{779,506} == NULL comparison with constant
//lint --e{779,506} == NULL comparison with constant
switch
(
fht
)
{
switch
(
fht
)
{
case
FH_SHA256
:
case
FH_SHA256
:
return
(
sha256cmp
(
fhh
->
sha256
,
p
,
l
));
return
(
FH_C_SHA256
(
fhh
->
sha256
,
p
,
l
));
#ifdef HAVE_XXHASH_H
#ifdef HAVE_XXHASH_H
case
FH_XXH32
:
case
FH_XXH32
:
return
(
fhh
->
xxh32
!=
XXH32
(
p
,
l
,
0
));
return
(
FH_C_XXH32
(
fhh
->
xxh32
,
p
,
l
));
case
FH_XXH3_64
:
case
FH_XXH3_64
:
return
(
fhh
->
xxh64
!=
XXH3_64bits
(
p
,
l
));
return
(
FH_C_XXH3_64
(
fhh
->
xxh64
,
p
,
l
));
case
FH_XXH3_128
:
case
FH_XXH3_128
:
{
return
(
FH_C_XXH3_128
(
fhh
->
xxh128
,
p
,
l
));
XXH128_hash_t
h
=
XXH3_128bits
(
p
,
l
);
return
(
memcmp
(
fhh
->
xxh128
,
&
h
,
sizeof
fhh
->
xxh128
));
}
#else
#else
case
FH_XXH32
:
case
FH_XXH32
:
case
FH_XXH3_64
:
case
FH_XXH3_64
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment