From 571e803760e775f73766eaae5f9b8de8dfff7214 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 8 Jul 2013 15:43:39 -0700 Subject: [PATCH] fix high-iteration stack overflow by flattening the list The core loop had too many generators: chaining them together results in high stack usage (and reduced speed) when called with a high number of iterations. At roughly 88000 iterations, python segfaults. Removing those extra stack frames also appears to speed up the loop by about 5% This fixes #2. --- pbkdf2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pbkdf2.py b/pbkdf2.py index b7a7dd4..29455db 100644 --- a/pbkdf2.py +++ b/pbkdf2.py @@ -72,7 +72,7 @@ def _pseudorandom(x, mac=mac): rv = u = _pseudorandom(salt + _pack_int(block)) for i in xrange(iterations - 1): u = _pseudorandom(''.join(map(chr, u))) - rv = starmap(xor, izip(rv, u)) + rv = list(starmap(xor, izip(rv, u))) buf.extend(rv) return ''.join(map(chr, buf))[:keylen]