Пример #1
0
def scrypt(password, salt, N=SCRYPT_N, r=SCRYPT_r, p=SCRYPT_p, olen=64):
    """Returns a key derived using the scrypt key-derivarion function

    N must be a power of two larger than 1 but no larger than 2 ** 63 (insane)
    r and p must be positive numbers such that r * p < 2 ** 30

    The default values are:
    N -- 2**14 (~16k)
    r -- 8
    p -- 1

    Memory usage is proportional to N*r. Defaults require about 16 MiB.
    Time taken is proportional to N*p. Defaults take <100ms of a recent x86.

    The last one differs from libscrypt defaults, but matches the 'interactive'
    work factor from the original paper. For long term storage where runtime of
    key derivation is not a problem, you could use 16 as in libscrypt or better
    yet increase N if memory is plentiful.
    """
    check_args(password, salt, N, r, p, olen)

    try:
        return _scrypt(password=password, salt=salt, N=N, r=r, p=p, buflen=olen)
    except:
        raise ValueError
Пример #2
0
def scrypt(password, salt, N=SCRYPT_N, r=SCRYPT_r, p=SCRYPT_p, olen=64):
    """Returns a key derived using the scrypt key-derivarion function

    N must be a power of two larger than 1 but no larger than 2 ** 63 (insane)
    r and p must be positive numbers such that r * p < 2 ** 30

    The default values are:
    N -- 2**14 (~16k)
    r -- 8
    p -- 1

    Memory usage is proportional to N*r. Defaults require about 16 MiB.
    Time taken is proportional to N*p. Defaults take <100ms of a recent x86.

    The last one differs from libscrypt defaults, but matches the 'interactive'
    work factor from the original paper. For long term storage where runtime of
    key derivation is not a problem, you could use 16 as in libscrypt or better
    yet increase N if memory is plentiful.
    """
    check_args(password, salt, N, r, p, olen)

    try:
        return _scrypt(password=password,
                       salt=salt,
                       N=N,
                       r=r,
                       p=p,
                       buflen=olen)
    except:
        raise ValueError
Пример #3
0
import numbers

try:
    from scrypt import hash as _scrypt
except ImportError:
    raise
except:
    raise ImportError('scrypt module failed to import')

from . import mcf as mcf_mod
from .common import *


# scrypt < 0.6 doesn't support hash length
try:
    _scrypt(b'password', b'NaCl', N=2, r=1, p=1, buflen=42)
except TypeError:
    raise ImportError('scrypt module version unsupported, 0.6+ required')


def scrypt(password, salt, N=SCRYPT_N, r=SCRYPT_r, p=SCRYPT_p, olen=64):
    """Returns a key derived using the scrypt key-derivarion function

    N must be a power of two larger than 1 but no larger than 2 ** 63 (insane)
    r and p must be positive numbers such that r * p < 2 ** 30

    The default values are:
    N -- 2**14 (~16k)
    r -- 8
    p -- 1
Пример #4
0
"""Scrypt implementation that calls into the 'scrypt' python module"""

try:
    from scrypt import hash as _scrypt
except ImportError:
    raise
except:
    raise ImportError('scrypt module failed to import')

from . import mcf as mcf_mod
from .common import (SCRYPT_N, SCRYPT_r, SCRYPT_p, SCRYPT_MCF_PREFIX_DEFAULT,
                     check_args)

# scrypt < 0.6 doesn't support hash length
try:
    _scrypt(b'password', b'NaCl', N=2, r=1, p=1, buflen=42)
except TypeError:
    raise ImportError('scrypt module version unsupported, 0.6+ required')


def scrypt(password, salt, N=SCRYPT_N, r=SCRYPT_r, p=SCRYPT_p, olen=64):
    """Returns a key derived using the scrypt key-derivarion function

    N must be a power of two larger than 1 but no larger than 2 ** 63 (insane)
    r and p must be positive numbers such that r * p < 2 ** 30

    The default values are:
    N -- 2**14 (~16k)
    r -- 8
    p -- 1