Move Scrypt helper function out of AES module.
Fix a compiler warning.
This commit is contained in:
parent
7a29c7be1e
commit
e16b408061
4 changed files with 44 additions and 42 deletions
|
@ -91,47 +91,6 @@ aes_module_init(processor_info_t *pc)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fixup parameters for scrypt. Memory is hardcoded here for
|
||||
* reproducibility.
|
||||
*/
|
||||
static void
|
||||
pickparams(int * logN, uint32_t * r, uint32_t * p)
|
||||
{
|
||||
size_t memlimit = 512UL * 1024UL * 1024UL; // 512M
|
||||
double opslimit = 65536;
|
||||
double maxN, maxrp;
|
||||
|
||||
*r = 8;
|
||||
/*
|
||||
* The memory limit requires that 128Nr <= memlimit, while the CPU
|
||||
* limit requires that 4Nrp <= opslimit. If opslimit < memlimit/32,
|
||||
* opslimit imposes the stronger limit on N.
|
||||
*/
|
||||
if (opslimit < memlimit/32) {
|
||||
/* Set p = 1 and choose N based on the CPU limit. */
|
||||
*p = 1;
|
||||
maxN = opslimit / (*r * 4);
|
||||
for (*logN = 1; *logN < 63; *logN += 1) {
|
||||
if ((uint64_t)(1) << *logN > maxN / 2)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Set N based on the memory limit. */
|
||||
maxN = memlimit / (*r * 128);
|
||||
for (*logN = 1; *logN < 63; *logN += 1) {
|
||||
if ((uint64_t)(1) << *logN > maxN / 2)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Choose p based on the CPU limit. */
|
||||
maxrp = (opslimit / 4) / ((uint64_t)(1) << *logN);
|
||||
if (maxrp > 0x3fffffff)
|
||||
maxrp = 0x3fffffff;
|
||||
*p = (uint32_t)(maxrp) / *r;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
aes_init(aes_ctx_t *ctx, uchar_t *salt, int saltlen, uchar_t *pwd, int pwd_len,
|
||||
uint64_t nonce, int enc)
|
||||
|
|
|
@ -50,6 +50,47 @@ static void blockmix_salsa8(uint32_t *, uint32_t *, uint32_t *, size_t);
|
|||
static uint64_t integerify(void *, size_t);
|
||||
static void smix(uint8_t *, size_t, uint64_t, uint32_t *, uint32_t *);
|
||||
|
||||
/*
|
||||
* Fixup parameters for scrypt. Memory is hardcoded here for
|
||||
* reproducibility.
|
||||
*/
|
||||
void
|
||||
pickparams(int * logN, uint32_t * r, uint32_t * p)
|
||||
{
|
||||
size_t memlimit = 512UL * 1024UL * 1024UL; // 512M
|
||||
double opslimit = 65536;
|
||||
double maxN, maxrp;
|
||||
|
||||
*r = 8;
|
||||
/*
|
||||
* The memory limit requires that 128Nr <= memlimit, while the CPU
|
||||
* limit requires that 4Nrp <= opslimit. If opslimit < memlimit/32,
|
||||
* opslimit imposes the stronger limit on N.
|
||||
*/
|
||||
if (opslimit < memlimit/32) {
|
||||
/* Set p = 1 and choose N based on the CPU limit. */
|
||||
*p = 1;
|
||||
maxN = opslimit / (*r * 4);
|
||||
for (*logN = 1; *logN < 63; *logN += 1) {
|
||||
if ((uint64_t)(1) << *logN > maxN / 2)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Set N based on the memory limit. */
|
||||
maxN = memlimit / (*r * 128);
|
||||
for (*logN = 1; *logN < 63; *logN += 1) {
|
||||
if ((uint64_t)(1) << *logN > maxN / 2)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Choose p based on the CPU limit. */
|
||||
maxrp = (opslimit / 4) / ((uint64_t)(1) << *logN);
|
||||
if (maxrp > 0x3fffffff)
|
||||
maxrp = 0x3fffffff;
|
||||
*p = (uint32_t)(maxrp) / *r;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
blkcpy(void * dest, void * src, size_t len)
|
||||
{
|
||||
|
|
|
@ -44,6 +44,8 @@
|
|||
int crypto_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, uint64_t,
|
||||
uint32_t, uint32_t, uint8_t *, size_t);
|
||||
|
||||
void pickparams(int * logN, uint32_t * r, uint32_t * p);
|
||||
|
||||
#define HAVE_POSIX_MEMALIGN
|
||||
|
||||
#endif /* !_CRYPTO_SCRYPT_H_ */
|
||||
|
|
|
@ -219,7 +219,7 @@ db_lookup_insert_s(archive_config_t *cfg, uchar_t *sim_cksum, int interval,
|
|||
index_t *indx = (index_t *)(cfg->dbdata);
|
||||
hash_entry_t **htab, *ent, **pent;
|
||||
|
||||
assert(cfg->similarity_cksum_sz & (sizeof (size_t) - 1) == 0);
|
||||
assert(cfg->similarity_cksum_sz && (sizeof (size_t) - 1) == 0);
|
||||
htab_entry = XXH32(sim_cksum, cfg->similarity_cksum_sz, 0);
|
||||
htab_entry ^= (htab_entry / cfg->similarity_cksum_sz);
|
||||
htab_entry = htab_entry % indx->hash_slots;
|
||||
|
|
Loading…
Reference in a new issue