Skip to content

Commit

Permalink
Merge pull request #939 from Cyan4973/detect894
Browse files Browse the repository at this point in the history
updated internal check in xxhsum
  • Loading branch information
Cyan4973 authored May 8, 2024
2 parents 0ddf146 + e9f1b96 commit 9f465f1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 13 deletions.
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 @@ -4713,11 +4718,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

0 comments on commit 9f465f1

Please sign in to comment.