Exemplo n.º 1
0
    def final(self, output=True):
        """Return hashed data as bytestring.

        `output` is primarily for internal use. It should only be False
        if you have a clear reason for doing so.

        This function can be called as either ``final`` or ``digest``.

        """
        self.tf.tweak[1] |= bigint(0x8000000000000000)  # SKEIN_T1_FLAG_FINAL
        buflen = len(self.buf)
        self.buf += zero_bytes[:64 - buflen]

        self._process_block(self.buf, buflen)

        if not output:
            hash_val = words2bytes(self.tf.key)
        else:
            hash_val = empty_bytes
            self.buf = zero_bytes[:]
            key = self.tf.key[:]  # temporary copy
            i = 0
            while i * 64 < self.digest_size:
                self.buf = words_format[1].pack(i) + self.buf[8:]
                self.tf.tweak = [0, self.block_type['out_final']]
                self._process_block(self.buf, 8)
                n = self.digest_size - i * 64
                if n >= 64:
                    n = 64
                hash_val += words2bytes(self.tf.key)[0:n]
                self.tf.key = key
                i += 1
        return hash_val
    def final(self, output=True):
        """Return hashed data as bytestring.

        `output` is primarily for internal use. It should only be False
        if you have a clear reason for doing so.

        This function can be called as either ``final`` or ``digest``.

        """
        self.tf.tweak[1] |= bigint(0x8000000000000000) # SKEIN_T1_FLAG_FINAL
        buflen = len(self.buf)
        self.buf += zero_bytes[:64-buflen]

        self._process_block(self.buf, buflen)

        if not output:
            hash_val = words2bytes(self.tf.key)
        else:
            hash_val = empty_bytes
            self.buf = zero_bytes[:]
            key = self.tf.key[:] # temporary copy
            i=0
            while i*64 < self.digest_size:
                self.buf = words_format[1].pack(i) + self.buf[8:]
                self.tf.tweak = [0, self.block_type['out_final']]
                self._process_block(self.buf, 8)
                n = self.digest_size - i*64
                if n >= 64:
                    n = 64
                hash_val += words2bytes(self.tf.key)[0:n]
                self.tf.key = key
                i+=1
        return hash_val
Exemplo n.º 3
0
 def getbytes(self, request_bytes):
     """Return random bytestring of length `request_bytes`."""
     self.digest_size = 64 + request_bytes
     self.update(words2bytes(self.tf.key))
     output = self.final()
     self.tf.key = bytes2words(output[0:64])
     return output[64:]
 def getbytes(self, request_bytes):
     """Return random bytestring of length `request_bytes`."""
     self.digest_size = 64 + request_bytes
     self.update(words2bytes(self.tf.key))
     output = self.final()
     self.tf.key = bytes2words(output[0:64])
     return output[64:]
Exemplo n.º 5
0
 def __init__(self, msg='', digest_bits=512, key=None, block_type='msg'):
     self.tf = Threefish512()
     if key:
         self.digest_bits = 512
         self._start_new_type('key')
         self.update(key)
         self.tf.key = bytes2words(self.final(False))
     self.digest_bits = digest_bits
     self.digest_size = (digest_bits + 7) >> 3
     self._start_new_type('cfg_final')
     b = words2bytes((0x133414853, digest_bits, 0, 0, 0, 0, 0, 0))
     self._process_block(b, 32)
     self._start_new_type(block_type)
     if msg:
         self.update(msg)
 def __init__(self, msg='', digest_bits=512, key=None,
              block_type='msg'):
     self.tf = Threefish512()
     if key:
         self.digest_bits = 512
         self._start_new_type('key')
         self.update(key)
         self.tf.key = bytes2words(self.final(False))
     self.digest_bits = digest_bits
     self.digest_size = (digest_bits + 7) >> 3
     self._start_new_type('cfg_final')
     b = words2bytes((0x133414853,digest_bits,0,0,0,0,0,0))
     self._process_block(b,32)
     self._start_new_type(block_type)
     if msg:
         self.update(msg)
Exemplo n.º 7
0
 def reseed(self, seed):
     """(Re)seed the generator."""
     self.digest_size = 64
     self.update(words2bytes(self.tf.key) + seed)
     self.tf.key = bytes2words(self.final())
 def reseed(self, seed):
     """(Re)seed the generator."""
     self.digest_size = 64
     self.update(words2bytes(self.tf.key) + seed)
     self.tf.key = bytes2words(self.final())