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

updated internal check in xxhsum #939

Merged
merged 2 commits into from
May 8, 2024
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
55 changes: 47 additions & 8 deletions cli/xsum_sanity_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,17 @@ static void XSUM_testXXH3(const void* data, const XSUM_testdata64_t* testData)
XXH3_generateSecret_fromSeed(secret, seed);
{ XSUM_U64 const Dresult = XXH3_64bits_withSecretandSeed(data, len, secret, XXH3_SECRET_DEFAULT_SIZE, seed);
XSUM_checkResult64(Dresult, Nresult);
} }
}

/* check that XXH3_64bits_withSecretandSeed()
* results in exactly the same return value as XXH3_64bits_withSeed()
* when len <= XXH3_MIDSIZE_MAX, whatever the content of @secret */
memset(secret, 0x99, 9);
if (len <= XXH3_MIDSIZE_MAX) {
XSUM_U64 const Dresult = XXH3_64bits_withSecretandSeed(data, len, secret, XXH3_SECRET_DEFAULT_SIZE, seed);
XSUM_checkResult64(Dresult, Nresult);
}
}

/* streaming API test */
{ XXH3_state_t* const state = XXH3_createState();
Expand Down Expand Up @@ -423,6 +433,17 @@ static void XSUM_testXXH3(const void* data, const XSUM_testdata64_t* testData)
(void)XXH3_64bits_reset_withSecretandSeed(state, secret, XXH3_SECRET_DEFAULT_SIZE, seed);
(void)XXH3_64bits_update(state, data, len);
XSUM_checkResult64(XXH3_64bits_digest(state), Nresult);

/* check that XXH3_64bits_withSecretandSeed()
* results in exactly the same return value as XXH3_64bits_withSeed()
* when len <= XXH3_MIDSIZE_MAX, whatever the content of @secret */
if (len <= XXH3_MIDSIZE_MAX) {
/* single ingestion */
memset(secret, 0x99, 9);
(void)XXH3_64bits_reset_withSecretandSeed(state, secret, XXH3_SECRET_DEFAULT_SIZE, seed);
(void)XXH3_64bits_update(state, data, len);
XSUM_checkResult64(XXH3_64bits_digest(state), Nresult);
}
}

XXH3_freeState(state);
Expand All @@ -431,10 +452,6 @@ static void XSUM_testXXH3(const void* data, const XSUM_testdata64_t* testData)
}


#ifndef XXH3_MIDSIZE_MAX
# define XXH3_MIDSIZE_MAX 240
#endif

static void XSUM_testXXH3_withSecret(const void* data, const void* secret,
size_t secretSize, const XSUM_testdata64_t* testData)
{
Expand Down Expand Up @@ -478,10 +495,11 @@ static void XSUM_testXXH3_withSecret(const void* data, const void* secret,
}

/* check that XXH3_64bits_reset_withSecretandSeed()
* results in exactly the same return value as XXH3_64bits_reset_withSecret() */
* results in exactly the same return value as XXH3_64bits_reset_withSecret()
* when len > XXH3_MIDSIZE_MAX, whatever the value of @seed */
if (len > XXH3_MIDSIZE_MAX) {
/* single ingestion */
(void)XXH3_64bits_reset_withSecretandSeed(state, secret, secretSize, 0);
(void)XXH3_64bits_reset_withSecretandSeed(state, secret, secretSize, 17);
(void)XXH3_64bits_update(state, data, len);
XSUM_checkResult64(XXH3_64bits_digest(state), Nresult);
}
Expand Down Expand Up @@ -524,7 +542,17 @@ static void XSUM_testXXH128(const void* data, const XSUM_testdata128_t* testData
XXH3_generateSecret_fromSeed(secret, seed);
{ XXH128_hash_t const Dresult = XXH3_128bits_withSecretandSeed(data, len, secret, XXH3_SECRET_DEFAULT_SIZE, seed);
XSUM_checkResult128(Dresult, Nresult);
} }
}

/* check that XXH3_128bits_withSecretandSeed()
* results in exactly the same return value as XXH3_128bits_withSeed()
* if len <= XXH3_MIDSIZE_MAX, whatever the content of @secret */
memset(secret, 0x99, 9);
if (len <= XXH3_MIDSIZE_MAX) {
XXH128_hash_t const Dresult = XXH3_128bits_withSecretandSeed(data, len, secret, XXH3_SECRET_DEFAULT_SIZE, seed);
XSUM_checkResult128(Dresult, Nresult);
}
}

/* streaming API test */
{ XXH3_state_t *state = XXH3_createState();
Expand Down Expand Up @@ -558,6 +586,17 @@ static void XSUM_testXXH128(const void* data, const XSUM_testdata128_t* testData
(void)XXH3_128bits_reset_withSecretandSeed(state, secret, XXH3_SECRET_DEFAULT_SIZE, seed);
(void)XXH3_128bits_update(state, data, len);
XSUM_checkResult128(XXH3_128bits_digest(state), Nresult);

/* check that XXH3_128bits_reset_withSecretandSeed()
* results in exactly the same return value as XXH3_128bits_reset_withSeed()
* if len <= XXH3_MIDSIZE_MAX, whatever the content of @secret */
if (len <= XXH3_MIDSIZE_MAX) {
/* single ingestion */
memset(secret, 0x99, 9);
(void)XXH3_128bits_reset_withSecretandSeed(state, secret, XXH3_SECRET_DEFAULT_SIZE, seed);
(void)XXH3_128bits_update(state, data, len);
XSUM_checkResult128(XXH3_128bits_digest(state), Nresult);
}
}

XXH3_freeState(state);
Expand Down
10 changes: 5 additions & 5 deletions xxhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -1923,6 +1923,11 @@ XXH_PUBLIC_API XXH_errorcode XXH3_generateSecret(XXH_NOESCAPE void* secretBuffer
*/
XXH_PUBLIC_API void XXH3_generateSecret_fromSeed(XXH_NOESCAPE void* secretBuffer, XXH64_hash_t seed);

/*!
* @brief Maximum size of "short" key in bytes.
*/
#define XXH3_MIDSIZE_MAX 240

/*!
* @brief Calculates 64/128-bit seeded variant of XXH3 hash of @p data.
*
Expand Down Expand Up @@ -4701,11 +4706,6 @@ XXH3_len_17to128_64b(const xxh_u8* XXH_RESTRICT input, size_t len,
}
}

/*!
* @brief Maximum size of "short" key in bytes.
*/
#define XXH3_MIDSIZE_MAX 240

XXH_NO_INLINE XXH_PUREF XXH64_hash_t
XXH3_len_129to240_64b(const xxh_u8* XXH_RESTRICT input, size_t len,
const xxh_u8* XXH_RESTRICT secret, size_t secretSize,
Expand Down
Loading