Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Auditbeat] Add XXH64 File Integrity Checks (#6626) #7311

Merged
merged 3 commits into from
Jun 15, 2018

Conversation

original-brownbear
Copy link
Member

@original-brownbear original-brownbear commented Jun 13, 2018

Adds XXH64 for #6626 (as instructed by #6626 (comment))

Definitely significantly faster than the other algorithms:

Output of BenchmarkHashFile (last one is xxh64)

10	 125849628 ns/op
10	 126909498 ns/op
10	 125919115 ns/op
10	 169575025 ns/op
10	 124420788 ns/op
5	 287273152 ns/op
5	 285969777 ns/op
10	 201358551 ns/op
10	 200579664 ns/op
5	 200776030 ns/op
10	 199927813 ns/op
5	 323143744 ns/op
3	 340378308 ns/op
3	 447976686 ns/op
2	 623592783 ns/op
50	  29904225 ns/op

func HashAddXx64(builder *flatbuffers.Builder, xx64 flatbuffers.UOffsetT) {
builder.PrependUOffsetTSlot(15, flatbuffers.UOffsetT(xx64), 0)
}
func HashStartXx64Vector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported function HashStartXx64Vector should have comment or be unexported

@@ -374,6 +391,12 @@ func HashAddBlake2b512(builder *flatbuffers.Builder, blake2b512 flatbuffers.UOff
func HashStartBlake2b512Vector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT {
return builder.StartVector(1, numElems, 1)
}
func HashAddXx64(builder *flatbuffers.Builder, xx64 flatbuffers.UOffsetT) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported function HashAddXx64 should have comment or be unexported

return 0
}

func (rcv *Hash) Xx64Length() int {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported method Hash.Xx64Length should have comment or be unexported

@@ -281,8 +281,25 @@ func (rcv *Hash) Blake2b512Length() int {
return 0
}

func (rcv *Hash) Xx64(j int) int8 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported method Hash.Xx64 should have comment or be unexported

Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add an entry to the CHANGELOG.asciidoc file, please.

Overall looks good. Just a few redlines. Thanks for adding it.

@@ -172,6 +172,7 @@ func TestHashFile(t *testing.T) {
SHA3_256: mustDecodeHex("3cb5385a2987ca45888d7877fbcf92b4854f7155ae19c96cecc7ea1300c6f5a4"),
SHA3_384: mustDecodeHex("f19539818b4f29fa0ee599db4113fd81b77cd1119682e6d799a052849d2e40ef0dad84bc947ba2dee742d9731f1b9e9b"),
SHA3_512: mustDecodeHex("f0a2c0f9090c1fd6dedf211192e36a6668d2b3c7f57a35419acb1c4fc7dfffc267bbcd90f5f38676caddcab652f6aacd1ed4e0ad0a8e1e4b98f890b62b6c7c5c"),
XXH64: mustDecodeHex("d3e8573b7abf279a"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Checks out for me.

$ pip install xxhash
macbook15:beats akroh$ python
Python 2.7.14 (default, Mar 10 2018, 00:01:04) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
>>> import xxhash
>>> xxhash.xxh64(b'hello world!\n').hexdigest()
'd3e8573b7abf279a'

@@ -20,6 +20,8 @@ import (
"golang.org/x/crypto/blake2b"
"golang.org/x/crypto/sha3"

"github.com/OneOfOne/xxhash"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally we have three import groups (stdlib, non-elastic, then elastic). So just merge this one into the group above.

@@ -58,7 +58,7 @@

# Hash types to compute when the file changes. Supported types are
# blake2b_256, blake2b_384, blake2b_512, md5, sha1, sha224, sha256, sha384,
# sha512, sha512_224, sha512_256, sha3_224, sha3_256, sha3_384 and sha3_512.
# sha512, sha512_224, sha512_256, sha3_224, sha3_256, sha3_384, sha3_512 and xxh64.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an Oxford comma.

@@ -96,7 +96,7 @@ a suffix to the value. The supported units are `b` (default), `kib`, `kb`, `mib`
*`hash_types`*:: A list of hash types to compute when the file changes.
The supported hash types are `blake2b_256`, `blake2b_384`, `blake2b_512`, `md5`,
`sha1`, `sha224`, `sha256`, `sha384`, `sha512`, `sha512_224`, `sha512_256`,
`sha3_224`, `sha3_256`, `sha3_384`, and `sha3_512`. The default value is `sha1`.
`sha3_224`, `sha3_256`, `sha3_384`, `sha3_512` and `xxh64`. The default value is `sha1`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an Oxford comma.

@original-brownbear
Copy link
Member Author

@andrewkroh thanks, all fixed I think :)

@andrewkroh
Copy link
Member

I'm probably hitting the upper read limit of the SSD with these benchmarks. I should probably refactor them to be performed on data from memory only.

Hash Algorithm Time per 100 MiB File (ns) MiB/sec
BenchmarkHashFile/xxh64-8 33600124 2976.179493
BenchmarkHashFile/blake2b_256-8 133043092 751.6361691
BenchmarkHashFile/sha1-8 135805400 736.3477446
BenchmarkHashFile/blake2b_512-8 136700485 731.5263
BenchmarkHashFile/blake2b_384-8 152761140 654.6167435
BenchmarkHashFile/md5-8 189990542 526.3419902
BenchmarkHashFile/sha512-8 228272969 438.0720172
BenchmarkHashFile/sha384-8 232457622 430.1859373
BenchmarkHashFile/sha512_256-8 253404170 394.6264973
BenchmarkHashFile/sha512_224-8 259873080 384.8032278
BenchmarkHashFile/sha256-8 298243208 335.2968226
BenchmarkHashFile/sha224-8 314394388 318.0718353
BenchmarkHashFile/sha3_224-8 362159705 276.1212764
BenchmarkHashFile/sha3_256-8 364152093 274.610532
BenchmarkHashFile/sha3_384-8 472527055 211.628094
BenchmarkHashFile/sha3_512-8 655922104 152.4571277

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants