Пример #1
0
 def gen():
     for i in irange(block_count):
         digest = prf_func(secret, salt + pack(">L", i+1))
         accum = bytes_to_int(digest)
         for _ in irange(rounds-1):
             digest = prf_func(secret, digest)
             accum ^= bytes_to_int(digest)
         yield int_to_bytes(accum, digest_size)
Пример #2
0
 def gen():
     for i in irange(block_count):
         digest = prf_func(secret, salt + pack(">L", i+1))
         accum = bytes_to_int(digest)
         for _ in irange(rounds-1):
             digest = prf_func(secret, digest)
             accum ^= bytes_to_int(digest)
         yield int_to_bytes(accum, digest_size)
Пример #3
0
 def gen():
     for i in irange(block_count):
         digest = keyed_prf(salt + pack(">L", i + 1))
         accum = bytes_to_int(digest)
         # speed-critical loop of pbkdf2
         # NOTE: currently converting digests to integers since that XORs faster.
         for _ in irange(rounds - 1):
             digest = keyed_prf(digest)
             accum ^= bytes_to_int(digest)
         yield int_to_bytes(accum, digest_size)
Пример #4
0
 def gen():
     for i in irange(block_count):
         digest = keyed_prf(salt + pack(">L", i+1))
         accum = bytes_to_int(digest)
         # speed-critical loop of pbkdf2
         # NOTE: currently converting digests to integers since that XORs faster.
         for _ in irange(rounds-1):
             digest = keyed_prf(digest)
             accum ^= bytes_to_int(digest)
         yield int_to_bytes(accum, digest_size)
Пример #5
0
def des_encrypt_block(key, input):
    """do traditional encryption of a single DES block

    :arg key: 8 byte des key
    :arg input: 8 byte plaintext
    :returns: 8 byte ciphertext

    all values must be :class:`bytes`
    """
    if not isinstance(key, bytes):
        raise TypeError("key must be bytes, not %s" % (type(key),))
    if len(key) == 7:
        key = expand_des_key(key)
    assert len(key) == 8
    if not isinstance(input, bytes):
        raise TypeError("input must be bytes, not %s" % (type(input),))
    assert len(input) == 8
    input = bytes_to_int(input)
    key = bytes_to_int(key)
    out = mdes_encrypt_int_block(key, input, 0, 1)
    return int_to_bytes(out, 8)