struct maid_stream_def
Type that defines a stream cipher algorithm
maid_stream
Opaque type that contains the state of a stream cipher
maid_stream *maid_stream_new(struct maid_stream_def def,
const u8 *restrict key,
const u8 *restrict nonce,
u64 counter)
Creates a stream cipher instance
name |
description |
def |
Algorithm definition |
key |
Algorithm-dependent |
nonce |
Algorithm-dependent |
counter |
Algorithm-dependent |
case |
description |
Success |
maid_stream instance |
Failure |
NULL |
maid_stream *maid_stream_del(maid_stream *st)
Deletes a stream cipher instance
name |
description |
st |
maid_stream instance |
case |
description |
Always |
NULL |
void maid_stream_renew(maid_stream *st, const u8 *restrict key,
const u8 *restrict nonce,
u64 counter)
Recreates a stream cipher instance
name |
description |
st |
maid_stream instance |
key |
Algorithm-dependent |
nonce |
Algorithm-dependent |
counter |
Algorithm-dependent |
void maid_stream_xor(maid_stream *st,
u8 *buffer, size_t size)
Generates keystream, and applies it with a xor operation
name |
description |
st |
maid_stream instance |
buffer |
Memory to be ciphered |
size |
Size of the operation |
const struct maid_stream_def maid_chacha20
Chacha20 stream cipher (IETF version)
name |
description |
key |
256-bit key |
nonce |
96-bit nonce |
counter |
0 to 2^32 |
#include <stdio.h>
#include <stdlib.h>
#include <maid/stream.h>
int main(void)
{
u8 key[32] = {0};
u8 iv [16] = {0};
maid_stream *st = maid_stream_new(maid_chacha20, key, iv, 0);
u8 data[64] = {0};
if (st)
maid_stream_xor(st, data, sizeof(data));
maid_stream_del(st);
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: