struct maid_block_def
Type that defines a block cipher algorithm
maid_block
Opaque type that contains the state of a block cipher
maid_block *maid_block_new(struct maid_block_def def,
const u8 *restrict key,
const u8 *restrict iv)
Creates a block cipher instance
name |
description |
def |
Algorithm definition |
key |
Algorithm-dependent |
iv |
Algorithm-dependent |
case |
description |
Success |
maid_block instance |
Failure |
NULL |
maid_block *maid_block_del(maid_block *bl)
Deletes a block cipher instance
name |
description |
bl |
maid_block instance |
case |
description |
Always |
NULL |
void maid_block_renew(maid_block *bl,const u8 *restrict key,
const u8 *restrict iv)
Recreates a block cipher instance
name |
description |
bl |
maid_block instance |
key |
Algorithm-dependent |
iv |
Algorithm-dependent |
void maid_block_ecb(maid_block *bl,
u8 *buffer, bool decrypt)
Applies ECB mode (doesn't change the iv)
name |
description |
bl |
maid_block instance |
buffer |
Block to be ciphered |
decrypt |
Encrypt/Decrypt operation |
void maid_block_ctr(maid_block *bl,
u8 *buffer, size_t size)
Applies CTR mode (increases iv accordingly)
name |
description |
bl |
maid_block instance |
buffer |
Memory to be ciphered |
size |
Size of the operation |
const struct maid_block_def maid_aes_128
AES-128 block cipher (NIST)
name |
description |
key |
128-bit key |
iv |
128-bit iv |
const struct maid_block_def maid_aes_192
AES-192 block cipher (NIST)
name |
description |
key |
192-bit key |
iv |
128-bit iv |
const struct maid_block_def maid_aes_256
AES-256 block cipher (NIST)
name |
description |
key |
256-bit key |
iv |
128-bit iv |
#include <stdio.h>
#include <stdlib.h>
#include <maid/block.h>
int main(void)
{
u8 key[32] = {0};
u8 iv [16] = {0};
maid_block *bl = maid_block_new(maid_aes_256, key, iv);
u8 data[64] = {0};
if (bl)
maid_block_ctr(bl, data, sizeof(data));
maid_block_del(bl);
for (size_t i = 0; i < sizeof(data); i++)
printf("%02x", data[i]);
printf("\n");
return EXIT_SUCCESS;
}
Without installation:
cc -static -Iinclude example.c -Lbuild -lmaid
With installation: