Current File : //usr/lib64/python2.7/site-packages/Crypto/Protocol/KDF.pyc |
�
Bd\Rc @ sy d Z d Z d d l Z d d l Z d d l Td d l m Z m Z d d l m
Z
d d d � Z d d d d
� Z
d S( s� This file contains a collection of standard key derivation functions.
A key derivation function derives one or more secondary secret keys from
one primary secret (a master key or a pass phrase).
This is typically done to insulate the secondary keys from each other,
to avoid that leakage of a secondary key compromises the security of the
master key, or to thwart attacks on pass phrases (e.g. via rainbow tables).
:undocumented: __revision__
s $Id$i����N( t *( t SHAt HMAC( t strxori� c C s� | s t } n t | � } | j | | � } | j } | | k rV t d | � � n t | � d k rw t d � � n x- t | d � D] } | j | j � � } q� W| j � | S( s� Derive one key from a password (or passphrase).
This function performs key derivation according an old version of
the PKCS#5 standard (v1.5).
This algorithm is called ``PBKDF1``. Even though it is still described
in the latest version of the PKCS#5 standard (version 2, or RFC2898),
newer applications should use the more secure and versatile `PBKDF2` instead.
:Parameters:
password : string
The secret password or pass phrase to generate the key from.
salt : byte string
An 8 byte string to use for better protection from dictionary attacks.
This value does not need to be kept secret, but it should be randomly
chosen for each derivation.
dkLen : integer
The length of the desired key. Default is 16 bytes, suitable for instance for `Crypto.Cipher.AES`.
count : integer
The number of iterations to carry out. It's recommended to use at least 1000.
hashAlgo : module
The hash algorithm to use, as a module or an object from the `Crypto.Hash` package.
The digest length must be no shorter than ``dkLen``.
The default algorithm is `SHA1`.
:Return: A byte string of length `dkLen` that can be used as key.
s: Selected hash algorithm has a too short digest (%d bytes).i s Salt is not 8 bytes long.i ( t SHA1t tobytest newt digest_sizet
ValueErrort lent xranget digest( t passwordt saltt dkLent countt hashAlgot pHashR t i( ( s9 /usr/lib64/python2.7/site-packages/Crypto/Protocol/KDF.pyt PBKDF1- s i c C s� t | � } | d k r$ d � } n t d � } d } x� t | � | k r� | | | t j d | � � } } x: t | d � D]( } | | | � } }
t | |
� } q W| | 7} | d } q9 W| | S( s� Derive one or more keys from a password (or passphrase).
This performs key derivation according to the PKCS#5 standard (v2.0),
by means of the ``PBKDF2`` algorithm.
:Parameters:
password : string
The secret password or pass phrase to generate the key from.
salt : string
A string to use for better protection from dictionary attacks.
This value does not need to be kept secret, but it should be randomly
chosen for each derivation. It is recommended to be at least 8 bytes long.
dkLen : integer
The cumulative length of the desired keys. Default is 16 bytes, suitable for instance for `Crypto.Cipher.AES`.
count : integer
The number of iterations to carry out. It's recommended to use at least 1000.
prf : callable
A pseudorandom function. It must be a function that returns a pseudorandom string
from two parameters: a secret and a salt. If not specified, HMAC-SHA1 is used.
:Return: A byte string of length `dkLen` that can be used as key material.
If you wanted multiple keys, just break up this string into segments of the desired length.
c S s t j | | t � j � S( N( R R R R ( t pt s( ( s9 /usr/lib64/python2.7/site-packages/Crypto/Protocol/KDF.pyt <lambda>p s t i s >IN( R t Nonet bR t structt packR
R ( R R
R R t prft keyR t Ut previousUt jt t( ( s9 /usr/lib64/python2.7/site-packages/Crypto/Protocol/KDF.pyt PBKDF2V s #
( t __doc__t __revision__t mathR t Crypto.Util.py3compatt Crypto.HashR R R t Crypto.Util.strxorR R R R"