summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTechnion <technion@lolware.net>2014-12-01 09:24:16 +0000
committerTechnion <technion@lolware.net>2014-12-01 09:24:16 +0000
commit7c949b891f7d5b964a5a233edec0a7feda402163 (patch)
treec65d5e04ec5ee53036a06bfc8fef0dde0c7b2b42
parentbd161172424af4627952d03412ee67142766d71c (diff)
Much more effecient N calculation, and now handles N > 15 (althought you wouldn't want to with today's computers).
Credit to Achim Stahlberger <achim.stahlberger@fun.de>.
-rw-r--r--crypto_scrypt-check.c19
1 files changed, 1 insertions, 18 deletions
diff --git a/crypto_scrypt-check.c b/crypto_scrypt-check.c
index f198ef0..7ac0e0c 100644
--- a/crypto_scrypt-check.c
+++ b/crypto_scrypt-check.c
@@ -13,23 +13,6 @@
#define strtok_r(str, val, saveptr) strtok((str), (val))
#endif
-/* pow() works with doubles. Sounds like it should cast to int correctly,
-* but doesn't always. This is faster anyway
-*/
-static uint16_t ipow(uint16_t base, uint64_t exp)
-{
- uint16_t result = 1;
- while (exp != 0)
- {
- if ((exp & 1) != 0)
- result *= base;
- exp >>= 1;
- base *= base;
- }
-
- return result;
-}
-
int libscrypt_check(char *mcf, const char *password)
{
/* Return values:
@@ -81,7 +64,7 @@ int libscrypt_check(char *mcf, const char *password)
if (N > SCRYPT_SAFE_N)
return -1;
- N = ipow(2, N);
+ N = (uint64_t)1 << N;
/* Useful debugging:
printf("We've obtained salt 'N' r p of '%s' %d %d %d\n", tok, N,r,p);