示例#1
0
 def _decrypt(self, crypttext, IV, readkey):
     self._status.set_status("decrypting")
     started = time.time()
     key = hashutil.ssk_readkey_data_hash(IV, readkey)
     decryptor = AES(key)
     plaintext = decryptor.process(crypttext)
     self._status.timings["decrypt"] = time.time() - started
     return plaintext
示例#2
0
 def _decrypt(self, crypttext, IV, readkey):
     self._status.set_status("decrypting")
     started = time.time()
     key = hashutil.ssk_readkey_data_hash(IV, readkey)
     decryptor = AES(key)
     plaintext = decryptor.process(crypttext)
     self._status.timings["decrypt"] = time.time() - started
     return plaintext
示例#3
0
 def _decrypt_segment(self, segment_and_salt):
     """
     I take a single segment and its salt, and decrypt it. I return
     the plaintext of the segment that is in my argument.
     """
     segment, salt = segment_and_salt
     self._set_current_status("decrypting")
     self.log("decrypting segment %d" % self._current_segment)
     started = time.time()
     key = hashutil.ssk_readkey_data_hash(salt, self._node.get_readkey())
     decryptor = AES(key)
     plaintext = decryptor.process(segment)
     self._status.accumulate_decrypt_time(time.time() - started)
     return plaintext
示例#4
0
 def _decrypt_segment(self, segment_and_salt):
     """
     I take a single segment and its salt, and decrypt it. I return
     the plaintext of the segment that is in my argument.
     """
     segment, salt = segment_and_salt
     self._set_current_status("decrypting")
     self.log("decrypting segment %d" % self._current_segment)
     started = time.time()
     key = hashutil.ssk_readkey_data_hash(salt, self._node.get_readkey())
     decryptor = AES(key)
     plaintext = decryptor.process(segment)
     self._status.accumulate_decrypt_time(time.time() - started)
     return plaintext
示例#5
0
    def _encrypt_and_encode(self):
        # this returns a Deferred that fires with a list of (sharedata,
        # sharenum) tuples. TODO: cache the ciphertext, only produce the
        # shares that we care about.
        self.log("_encrypt_and_encode")

        self._status.set_status("Encrypting")
        started = time.time()

        key = hashutil.ssk_readkey_data_hash(self.salt, self.readkey)
        enc = AES(key)
        crypttext = enc.process(self.newdata)
        assert len(crypttext) == len(self.newdata)

        now = time.time()
        self._status.timings["encrypt"] = now - started
        started = now

        # now apply FEC

        self._status.set_status("Encoding")
        fec = codec.CRSEncoder()
        fec.set_params(self.segment_size, self.required_shares,
                       self.total_shares)
        piece_size = fec.get_block_size()
        crypttext_pieces = [None] * self.required_shares
        for i in range(len(crypttext_pieces)):
            offset = i * piece_size
            piece = crypttext[offset:offset + piece_size]
            piece = piece + "\x00" * (piece_size - len(piece))  # padding
            crypttext_pieces[i] = piece
            assert len(piece) == piece_size

        d = fec.encode(crypttext_pieces)

        def _done_encoding(res):
            elapsed = time.time() - started
            self._status.timings["encode"] = elapsed
            return res

        d.addCallback(_done_encoding)
        return d
示例#6
0
    def _encrypt_and_encode(self):
        # this returns a Deferred that fires with a list of (sharedata,
        # sharenum) tuples. TODO: cache the ciphertext, only produce the
        # shares that we care about.
        self.log("_encrypt_and_encode")

        self._status.set_status("Encrypting")
        started = time.time()

        key = hashutil.ssk_readkey_data_hash(self.salt, self.readkey)
        enc = AES(key)
        crypttext = enc.process(self.newdata)
        assert len(crypttext) == len(self.newdata)

        now = time.time()
        self._status.timings["encrypt"] = now - started
        started = now

        # now apply FEC

        self._status.set_status("Encoding")
        fec = codec.CRSEncoder()
        fec.set_params(self.segment_size,
                       self.required_shares, self.total_shares)
        piece_size = fec.get_block_size()
        crypttext_pieces = [None] * self.required_shares
        for i in range(len(crypttext_pieces)):
            offset = i * piece_size
            piece = crypttext[offset:offset+piece_size]
            piece = piece + "\x00"*(piece_size - len(piece)) # padding
            crypttext_pieces[i] = piece
            assert len(piece) == piece_size

        d = fec.encode(crypttext_pieces)
        def _done_encoding(res):
            elapsed = time.time() - started
            self._status.timings["encode"] = elapsed
            return res
        d.addCallback(_done_encoding)
        return d