Пример #1
0
 def __init__(self, data=None):
     state = VoidPointer()
     result = _raw_keccak_lib.keccak_init(state.address_of(), c_size_t(64), 0x1F)
     if result:
         raise ValueError("Error %d while instantiating SHAKE256" % result)
     self._state = SmartPointer(state.get(), _raw_keccak_lib.keccak_destroy)
     self._is_squeezing = False
     if data:
         self.update(data)
Пример #2
0
 def __init__(self, data=None):
     state = VoidPointer()
     result = _raw_keccak_lib.keccak_init(state.address_of(), c_size_t(32),
                                          0x1F)
     if result:
         raise ValueError("Error %d while instantiating SHAKE128" % result)
     self._state = SmartPointer(state.get(), _raw_keccak_lib.keccak_destroy)
     self._is_squeezing = False
     if data:
         self.update(data)
Пример #3
0
    def __init__(self, data, update_after_digest):
        self._update_after_digest = update_after_digest
        self._digest_done = False

        state = VoidPointer()
        result = _raw_keccak_lib.keccak_init(state.address_of(),
                                             c_size_t(self.digest_size * 2),
                                             0x06)
        if result:
            raise ValueError("Error %d while instantiating SHA-3/384" % result)
        self._state = SmartPointer(state.get(), _raw_keccak_lib.keccak_destroy)
        if data:
            self.update(data)
Пример #4
0
    def __init__(self, data, update_after_digest):
        self._update_after_digest = update_after_digest
        self._digest_done = False

        state = VoidPointer()
        result = _raw_keccak_lib.keccak_init(state.address_of(),
                                             c_size_t(self.digest_size * 2),
                                             0x06)
        if result:
            raise ValueError("Error %d while instantiating SHA-3/384"
                             % result)
        self._state = SmartPointer(state.get(),
                                   _raw_keccak_lib.keccak_destroy)
        if data:
            self.update(data)
Пример #5
0
    def __init__(self, data, custom, capacity, function):
        state = VoidPointer()

        if custom or function:
            prefix_unpad = _encode_str(function) + _encode_str(custom)
            prefix = _bytepad(prefix_unpad, (1600 - capacity) // 8)
            self._padding = 0x04
        else:
            prefix = None
            self._padding = 0x1F  # for SHAKE

        result = _raw_keccak_lib.keccak_init(state.address_of(),
                                             c_size_t(capacity // 8),
                                             c_ubyte(24))
        if result:
            raise ValueError("Error %d while instantiating cSHAKE" % result)
        self._state = SmartPointer(state.get(), _raw_keccak_lib.keccak_destroy)
        self._is_squeezing = False

        if prefix:
            self.update(prefix)

        if data:
            self.update(data)