Lines Matching refs:secret

774  * default 64-bit variant, using default secret and default seed of 0.
780 * This variant generates a custom secret on the fly
781 * based on default secret altered using the `seed` value.
788 * The bare minimum size for a custom secret.
798 * It's possible to provide any blob of bytes as a "secret" to generate the hash.
801 * However, the quality of the secret impacts the dispersion of the hash algorithm.
802 * Therefore, the secret _must_ look like a bunch of random bytes.
806 * It will generate a proper high entropy secret derived from the blob of bytes.
811 * because, when hashing _small_ inputs, only a portion of the secret is employed.
813 XXH_PUBLIC_API XXH64_hash_t XXH3_64bits_withSecret(const void* data, size_t len, const void* secret, size_t secretSize);
842 * Generate a custom secret from `seed`, and store it into `statePtr`.
848 * `secret` is referenced, it _must outlive_ the hash streaming session.
850 * and the quality of produced hash values depends on secret's entropy
851 * (secret's content should look like a bunch of random bytes).
852 * When in doubt about the randomness of a candidate `secret`,
855 XXH_PUBLIC_API XXH_errorcode XXH3_64bits_reset_withSecret(XXH3_state_t* statePtr, const void* secret, size_t secretSize);
881 XXH_PUBLIC_API XXH128_hash_t XXH3_128bits_withSecret(const void* data, size_t len, const void* secret, size_t secretSize);
898 XXH_PUBLIC_API XXH_errorcode XXH3_128bits_reset_withSecret(XXH3_state_t* statePtr, const void* secret, size_t secretSize);
1038 * @brief Default size of the secret buffer (and @ref XXH3_kSecret).
1072 /*!< Used to store a custom secret generated from a seed. */
1092 /*!< Reference to an external secret for the _withSecret variants, NULL
1125 * Derive a high-entropy secret from any user-defined content, named customSeed.
1126 * The generated secret can be used in combination with `*_withSecret()` functions.
1131 * and derives from it a high-entropy secret of length @secretSize
1135 * The generated secret can then be used with any `*_withSecret()` variant.
1138 * are part of this list. They all accept a `secret` parameter
1146 * The resulting `secret` will nonetheless provide all required qualities.
1156 * Generate the same secret as the _withSeed() variants.
1158 * The resulting secret has a length of XXH3_SECRET_DEFAULT_SIZE (necessarily).
1161 * The generated secret can be used in combination with
1172 * or @secret for "large" keys (>= XXH3_MIDSIZE_MAX).
1175 * `_withSeed()` has to generate the secret on the fly for "large" keys.
1181 * When @secret has been generated by XXH3_generateSecret_fromSeed(),
1184 * by skipping the need to regenerate the secret for every large input.
1186 * Another usage scenario is to hash the secret to a 64-bit hash value,
1188 * and then employ both the seed and the secret in _withSecretandSeed().
1189 * On top of speed, an added benefit is that each bit in the secret
1192 * This is not guaranteed when using the secret directly in "small data" scenarios,
1193 * because only portions of the secret are employed for small data.
1197 const void* secret, size_t secretSize,
1202 const void* secret, size_t secretSize,
1207 const void* secret, size_t secretSize,
1212 const void* secret, size_t secretSize,
3193 /*! Pseudorandom secret taken directly from FARSH. */
3453 * the entire secret.
3458 * Therefore, we use different sections of the secret and always mix two secret
3463 * The XOR mixing hides individual parts of the secret and increases entropy.
3468 XXH3_len_1to3_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed)
3472 XXH_ASSERT(secret != NULL);
3483 xxh_u64 const bitflip = (XXH_readLE32(secret) ^ XXH_readLE32(secret+4)) + seed;
3490 XXH3_len_4to8_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed)
3493 XXH_ASSERT(secret != NULL);
3498 xxh_u64 const bitflip = (XXH_readLE64(secret+8) ^ XXH_readLE64(secret+16)) - seed;
3506 XXH3_len_9to16_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed)
3509 XXH_ASSERT(secret != NULL);
3511 { xxh_u64 const bitflip1 = (XXH_readLE64(secret+24) ^ XXH_readLE64(secret+32)) + seed;
3512 xxh_u64 const bitflip2 = (XXH_readLE64(secret+40) ^ XXH_readLE64(secret+48)) - seed;
3523 XXH3_len_0to16_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed)
3526 { if (XXH_likely(len > 8)) return XXH3_len_9to16_64b(input, len, secret, seed);
3527 if (XXH_likely(len >= 4)) return XXH3_len_4to8_64b(input, len, secret, seed);
3528 if (len) return XXH3_len_1to3_64b(input, len, secret, seed);
3529 return XXH64_avalanche(seed ^ (XXH_readLE64(secret+56) ^ XXH_readLE64(secret+64)));
3544 * cancelling out the secret is taken an arbitrary number of times (addressed
3560 const xxh_u8* XXH_RESTRICT secret, xxh_u64 seed64)
3585 input_lo ^ (XXH_readLE64(secret) + seed64),
3586 input_hi ^ (XXH_readLE64(secret+8) - seed64)
3594 const xxh_u8* XXH_RESTRICT secret, size_t secretSize,
3604 acc += XXH3_mix16B(input+48, secret+96, seed);
3605 acc += XXH3_mix16B(input+len-64, secret+112, seed);
3607 acc += XXH3_mix16B(input+32, secret+64, seed);
3608 acc += XXH3_mix16B(input+len-48, secret+80, seed);
3610 acc += XXH3_mix16B(input+16, secret+32, seed);
3611 acc += XXH3_mix16B(input+len-32, secret+48, seed);
3613 acc += XXH3_mix16B(input+0, secret+0, seed);
3614 acc += XXH3_mix16B(input+len-16, secret+16, seed);
3624 const xxh_u8* XXH_RESTRICT secret, size_t secretSize,
3637 acc += XXH3_mix16B(input+(16*i), secret+(16*i), seed);
3667 acc += XXH3_mix16B(input+(16*i), secret+(16*(i-8)) + XXH3_MIDSIZE_STARTOFFSET, seed);
3670 acc += XXH3_mix16B(input + len - 16, secret + XXH3_SECRET_SIZE_MIN - XXH3_MIDSIZE_LASTOFFSET, seed);
3679 #define XXH_SECRET_CONSUME_RATE 8 /* nb of secret bytes consumed at each accumulation */
3741 const void* XXH_RESTRICT secret)
3750 /* key_vec = secret[0]; */
3751 __m512i const key_vec = _mm512_loadu_si512 (secret);
3778 * Since our algorithm uses a pseudorandom secret to add some variance into the
3788 XXH3_scrambleAcc_avx512(void* XXH_RESTRICT acc, const void* XXH_RESTRICT secret)
3799 /* xacc[0] ^= secret; */
3800 __m512i const key_vec = _mm512_loadu_si512 (secret);
3850 const void* XXH_RESTRICT secret)
3859 const __m256i* const xsecret = (const __m256i *) secret;
3882 XXH3_scrambleAcc_avx2(void* XXH_RESTRICT acc, const void* XXH_RESTRICT secret)
3888 const __m256i* const xsecret = (const __m256i *) secret;
3925 * - do not extract the secret from sse registers in the internal loop
3955 const void* XXH_RESTRICT secret)
3965 const __m128i* const xsecret = (const __m128i *) secret;
3988 XXH3_scrambleAcc_sse2(void* XXH_RESTRICT acc, const void* XXH_RESTRICT secret)
3994 const __m128i* const xsecret = (const __m128i *) secret;
4036 * - do not extract the secret from sse registers in the internal loop
4056 void const* XXH_RESTRICT secret, size_t lane);
4060 void const* XXH_RESTRICT secret, size_t lane);
4075 const void* XXH_RESTRICT secret)
4083 uint8_t const* const xsecret = (const uint8_t *) secret;
4110 XXH3_scalarRound(acc, input, secret, i);
4116 XXH3_scrambleAcc_neon(void* XXH_RESTRICT acc, const void* XXH_RESTRICT secret)
4121 uint8_t const* xsecret = (uint8_t const*) secret;
4169 XXH3_scalarScrambleRound(acc, secret, i);
4181 const void* XXH_RESTRICT secret)
4186 xxh_u64x2 const* const xsecret = (xxh_u64x2 const*) secret; /* no alignment restriction */
4215 XXH3_scrambleAcc_vsx(void* XXH_RESTRICT acc, const void* XXH_RESTRICT secret)
4220 const xxh_u64x2* const xsecret = (const xxh_u64x2*) secret;
4258 void const* XXH_RESTRICT secret,
4263 xxh_u8 const* xsecret = (xxh_u8 const*) secret;
4281 const void* XXH_RESTRICT secret)
4285 XXH3_scalarRound(acc, input, secret, i);
4298 void const* XXH_RESTRICT secret,
4302 const xxh_u8* const xsecret = (const xxh_u8*) secret; /* no alignment restriction */
4320 XXH3_scrambleAcc_scalar(void* XXH_RESTRICT acc, const void* XXH_RESTRICT secret)
4324 XXH3_scalarScrambleRound(acc, secret, i);
4457 * Assumption: nbStripes will not overflow the secret size
4462 const xxh_u8* XXH_RESTRICT secret,
4472 secret + n*XXH_SECRET_CONSUME_RATE);
4479 const xxh_u8* XXH_RESTRICT secret, size_t secretSize,
4492 XXH3_accumulate(acc, input + n*block_len, secret, nbStripesPerBlock, f_acc512);
4493 f_scramble(acc, secret + secretSize - XXH_STRIPE_LEN);
4500 XXH3_accumulate(acc, input + nb_blocks*block_len, secret, nbStripes, f_acc512);
4504 #define XXH_SECRET_LASTACC_START 7 /* not aligned on 8, last secret is different from acc & scrambler */
4505 f_acc512(acc, p, secret + secretSize - XXH_STRIPE_LEN - XXH_SECRET_LASTACC_START);
4510 XXH3_mix2Accs(const xxh_u64* XXH_RESTRICT acc, const xxh_u8* XXH_RESTRICT secret)
4513 acc[0] ^ XXH_readLE64(secret),
4514 acc[1] ^ XXH_readLE64(secret+8) );
4518 XXH3_mergeAccs(const xxh_u64* XXH_RESTRICT acc, const xxh_u8* XXH_RESTRICT secret, xxh_u64 start)
4524 result64 += XXH3_mix2Accs(acc+2*i, secret + 16*i);
4549 const void* XXH_RESTRICT secret, size_t secretSize,
4555 XXH3_hashLong_internal_loop(acc, (const xxh_u8*)input, len, (const xxh_u8*)secret, secretSize, f_acc512, f_scramble);
4559 /* do not align on 8, so that the secret is different from the accumulator */
4562 return XXH3_mergeAccs(acc, (const xxh_u8*)secret + XXH_SECRET_MERGEACCS_START, (xxh_u64)len * XXH_PRIME64_1);
4566 * It's important for performance to transmit secret's size (when it's static)
4572 XXH64_hash_t seed64, const xxh_u8* XXH_RESTRICT secret, size_t secretLen)
4575 return XXH3_hashLong_64b_internal(input, len, secret, secretLen, XXH3_accumulate_512, XXH3_scrambleAcc);
4582 * and provide a statically defined secret size to allow optimization of vector loop.
4586 XXH64_hash_t seed64, const xxh_u8* XXH_RESTRICT secret, size_t secretLen)
4588 (void)seed64; (void)secret; (void)secretLen;
4614 { XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
4615 f_initSec(secret, seed);
4616 return XXH3_hashLong_64b_internal(input, len, secret, sizeof(secret),
4626 XXH64_hash_t seed, const xxh_u8* secret, size_t secretLen)
4628 (void)secret; (void)secretLen;
4639 XXH64_hash_t seed64, const void* XXH_RESTRICT secret, size_t secretLen,
4651 return XXH3_len_0to16_64b((const xxh_u8*)input, len, (const xxh_u8*)secret, seed64);
4653 return XXH3_len_17to128_64b((const xxh_u8*)input, len, (const xxh_u8*)secret, secretLen, seed64);
4655 return XXH3_len_129to240_64b((const xxh_u8*)input, len, (const xxh_u8*)secret, secretLen, seed64);
4656 return f_hashLong(input, len, seed64, (const xxh_u8*)secret, secretLen);
4670 XXH3_64bits_withSecret(const void* input, size_t len, const void* secret, size_t secretSize)
4672 return XXH3_64bits_internal(input, len, 0, secret, secretSize, XXH3_hashLong_64b_withSecret);
4683 XXH3_64bits_withSecretandSeed(const void* input, size_t len, const void* secret, size_t secretSize, XXH64_hash_t seed)
4687 return XXH3_hashLong_64b_withSecret(input, len, seed, (const xxh_u8*)secret, secretSize);
4784 const void* secret, size_t secretSize)
4802 statePtr->extSecret = (const unsigned char*)secret;
4819 XXH3_64bits_reset_withSecret(XXH3_state_t* statePtr, const void* secret, size_t secretSize)
4822 XXH3_reset_internal(statePtr, 0, secret, secretSize);
4823 if (secret == NULL) return XXH_ERROR;
4842 XXH3_64bits_reset_withSecretandSeed(XXH3_state_t* statePtr, const void* secret, size_t secretSize, XXH64_hash_t seed64)
4845 if (secret == NULL) return XXH_ERROR;
4847 XXH3_reset_internal(statePtr, seed64, secret, secretSize);
4854 * so that the function can blindly consume all stripes using the "normal" secret segment */
4859 const xxh_u8* XXH_RESTRICT secret, size_t secretLimit,
4869 XXH3_accumulate(acc, input, secret + nbStripesSoFarPtr[0] * XXH_SECRET_CONSUME_RATE, nbStripesToEndofBlock, f_acc512);
4870 f_scramble(acc, secret + secretLimit);
4871 XXH3_accumulate(acc, input + nbStripesToEndofBlock * XXH_STRIPE_LEN, secret, nbStripesAfterBlock, f_acc512);
4874 XXH3_accumulate(acc, input, secret + nbStripesSoFarPtr[0] * XXH_SECRET_CONSUME_RATE, nbStripes, f_acc512);
4900 const unsigned char* const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret;
4935 secret, state->secretLimit,
4948 XXH3_accumulate(acc, input, secret + state->nbStripesSoFar * XXH_SECRET_CONSUME_RATE, nbStripesToEnd, f_acc512);
4949 f_scramble(acc, secret + state->secretLimit);
4956 XXH3_accumulate(acc, input, secret, state->nbStripesPerBlock, f_acc512);
4957 f_scramble(acc, secret + state->secretLimit);
4962 XXH3_accumulate(acc, input, secret, nbStripes, f_acc512);
4978 secret, state->secretLimit,
5014 const unsigned char* secret)
5027 secret, state->secretLimit,
5032 secret + state->secretLimit - XXH_SECRET_LASTACC_START);
5041 secret + state->secretLimit - XXH_SECRET_LASTACC_START);
5048 const unsigned char* const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret;
5051 XXH3_digest_long(acc, state, secret);
5053 secret + XXH_SECRET_MERGEACCS_START,
5060 secret, state->secretLimit + XXH_STRIPE_LEN);
5083 XXH3_len_1to3_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed)
5088 XXH_ASSERT(secret != NULL);
5100 xxh_u64 const bitflipl = (XXH_readLE32(secret) ^ XXH_readLE32(secret+4)) + seed;
5101 xxh_u64 const bitfliph = (XXH_readLE32(secret+8) ^ XXH_readLE32(secret+12)) - seed;
5112 XXH3_len_4to8_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed)
5115 XXH_ASSERT(secret != NULL);
5121 xxh_u64 const bitflip = (XXH_readLE64(secret+16) ^ XXH_readLE64(secret+24)) + seed;
5139 XXH3_len_9to16_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed)
5142 XXH_ASSERT(secret != NULL);
5144 { xxh_u64 const bitflipl = (XXH_readLE64(secret+32) ^ XXH_readLE64(secret+40)) - seed;
5145 xxh_u64 const bitfliph = (XXH_readLE64(secret+48) ^ XXH_readLE64(secret+56)) + seed;
5211 * Assumption: `secret` size is >= XXH3_SECRET_SIZE_MIN
5214 XXH3_len_0to16_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed)
5217 { if (len > 8) return XXH3_len_9to16_128b(input, len, secret, seed);
5218 if (len >= 4) return XXH3_len_4to8_128b(input, len, secret, seed);
5219 if (len) return XXH3_len_1to3_128b(input, len, secret, seed);
5221 xxh_u64 const bitflipl = XXH_readLE64(secret+64) ^ XXH_readLE64(secret+72);
5222 xxh_u64 const bitfliph = XXH_readLE64(secret+80) ^ XXH_readLE64(secret+88);
5234 const xxh_u8* secret, XXH64_hash_t seed)
5236 acc.low64 += XXH3_mix16B (input_1, secret+0, seed);
5238 acc.high64 += XXH3_mix16B (input_2, secret+16, seed);
5246 const xxh_u8* XXH_RESTRICT secret, size_t secretSize,
5258 acc = XXH128_mix32B(acc, input+48, input+len-64, secret+96, seed);
5260 acc = XXH128_mix32B(acc, input+32, input+len-48, secret+64, seed);
5262 acc = XXH128_mix32B(acc, input+16, input+len-32, secret+32, seed);
5264 acc = XXH128_mix32B(acc, input, input+len-16, secret, seed);
5279 const xxh_u8* XXH_RESTRICT secret, size_t secretSize,
5294 secret + (32 * i),
5304 secret + XXH3_MIDSIZE_STARTOFFSET + (32 * (i - 4)),
5311 secret + XXH3_SECRET_SIZE_MIN - XXH3_MIDSIZE_LASTOFFSET - 16,
5328 const xxh_u8* XXH_RESTRICT secret, size_t secretSize,
5334 XXH3_hashLong_internal_loop(acc, (const xxh_u8*)input, len, secret, secretSize, f_acc512, f_scramble);
5341 secret + XXH_SECRET_MERGEACCS_START,
5344 secret + secretSize
5357 const void* XXH_RESTRICT secret, size_t secretLen)
5359 (void)seed64; (void)secret; (void)secretLen;
5371 const void* XXH_RESTRICT secret, size_t secretLen)
5374 return XXH3_hashLong_128b_internal(input, len, (const xxh_u8*)secret, secretLen,
5389 { XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
5390 f_initSec(secret, seed64);
5391 return XXH3_hashLong_128b_internal(input, len, (const xxh_u8*)secret, sizeof(secret),
5401 XXH64_hash_t seed64, const void* XXH_RESTRICT secret, size_t secretLen)
5403 (void)secret; (void)secretLen;
5413 XXH64_hash_t seed64, const void* XXH_RESTRICT secret, size_t secretLen,
5418 * If an action is to be taken if `secret` conditions are not respected,
5424 return XXH3_len_0to16_128b((const xxh_u8*)input, len, (const xxh_u8*)secret, seed64);
5426 return XXH3_len_17to128_128b((const xxh_u8*)input, len, (const xxh_u8*)secret, secretLen, seed64);
5428 return XXH3_len_129to240_128b((const xxh_u8*)input, len, (const xxh_u8*)secret, secretLen, seed64);
5429 return f_hl128(input, len, seed64, secret, secretLen);
5445 XXH3_128bits_withSecret(const void* input, size_t len, const void* secret, size_t secretSize)
5448 (const xxh_u8*)secret, secretSize,
5463 XXH3_128bits_withSecretandSeed(const void* input, size_t len, const void* secret, size_t secretSize, XXH64_hash_t seed)
5467 return XXH3_hashLong_128b_withSecret(input, len, seed, secret, secretSize);
5494 XXH3_128bits_reset_withSecret(XXH3_state_t* statePtr, const void* secret, size_t secretSize)
5496 return XXH3_64bits_reset_withSecret(statePtr, secret, secretSize);
5508 XXH3_128bits_reset_withSecretandSeed(XXH3_state_t* statePtr, const void* secret, size_t secretSize, XXH64_hash_t seed)
5510 return XXH3_64bits_reset_withSecretandSeed(statePtr, secret, secretSize, seed);
5524 const unsigned char* const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret;
5527 XXH3_digest_long(acc, state, secret);
5531 secret + XXH_SECRET_MERGEACCS_START,
5534 secret + state->secretLimit + XXH_STRIPE_LEN
5544 secret, state->secretLimit + XXH_STRIPE_LEN);
5662 XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
5663 XXH3_initCustomSecret(secret, seed);
5665 memcpy(secretBuffer, secret, XXH_SECRET_DEFAULT_SIZE);