.. index:: single: block_cipher_prepared_key_protocol
.. _block_cipher_prepared_key_protocol/0:

.. rst-class:: right

**protocol**

``block_cipher_prepared_key_protocol``
======================================

Protocol for block ciphers supporting opaque prepared keys for repeated block operations.

| **Availability:** 
|    ``logtalk_load(block_ciphers(loader))``

| **Author:** Paulo Moura
| **Version:** 1:0:0
| **Date:** 2026-08-08

| **Compilation flags:**
|    ``static``


| **Extends:**
|    ``public`` :ref:`block_cipher_protocol <block_cipher_protocol/0>`

| **Remarks:**
|    (none)

| **Inherited public predicates:**
|     :ref:`block_cipher_protocol/0::block_size/1`  :ref:`block_cipher_protocol/0::decrypt_block/3`  :ref:`block_cipher_protocol/0::encrypt_block/3`  :ref:`block_cipher_protocol/0::key_size/1`  

.. contents::
   :local:
   :backlinks: top

Public predicates
-----------------

.. index:: prepare_key/2
.. _block_cipher_prepared_key_protocol/0::prepare_key/2:

``prepare_key/2``
^^^^^^^^^^^^^^^^^

Validates and prepares a key for repeated block encryption or decryption.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``prepare_key(Key,PreparedKey)``
| **Mode and number of proofs:**
|    ``prepare_key(+list(byte),--compound)`` - ``one_or_error``

| **Exceptions:**
|    ``Key`` is a variable or a partial list:
|        ``instantiation_error``
|    ``Key`` is a list but not with the required number of bytes:
|        ``type_error(list(byte,KeySize),Key)``
|    ``Key`` contains a non-integer byte:
|        ``type_error(integer,Byte)``
|    ``Key`` contains an integer outside the byte range:
|        ``domain_error(byte,Byte)``


------------

.. index:: encrypt_prepared_block/3
.. _block_cipher_prepared_key_protocol/0::encrypt_prepared_block/3:

``encrypt_prepared_block/3``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Encrypts a plaintext block using an opaque prepared key created by the same cipher object.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``encrypt_prepared_block(PreparedKey,PlaintextBlock,CiphertextBlock)``
| **Mode and number of proofs:**
|    ``encrypt_prepared_block(+compound,+list(byte),--list(byte))`` - ``one_or_error``

| **Exceptions:**
|    ``PreparedKey`` was not created by this cipher object:
|        ``domain_error(block_cipher_prepared_key,PreparedKey)``
|    ``PlaintextBlock`` is a variable or a partial list:
|        ``instantiation_error``
|    ``PlaintextBlock`` is not a list of the required number of bytes:
|        ``type_error(list(byte,BlockSize),PlaintextBlock)``
|    ``PlaintextBlock`` contains a non-integer byte:
|        ``type_error(integer,Byte)``
|    ``PlaintextBlock`` contains an integer outside the byte range:
|        ``domain_error(byte,Byte)``


------------

.. index:: decrypt_prepared_block/3
.. _block_cipher_prepared_key_protocol/0::decrypt_prepared_block/3:

``decrypt_prepared_block/3``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Decrypts a ciphertext block using an opaque prepared key created by the same cipher object.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``decrypt_prepared_block(PreparedKey,CiphertextBlock,PlaintextBlock)``
| **Mode and number of proofs:**
|    ``decrypt_prepared_block(+compound,+list(byte),--list(byte))`` - ``one_or_error``

| **Exceptions:**
|    ``PreparedKey`` was not created by this cipher object:
|        ``domain_error(block_cipher_prepared_key,PreparedKey)``
|    ``CiphertextBlock`` is a variable or a partial list:
|        ``instantiation_error``
|    ``CiphertextBlock`` is not a list of the required number of bytes:
|        ``type_error(list(byte,BlockSize),CiphertextBlock)``
|    ``CiphertextBlock`` contains a non-integer byte:
|        ``type_error(integer,Byte)``
|    ``CiphertextBlock`` contains an integer outside the byte range:
|        ``domain_error(byte,Byte)``


------------

Protected predicates
--------------------

(no local declarations; see entity ancestors if any)

Private predicates
------------------

(no local declarations; see entity ancestors if any)

Operators
---------

(none)

