Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
f7708318
Commit
f7708318
authored
Jul 21, 2016
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cache-digest: Truncate hash from MSB
parent
24edc961
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
24 deletions
+22
-24
src/cache_digest.cc
src/cache_digest.cc
+22
-24
No files found.
src/cache_digest.cc
View file @
f7708318
...
...
@@ -32,6 +32,26 @@
namespace
nghttp2
{
namespace
{
// Truncates |md| to |nbits| bits counting from MSB. |nbits| is
// guaranteed to be less than or equal to 62.
uint64_t
truncate_hash
(
const
uint8_t
*
md
,
uint32_t
nbits
)
{
uint64_t
v
;
v
=
(
static_cast
<
uint64_t
>
(
md
[
0
])
<<
56
)
+
(
static_cast
<
uint64_t
>
(
md
[
1
])
<<
48
)
+
(
static_cast
<
uint64_t
>
(
md
[
2
])
<<
40
)
+
(
static_cast
<
uint64_t
>
(
md
[
3
])
<<
32
)
+
(
static_cast
<
uint64_t
>
(
md
[
4
])
<<
24
)
+
(
static_cast
<
uint64_t
>
(
md
[
5
])
<<
16
)
+
(
static_cast
<
uint64_t
>
(
md
[
6
])
<<
8
)
+
static_cast
<
uint64_t
>
(
md
[
31
]);
v
>>=
64
-
nbits
;
return
v
;
}
}
// namespace
namespace
{
int
compute_hash_values
(
std
::
vector
<
uint64_t
>
&
hash_values
,
const
std
::
vector
<
std
::
string
>
&
uris
,
uint32_t
nbits
)
{
...
...
@@ -41,8 +61,6 @@ int compute_hash_values(std::vector<uint64_t> &hash_values,
return
-
1
;
}
uint64_t
mask
=
(
static_cast
<
uint64_t
>
(
1
)
<<
nbits
)
-
1
;
auto
ctx
=
EVP_MD_CTX_create
();
hash_values
.
resize
(
uris
.
size
());
...
...
@@ -70,18 +88,7 @@ int compute_hash_values(std::vector<uint64_t> &hash_values,
assert
(
len
==
32
);
uint64_t
v
;
v
=
(
static_cast
<
uint64_t
>
(
md
[
24
])
<<
56
)
+
(
static_cast
<
uint64_t
>
(
md
[
25
])
<<
48
)
+
(
static_cast
<
uint64_t
>
(
md
[
26
])
<<
40
)
+
(
static_cast
<
uint64_t
>
(
md
[
27
])
<<
32
)
+
(
static_cast
<
uint64_t
>
(
md
[
28
])
<<
24
)
+
(
static_cast
<
uint64_t
>
(
md
[
29
])
<<
16
)
+
(
static_cast
<
uint64_t
>
(
md
[
30
])
<<
8
)
+
static_cast
<
uint64_t
>
(
md
[
31
]);
v
&=
mask
;
*
p
++
=
v
;
*
p
++
=
truncate_hash
(
md
.
data
(),
nbits
);
}
EVP_MD_CTX_destroy
(
ctx
);
...
...
@@ -219,7 +226,6 @@ ssize_t cache_digest_encode(uint8_t *data, size_t datalen,
int
cache_digest_hash
(
uint64_t
&
key
,
size_t
nbits
,
const
StringRef
&
s
)
{
int
rv
;
uint64_t
mask
=
(
static_cast
<
uint64_t
>
(
1
)
<<
nbits
)
-
1
;
std
::
array
<
uint8_t
,
32
>
md
;
...
...
@@ -246,15 +252,7 @@ int cache_digest_hash(uint64_t &key, size_t nbits, const StringRef &s) {
EVP_MD_CTX_destroy
(
ctx
);
key
=
(
static_cast
<
uint64_t
>
(
md
[
24
])
<<
56
)
+
(
static_cast
<
uint64_t
>
(
md
[
25
])
<<
48
)
+
(
static_cast
<
uint64_t
>
(
md
[
26
])
<<
40
)
+
(
static_cast
<
uint64_t
>
(
md
[
27
])
<<
32
)
+
(
static_cast
<
uint64_t
>
(
md
[
28
])
<<
24
)
+
(
static_cast
<
uint64_t
>
(
md
[
29
])
<<
16
)
+
(
static_cast
<
uint64_t
>
(
md
[
30
])
<<
8
)
+
static_cast
<
uint64_t
>
(
md
[
31
]);
key
&=
mask
;
key
=
truncate_hash
(
md
.
data
(),
nbits
);
return
0
;
}
...
...
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