struct maid_rng_def
Type that defines a RNG algorithm
maid_rng
Opaque type that contains the state of a RNG
maid_rng *maid_rng_new(struct maid_rng_def def,
const u8 *entropy)
Creates a RNG instance
name |
description |
def |
Algorithm definition |
entropy |
Algorithm-dependent |
case |
description |
Success |
maid_rng instance |
Failure |
NULL |
maid_rng *maid_rng_del(maid_rng *g)
Deletes a RNG instance
name |
description |
g |
maid_rng instance |
case |
description |
Always |
NULL |
void maid_rng_renew(maid_rng *g, const u8 *entropy)
Recreates a RNG instance
name |
description |
g |
maid_rng instance |
entropy |
Algorithm-dependent |
void maid_rng_generate(maid_rng *g, u8 *buffer,
size_t size)
Generates pseudorandom bytes
name |
description |
g |
maid_rng instance |
buffer |
Memory to be written on |
size |
Size of the operation |
const struct maid_rng_def maid_ctr_drbg_aes_128
CTR-DRBG with AES-128 (NIST)
name |
description |
entropy |
32 bytes |
const struct maid_rng_def maid_ctr_drbg_aes_192
CTR-DRBG with AES-192 (NIST)
name |
description |
entropy |
40 bytes |
const struct maid_rng_def maid_ctr_drbg_aes_256
CTR-DRBG with AES-256 (NIST)
name |
description |
entropy |
48 bytes |
#include <stdio.h>
#include <stdlib.h>
#include <maid/rng.h>
int main(void)
{
u8 entropy[32] = {0xc2, 0xae, 0x5a, 0x05, 0x39, 0x3a, 0x57, 0xf6,
0x2b, 0xa3, 0xc2, 0xec, 0x80, 0x4a, 0x23, 0xda,
0x37, 0x81, 0xa6, 0xa0, 0x94, 0x4a, 0xe7, 0xbf,
0xd4, 0xe5, 0xda, 0xc9, 0x29, 0x14, 0x83, 0x65};
maid_rng *g = maid_rng_new(maid_ctr_drbg_aes_128, entropy);
u8 data[64] = {0};
if (g)
maid_rng_generate(g, data, sizeof(data));
maid_rng_del(g);
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: