AES ECB APIs - zpc/aes_ecb.h

libzpc provides APIs for processing Advanced Encryption Standard (AES) block cipher in Electronic Code Book (ECB) mode of operation.

Data structures

The context of an AES-ECB operation is opaque for an application and is stored in objects of type
struct zpc_aes_ecb;
Context objects must not be shared among multiple threads. They may be used for multiple operations by setting or resetting the key or initialization vector.

zpc_aes_ecb_alloc

Purpose: Allocate a new context object for an AES-ECB operation.

Format:

int zpc_aes_ecb_alloc ( 
    struct zpc_aes_ecb **ctx );

Parameters:

Direction Name Description
output ctx Pointer to an AES-ECB context object

Return codes:

0 on success. Otherwise, a non-zero error code is returned.

zpc_aes_ecb_decrypt

Purpose: Decrypt a ciphertext using AES-ECB to obtain the corresponding plaintext.

The ciphertext buffer length must be a multiple of 16 bytes.

The plaintext buffer must be large enough to store the resulting plaintext which has the same length as the ciphertext. The application must remove any padding from the plaintext.

Plaintext and ciphertext buffer may be equal such that the operation is done in-place. If the operation is not done in-place, plaintext and ciphertext buffers must not overlap.

A ciphertext may be decrypted chunk-wise. For every operation on a ciphertext chunk, the same rules apply as for the one-shot decryption. In particular, each chunk's length must be a multiple of 16 bytes. The same context object must be used to decrypt all chunks without modifying it between operations.

Format:

int zpc_aes_ecb_decrypt (
    struct zpc_aes_ecb *ctx,
    unsigned char *pt,
    const unsigned char *ct,
    size_t ctlen );

Parameters:

Direction Name Description
input, output ctx Pointer to an AES-ECB context object
output pt Pointer to the plaintext buffer
input ct Pointer to the ciphertext buffer
input ctlen Ciphertext length [bytes]

Return codes:

0 on success. Otherwise, a non-zero error code is returned.

zpc_aes_ecb_encrypt

Purpose: Encrypt a plaintext using AES-ECB to obtain the corresponding ciphertext.

The plaintext buffer length must be a multiple of 16 bytes. The application must care for padding the plaintext appropriately.

The ciphertext buffer must be large enough to store the resulting ciphertext which has the same length as the (padded) plaintext.

Plaintext and ciphertext buffer may be equal such that the operation is done in-place. If the operation is not done in-place, plaintext and ciphertext buffers must not overlap.

A plaintext may be encrypted chunk-wise. For every operation on a plaintext chunk, the same rules apply as for the one-shot encryption. In particular, each chunk's length must be a multiple of 16 bytes. The same context object must be used to encrypt all chunks without modifying it in between operations.

Format:

int zpc_aes_ecb_encrypt (
    struct zpc_aes_ecb *ctx,
    unsigned char *ct,
    const unsigned char *pt,
    size_t ptlen );

Parameters:

Direction Name Description
input, output ctx Pointer to an AES-ECB context object
output ct Pointer to the ciphertext buffer
input pt Pointer to the plaintext buffer
input ptlen Plaintext length [bytes]

Return codes:

0 on success. Otherwise, a non-zero error code is returned.

zpc_aes_ecb_free

Purpose: Free an AES-ECB context object.

If a key is set, the reference count of that key object is decremented. The context object argument is set to NULL.

Format:

void zpc_aes_ecb_free (
     struct zpc_aes_ecb **ctx );

Parameters:

Direction Name Description
input, output ctx Pointer to an AES-ECB context object

zpc_aes_ecb_set_key

Purpose: Set the key to be used in the context of an AES-ECB operation.

If a key is already set, the reference count of that key object is decremented. The context's key reference is set to the key object argument. If the key object argument is not NULL, the reference count of that key object is incremented.

Format:

int zpc_aes_ecb_set_key (
    struct zpc_aes_ecb *ctx,
    struct zpc_aes_key *key );

Parameters:

Direction Name Description
input, output ctx Pointer to an AES-ECB context object
input key Pointer to an AES key object

Return codes:

0 on success. Otherwise, a non-zero error code is returned.