def sign(self, message): message = mac_pad(message, self.BLOCK_SIZE) tag = b'\x00' * self.BLOCK_SIZE for block in get_blocks(message, self.BLOCK_SIZE): tag = self.cipher1.encrypt(xor(block, tag)) return self.cipher2.encrypt(tag)
def sign(self, message): last_block_key = self.k2 if len(message) % self.BLOCK_SIZE == 0 else self.k1 if last_block_key == self.k1: message = mac_pad(message, self.BLOCK_SIZE) tag = b'\x00' * self.BLOCK_SIZE for block in get_blocks(message[:-self.BLOCK_SIZE], self.BLOCK_SIZE): tag = self.cipher.encrypt(xor(block, tag)) last_block = message[-self.BLOCK_SIZE:] return self.cipher.encrypt(xor(last_block_key, xor(last_block, tag)))