iota/crypto/pycurl.py
def squeeze(self, trits, offset=0, length=HASH_LENGTH):
        # type: (MutableSequence[int], Optional[int], Optional[int]) -> None
        """
        Squeeze trits from the sponge.

        :param trits:
            Sequence that the squeezed trits will be copied to.
            Note: this object will be modified!

        :param offset:
            Starting offset in ``trits``.

        :param length:
            Number of trits to squeeze, default to ``HASH_LENGTH``
        """
        # Squeeze is kind of like the opposite of absorb; it copies
        # trits from internal state to the ``trits`` parameter, one hash
        # at a time, and transforming internal state in between hashes.
        #
        # However, only the first hash of the state is "public", so we
        # can simplify the implementation somewhat.

        # Ensure length can be mod by HASH_LENGTH
        if length % HASH_LENGTH != 0:
            raise with_context(
                exc=ValueError('Invalid length passed to ``squeeze`.'),

                context={
                    'trits': trits,
                    'offset': offset,
                    'length': length,
                })

        # Ensure that ``trits`` can hold at least one hash worth of
        # trits.
        trits.extend([0] * max(0, length - len(trits)))

        # Check trits with offset can handle hash length
        if len(trits) - offset < HASH_LENGTH:
            raise with_context(
                exc=ValueError('Invalid offset passed to ``squeeze``.'),

                context={
                    'trits': trits,
                    'offset': offset,
                    'length': length
                },
            )

        while length >= HASH_LENGTH:
            # Copy exactly one hash.
            trits[offset:offset + HASH_LENGTH] = self._state[0:HASH_LENGTH]

            # One hash worth of trits copied; now transform.
            self._transform()

            offset += HASH_LENGTH
            length -= HASH_LENGTH
def squeeze(self, trits, offset=0, length=HASH_LENGTH):
        # type: (MutableSequence[int], Optional[int], Optional[int]) -> None
        # Squeeze is kind of like the opposite of absorb; it copies
        # trits from internal state to the ``trits`` parameter, one hash
        # at a time, and transforming internal state in between hashes.
        #
        # However, only the first hash of the state is "public", so we
        # can simplify the implementation somewhat.

        # Ensure length can be mod by HASH_LENGTH
        if length % HASH_LENGTH != 0:
            raise with_context(
                exc=ValueError('Invalid length passed to ``squeeze`.'),

                context={
                    'trits': trits,
                    'offset': offset,
                    'length': length,
                })

        # Ensure that ``trits`` can hold at least one hash worth of
        # trits.
        trits.extend([0] * max(0, length - len(trits)))

        # Check trits with offset can handle hash length
        if len(trits) - offset < HASH_LENGTH:
            raise with_context(
                exc=ValueError('Invalid offset passed to ``squeeze``.'),

                context={
                    'trits': trits,
                    'offset': offset,
                    'length': length
                },
            )

        while length >= HASH_LENGTH:
            # Copy exactly one hash.
            trits[offset:offset + HASH_LENGTH] = self._state[0:HASH_LENGTH]

            # One hash worth of trits copied; now transform.
            self._transform()

            offset += HASH_LENGTH
            length -= HASH_LENGTH
def squeeze ( self , trits , offset = 0 , length = HASH_LENGTH ) : # type: (MutableSequence[int], Optional[int], Optional[int]) -> None # Squeeze is kind of like the opposite of absorb; it copies # trits from internal state to the ``trits`` parameter, one hash # at a time, and transforming internal state in between hashes. # # However, only the first hash of the state is "public", so we # can simplify the implementation somewhat. # Ensure length can be mod by HASH_LENGTH if length % HASH_LENGTH != 0 : raise with_context ( exc = ValueError ( 'Invalid length passed to ``squeeze`.' ) , context = { 'trits' : trits , 'offset' : offset , 'length' : length , } ) # Ensure that ``trits`` can hold at least one hash worth of # trits. trits . extend ( [ 0 ] * max ( 0 , length - len ( trits ) ) ) # Check trits with offset can handle hash length if len ( trits ) - offset < HASH_LENGTH : raise with_context ( exc = ValueError ( 'Invalid offset passed to ``squeeze``.' ) , context = { 'trits' : trits , 'offset' : offset , 'length' : length } , ) while length >= HASH_LENGTH : # Copy exactly one hash. trits [ offset : offset + HASH_LENGTH ] = self . _state [ 0 : HASH_LENGTH ] # One hash worth of trits copied; now transform. self . _transform ( ) offset += HASH_LENGTH length -= HASH_LENGTH
Squeeze trits from the sponge.

        :param trits:
            Sequence that the squeezed trits will be copied to.
            Note: this object will be modified!

        :param offset:
            Starting offset in ``trits``.

        :param length:
            Number of trits to squeeze, default to ``HASH_LENGTH``
Squeeze trits from the sponge .