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

added xxh3_128 reference implementation and checksums, fixed use of d… #319

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* text=auto
*.java text eol=lf
*.txt text eol=lf
*.py text eol=lf
*.md text eol=lf
*.csv text
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@
[submodule "reference-implementations/komihash_5_10/komihash"]
path = reference-implementations/komihash_5_10/komihash
url = https://github.com/avaneev/komihash.git
[submodule "reference-implementations/xxh3_128/xxHash"]
path = reference-implementations/xxh3_128/xxHash
url = https://github.com/Cyan4973/xxHash.git
1 change: 1 addition & 0 deletions reference-implementations/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ murmur3_32/murmur3_32_checksum_config.cpp \
murmur3_128/murmur3_128_checksum_config.cpp \
murmur3_128/smhasher/src/MurmurHash3.cpp \
xxh3/xxh3_checksum_config.cpp \
xxh3_128/xxh3_128_checksum_config.cpp \
xxh3/xxHash/xxhash.c \
farmna.a \
farmuo.a \
Expand Down
20 changes: 12 additions & 8 deletions reference-implementations/calculate_checksums.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
#include <random>
#include <fstream>

#include "openssl/sha.h"
#include <openssl/evp.h>

#include "komihash_4_3/komihash_4_3_checksum_config.hpp"
#include "komihash_4_5/komihash_4_5_checksum_config.hpp"
Expand All @@ -32,6 +32,7 @@
#include "farmhash_na/farmhash_na_checksum_config.hpp"
#include "farmhash_uo/farmhash_uo_checksum_config.hpp"
#include "xxh3/xxh3_checksum_config.hpp"
#include "xxh3_128/xxh3_128_checksum_config.hpp"

using namespace std;

Expand Down Expand Up @@ -76,10 +77,10 @@ void computeAndPrintChecksum(
if (dataLength > maxSupportedLength)
continue;

uint8_t checkSum[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
uint8_t checkSum[EVP_MAX_MD_SIZE];
EVP_MD_CTX *mdctx = EVP_MD_CTX_new();

SHA256_Init(&sha256);
EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL);

uint64_t seed = rng();
uint64_t rngState = seed;
Expand Down Expand Up @@ -107,16 +108,18 @@ void computeAndPrintChecksum(
hashFunctionConfig.calculateHash(seedBytes, &hashBytes[0],
dataBytes, dataLength);

SHA256_Update(&sha256, &hashBytes[0], hashBytes.size());
EVP_DigestUpdate(mdctx, &hashBytes[0], hashBytes.size());

}

SHA256_Final(checkSum, &sha256);
unsigned int lengthOfHash = 0;
EVP_DigestFinal_ex(mdctx, checkSum, &lengthOfHash);
EVP_MD_CTX_free(mdctx);

outputFile << dec << dataLength << ",";
outputFile << dec << numCycles << ",";
outputFile << hex << setfill('0') << setw(16) << seed << ",";
for (uint64_t k = 0; k < SHA256_DIGEST_LENGTH; ++k)
for (uint64_t k = 0; k < lengthOfHash; ++k)
outputFile << hex << setfill('0') << setw(2)
<< static_cast<uint64_t>(checkSum[k]);

Expand All @@ -142,6 +145,7 @@ int main(int argc, char *argv[]) {
computeAndPrintChecksum<FarmHashNaChecksumConfig>();
computeAndPrintChecksum<FarmHashUoChecksumConfig>();
computeAndPrintChecksum<XXH3ChecksumConfig>();
computeAndPrintChecksum<XXH3_128_ChecksumConfig>();

return 0;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
#define FARMHASH_NA_CHECKSUM_CONFIG_HPP

#include <string>
#include <cstdint>

class FarmHashNaChecksumConfig {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
#define FARMHASH_UO_CHECKSUM_CONFIG_HPP

#include <string>
#include <cstdint>

class FarmHashUoChecksumConfig {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
#define KOMIHASH_4_3_CHECKSUM_CONFIG_HPP

#include <string>
#include <cstdint>

class Komihash4_3ChecksumConfig {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
#define KOMIHASH_4_5_CHECKSUM_CONFIG_HPP

#include <string>
#include <cstdint>

class Komihash4_5ChecksumConfig {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
#define KOMIHASH_4_7_CHECKSUM_CONFIG_HPP

#include <string>
#include <cstdint>

class Komihash4_7ChecksumConfig {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
#define KOMIHASH_5_0_CHECKSUM_CONFIG_HPP

#include <string>
#include <cstdint>

class Komihash5_0ChecksumConfig {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
#define KOMIHASH_5_10_CHECKSUM_CONFIG_HPP

#include <string>
#include <cstdint>

class Komihash5_10ChecksumConfig {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
#define MURMUR3_128_CHECKSUM_CONFIG_HPP

#include <string>
#include <cstring>
#include <cstdint>

class Murmur3_128_ChecksumConfig {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
#define MURMUR3_32_CHECKSUM_CONFIG_HPP

#include <string>
#include <cstdint>

class Murmur3_32_ChecksumConfig {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
#define POLYMURHASH_2_0_CHECKSUM_CONFIG_HPP

#include <string>
#include <cstdint>

class PolymurHash_2_0_ChecksumConfig {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
#define WYHASH_FINAL_3_CHECKSUM_CONFIG_HPP

#include <string>
#include <cstdint>

class WyhashFinal3ChecksumConfig {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
#define WYHASH_FINAL_4_CHECKSUM_CONFIG_HPP

#include <string>
#include <cstdint>

class WyhashFinal4ChecksumConfig {

Expand Down
3 changes: 2 additions & 1 deletion reference-implementations/xxh3/xxh3_checksum_config.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
#define XXH3_CHECKSUM_CONFIG_HPP

#include <string>
#include <cstdint>

class XXH3ChecksumConfig {

Expand Down
1 change: 1 addition & 0 deletions reference-implementations/xxh3_128/xxHash
Submodule xxHash added at e4e33f
32 changes: 32 additions & 0 deletions reference-implementations/xxh3_128/xxh3_128_checksum_config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "xxh3_128_checksum_config.hpp"
#include "xxhash/xxhash.h"
#include <cstring>

void XXH3_128_ChecksumConfig::calculateHash(const uint8_t *seedBytes,
uint8_t *hashBytes, const uint8_t *dataBytes, uint64_t size) const {

uint64_t seed;
memcpy(&seed, seedBytes, 8);

XXH128_hash_t hash0 = XXH3_128bits((char*) (&dataBytes[0]), size);
XXH128_hash_t hash1 = XXH3_128bits_withSeed((char*) (&dataBytes[0]), size,
seed);

memcpy(hashBytes, &hash0, 16);
memcpy(hashBytes + 16, &hash1, 16);
}
43 changes: 43 additions & 0 deletions reference-implementations/xxh3_128/xxh3_128_checksum_config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef XXH3_128_CHECKSUM_CONFIG_HPP
#define XXH3_128_CHECKSUM_CONFIG_HPP

#include <string>
#include <cstdint>

class XXH3_128_ChecksumConfig {

public:

uint64_t getSeedSize() const {
return 8;
}

uint64_t getHashSize() const {
return 32;
}

std::string getName() const {
return "XXH3_128";
}

void calculateHash(const uint8_t *seedBytes, uint8_t *hashBytes,
const uint8_t *dataBytes, uint64_t size) const;

};

#endif // XXH3_128_CHECKSUM_CONFIG_HPP
Loading
Loading