From e16b40806122fd40ff510efac41e74b8bc185bae Mon Sep 17 00:00:00 2001 From: Moinak Ghosh Date: Sun, 3 Mar 2013 21:55:59 +0530 Subject: [PATCH] Move Scrypt helper function out of AES module. Fix a compiler warning. --- crypto/aes/crypto_aes.c | 41 ----------------------------- crypto/scrypt/crypto_scrypt-nosse.c | 41 +++++++++++++++++++++++++++++ crypto/scrypt/crypto_scrypt.h | 2 ++ rabin/global/db.c | 2 +- 4 files changed, 44 insertions(+), 42 deletions(-) diff --git a/crypto/aes/crypto_aes.c b/crypto/aes/crypto_aes.c index e29b375..6c4aaa6 100644 --- a/crypto/aes/crypto_aes.c +++ b/crypto/aes/crypto_aes.c @@ -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) diff --git a/crypto/scrypt/crypto_scrypt-nosse.c b/crypto/scrypt/crypto_scrypt-nosse.c index 1580a72..eb2edf4 100644 --- a/crypto/scrypt/crypto_scrypt-nosse.c +++ b/crypto/scrypt/crypto_scrypt-nosse.c @@ -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) { diff --git a/crypto/scrypt/crypto_scrypt.h b/crypto/scrypt/crypto_scrypt.h index 2e5f636..5a37aac 100644 --- a/crypto/scrypt/crypto_scrypt.h +++ b/crypto/scrypt/crypto_scrypt.h @@ -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_ */ diff --git a/rabin/global/db.c b/rabin/global/db.c index 2e340c4..4818e4c 100644 --- a/rabin/global/db.c +++ b/rabin/global/db.c @@ -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;