Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/root/sys/lib/python2.7/hashlib.pyo

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�`^c@szdZdZeZedZd
�Zd�Zdd
�Zdd�ZyddlZeZ	eZ
Wnek
r�eZ	eZ
nXxUeD]MZye
e�e
�e<Wq�ek
r�ddlZejde�q�Xq�WyddlmZWnsek
rcddlZddlZdjd�ed�D��Zdjd�ed�D��Zdd�ZnX[[[
[[[dS(sphashlib module - A common interface to many hash functions.

new(name, string='') - returns a new hash object implementing the
                       given hash function; initializing the hash
                       using the given string data.

Named constructor functions are also available, these are much faster
than using new():

md5(), sha1(), sha224(), sha256(), sha384(), and sha512()

More algorithms may be available on your platform but the above are
guaranteed to exist.

NOTE: If you want the adler32 or crc32 hash functions they are available in
the zlib module.

Choose your hash function wisely.  Some have known collision weaknesses.
sha384 and sha512 will be slow on 32 bit platforms.

Hash objects have these methods:
 - update(arg): Update the hash object with the string arg. Repeated calls
                are equivalent to a single call with the concatenation of all
                the arguments.
 - digest():    Return the digest of the strings passed to the update() method
                so far. This may contain non-ASCII characters, including
                NUL bytes.
 - hexdigest(): Like digest() except the digest is returned as a string of
                double length, containing only hexadecimal digits.
 - copy():      Return a copy (clone) of the hash object. This can be used to
                efficiently compute the digests of strings that share a common
                initial substring.

For example, to obtain the digest of the string 'Nobody inspects the
spammish repetition':

    >>> import hashlib
    >>> m = hashlib.md5()
    >>> m.update("Nobody inspects")
    >>> m.update(" the spammish repetition")
    >>> m.digest()
    '\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d\xf0\xff\xe9'

More condensed:

    >>> hashlib.sha224("Nobody inspects the spammish repetition").hexdigest()
    'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2'

tmd5tsha1tsha224tsha256tsha384tsha512tnewt
algorithmstpbkdf2_hmaccCsy�|dkr"ddl}|jS|dkrAddl}|jS|dkr�ddl}|d
}|dkrv|jS|dkr�|jSnK|dkr�ddl}|d
}|dkr�|jS|dkr�|jSnWnt	k
r�nXt
d|��dS(NtSHA1Ri�tMD5RtSHA256RtSHA224Rit256t224tSHA512RtSHA384Rt512t384sunsupported hash type (R	R(R
R(Rssha256Rssha224(Rssha512Rssha384(t_shaRt_md5t_sha256RRt_sha512RRtImportErrort
ValueError(tnameRRRtbsR((s/sys/lib/python2.7/hashlib.pyt__get_builtin_constructorBs0



cCsGy"ttd|�}|�|SWnttfk
rBt|�SXdS(Ntopenssl_(tgetattrt_hashlibtAttributeErrorRR(Rtf((s/sys/lib/python2.7/hashlib.pyt__get_openssl_constructor^stcCst|�|�S(s|new(name, string='') - Return a new hashing object using the named algorithm;
    optionally initialized with a string.
    (R(Rtstring((s/sys/lib/python2.7/hashlib.pyt__py_newjscCs9ytj||�SWntk
r4t|�|�SXdS(s|new(name, string='') - Return a new hashing object using the named algorithm;
    optionally initialized with a string.
    N(RRRR(RR#((s/sys/lib/python2.7/hashlib.pyt
__hash_newqs
i�Nscode for hash %s was not found.(Rccs|]}t|dA�VqdS(i\N(tchr(t.0tx((s/sys/lib/python2.7/hashlib.pys	<genexpr>�siccs|]}t|dA�VqdS(i6N(R&(R'R(((s/sys/lib/python2.7/hashlib.pys	<genexpr>�scCsCt|t�st|��nt|ttf�sHtt|��}nt|ttf�srtt|��}nt|�}t|�}t|dd�}t|�|kr�t||�j	�}n|d|t|�}|j
|jt��|j
|jt
��||d�}|dkr4t|��n|dkrL|j}n|dkrgt|��ndt|�jd}	d}
d}x�t|
�|kr:||tjd	|��}ttj|�d
�}
x@t|d�D].}||�}|
ttj|�d
�N}
q�|d7}|
tj|	|
�7}
q�W|
| S(s�Password based key derivation function 2 (PKCS #5 v2.0)

        This Python implementations based on the hmac module about as fast
        as OpenSSL's PKCS5_PBKDF2_HMAC for short passwords and much faster
        for long passwords.
        t
block_sizei@tcSsB|j�}|j�}|j|�|j|j��|j�S(N(tcopytupdatetdigest(tmsgtinnertouterticpytocpy((s/sys/lib/python2.7/hashlib.pytprf�s

is%%0%ixiR"s>IiN(t
isinstancetstrt	TypeErrortbytest	bytearraytbufferRRtlenR-R,t	translatet	_trans_36t	_trans_5CRtNonetdigest_sizetstructtpacktinttbinasciithexlifytxranget	unhexlify(t	hash_nametpasswordtsaltt
iterationstdklenR/R0t	blocksizeR3thex_format_stringtdkeytlooptprevtrkeyti((s/sys/lib/python2.7/hashlib.pyR�sB	 
(smd5ssha1ssha224ssha256ssha384ssha512(snews
algorithmsspbkdf2_hmac(t__doc__t__always_supportedRt__all__RR!R$R%RRt
__get_hashRt__func_nametglobalsRtloggingt	exceptionRRCR@tjointrangeR=R<R>(((s/sys/lib/python2.7/hashlib.pyt<module>7s<
		





9	

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].