Skip to content

File syn_aes128.c

FileList > src > syntropic > util > syn_aes128.c

Go to the source code of this file

AES-128 implementation (S-Box, Key Expansion, ECB, CBC mode).

  • #include "syn_aes128.h"
  • #include "syn_assert.h"
  • #include <string.h>

Public Static Attributes

Type Name
const uint8_t rcon = {0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36}
const uint8_t rsbox = /* multi line expression */
const uint8_t sbox = /* multi line expression */

Public Functions

Type Name
SYN_Status syn_aes128_cbc_decrypt (const SYN_AES128_Context * ctx, const uint8_t iv, const uint8_t * in, size_t in_len, uint8_t * out, size_t out_capacity, size_t * out_len)
Decrypt data using AES-128-CBC with PKCS#7 padding removal.
SYN_Status syn_aes128_cbc_encrypt (const SYN_AES128_Context * ctx, const uint8_t iv, const uint8_t * in, size_t in_len, uint8_t * out, size_t out_capacity, size_t * out_len)
Encrypt data using AES-128-CBC with PKCS#7 padding.
void syn_aes128_decrypt_block (const SYN_AES128_Context * ctx, const uint8_t in, uint8_t out)
Decrypt a single 16-byte block (ECB mode).
void syn_aes128_encrypt_block (const SYN_AES128_Context * ctx, const uint8_t in, uint8_t out)
Encrypt a single 16-byte block (ECB mode).
SYN_Status syn_aes128_init (SYN_AES128_Context * ctx, const uint8_t key)
Initialize AES-128 context and expand 128-bit key.

Public Static Functions

Type Name
uint8_t gmult (uint8_t a, uint8_t b)
uint8_t gmult2 (uint8_t a)

Public Static Attributes Documentation

variable rcon

const uint8_t rcon[11];

variable rsbox

const uint8_t rsbox[256];

variable sbox

const uint8_t sbox[256];

Public Functions Documentation

function syn_aes128_cbc_decrypt

Decrypt data using AES-128-CBC with PKCS#7 padding removal.

SYN_Status syn_aes128_cbc_decrypt (
    const SYN_AES128_Context * ctx,
    const uint8_t iv,
    const uint8_t * in,
    size_t in_len,
    uint8_t * out,
    size_t out_capacity,
    size_t * out_len
) 

Parameters:

  • ctx Initialized AES-128 context.
  • iv 16-byte initialization vector.
  • in Ciphertext buffer (multiple of 16 bytes).
  • in_len Ciphertext length in bytes.
  • out Plaintext output buffer.
  • out_capacity Output buffer size.
  • out_len Decrypted plaintext byte count written.

Returns:

SYN_OK on success, or SYN_INVALID_PARAM on invalid padding.


function syn_aes128_cbc_encrypt

Encrypt data using AES-128-CBC with PKCS#7 padding.

SYN_Status syn_aes128_cbc_encrypt (
    const SYN_AES128_Context * ctx,
    const uint8_t iv,
    const uint8_t * in,
    size_t in_len,
    uint8_t * out,
    size_t out_capacity,
    size_t * out_len
) 

Parameters:

  • ctx Initialized AES-128 context.
  • iv 16-byte initialization vector.
  • in Plaintext buffer.
  • in_len Plaintext length in bytes.
  • out Ciphertext buffer (must be large enough for in_len + PKCS7 padding).
  • out_capacity Maximum size of output buffer.
  • out_len Output byte count written.

Returns:

SYN_OK on success.


function syn_aes128_decrypt_block

Decrypt a single 16-byte block (ECB mode).

void syn_aes128_decrypt_block (
    const SYN_AES128_Context * ctx,
    const uint8_t in,
    uint8_t out
) 

Parameters:

  • ctx Initialized AES-128 context.
  • in 16-byte ciphertext block.
  • out 16-byte plaintext block.

function syn_aes128_encrypt_block

Encrypt a single 16-byte block (ECB mode).

void syn_aes128_encrypt_block (
    const SYN_AES128_Context * ctx,
    const uint8_t in,
    uint8_t out
) 

Parameters:

  • ctx Initialized AES-128 context.
  • in 16-byte plaintext block.
  • out 16-byte ciphertext block.

function syn_aes128_init

Initialize AES-128 context and expand 128-bit key.

SYN_Status syn_aes128_init (
    SYN_AES128_Context * ctx,
    const uint8_t key
) 

Parameters:

  • ctx AES-128 context instance.
  • key 16-byte key buffer.

Returns:

SYN_OK on success.


Public Static Functions Documentation

function gmult

static inline uint8_t gmult (
    uint8_t a,
    uint8_t b
) 

function gmult2

static inline uint8_t gmult2 (
    uint8_t a
) 


The documentation for this class was generated from the following file src/syntropic/util/syn_aes128.c