�
�
5Xc@s�dZddlmZddlZddlmZmZddlmZddl m
Z
mZmZm
Z
ddlmZdd gZd
ddd
ddgZejd�ZdZd�ZdS(s�passlib.crypto._blowfish - pure-python eks-blowfish implementation for bcrypt
This is a pure-python implementation of the EKS-Blowfish algorithm described by
Provos and Mazieres in `A Future-Adaptable Password Scheme
<http://www.openbsd.org/papers/bcrypt-paper.ps>`_.
This package contains two submodules:
* ``_blowfish/base.py`` contains a class implementing the eks-blowfish algorithm
using easy-to-examine code.
* ``_blowfish/unrolled.py`` contains a subclass which replaces some methods
of the original class with sped-up versions, mainly using unrolled loops
and local variables. this is the class which is actually used by
Passlib to perform BCrypt in pure python.
This module is auto-generated by a script, ``_blowfish/_gen_files.py``.
Status
------
This implementation is usable, but is an order of magnitude too slow to be
usable with real security. For "ok" security, BCrypt hashes should have at
least 2**11 rounds (as of 2011). Assuming a desired response time <= 100ms,
this means a BCrypt implementation should get at least 20 rounds/ms in order
to be both usable *and* secure. On a 2 ghz cpu, this implementation gets
roughly 0.09 rounds/ms under CPython (220x too slow), and 1.9 rounds/ms
under PyPy (10x too slow).
History
-------
While subsequently modified considerly for Passlib, this code was originally
based on `jBcrypt 0.2 <http://www.mindrot.org/projects/jBCrypt/>`_, which was
released under the BSD license::
Copyright (c) 2006 Damien Miller <djm@mindrot.org>
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
i����(tchainN(tgetrandbytestrng(tbcrypt64(tBytesIOtunicodetutnative_string_types(tBlowfishEngineRt
raw_bcryptihprOiBnaeiloheiSrediDyrcitbuos>6Itc
Cs�t}|td�ks�|td�ks�|td�kr?nO|td�krZt}n4|td�kr{td��ntd|f��tj|�}t|�dkr�td ��nt|�dkr�|d }n|r�|t7}n|d
ks|dkrtd��nt�}|j |�}|j |�}|d
}|j
||�d
|>} |j||| �tt
�}
d}xM|dkr�|j|
||
|d
d�\|
|<|
|d
<|d7}q�Wtj|
�d }tj|�S(sSperform central password hashing step in bcrypt scheme.
:param password: the password to hash
:param ident: identifier w/ minor version (e.g. 2, 2a)
:param salt: the binary salt to use (encoded in bcrypt-base64)
:param log_rounds: the log2 of the number of rounds (as int)
:returns: bcrypt-base64 encoded checksum
t2at2yt2bt2t2xs>crypt_blowfish's buggy '2x' hashes are not currently supportedsunknown ident: %risMissing salt bytesiisBad number of roundsiiii@ii����(tTrueRtFalset
ValueErrorRtdecode_bytestlentBNULLRtkey_to_wordsteks_salted_expandteks_repeated_expandtlisttBCRYPT_CDATAtrepeat_enciphert
digest_structtpacktencode_bytes(
tpasswordtidenttsaltt
log_roundstadd_null_paddingtenginet
pass_wordst
salt_wordstsalt_words16troundstdatatitraw((sE/usr/lib/python2.7/site-packages/passlib/crypto/_blowfish/__init__.pyR Xs>6
3(t__doc__t itertoolsRtstructt
passlib.utilsRRtpasslib.utils.binaryRtpasslib.utils.compatRRRRt!passlib.crypto._blowfish.unrolledRt__all__RtStructRRR (((sE/usr/lib/python2.7/site-packages/passlib/crypto/_blowfish/__init__.pyt<module>1s" |