NE_MKNONCE(3)

NAME
ne_mknonce - generate a nonce

SYNOPSIS

#include <ne_string.h>

int ne_mknonce(unsigned char *nonce, size_t len, unsigned int flags);

DESCRIPTION

ne_mknonce fills the buffer pointed to by nonce with len bytes of random data suitable for use as a nonce. The value of len must be greater than zero and no greater than 256.

The flags parameter is reserved for future use and must be set to zero.

The caller is responsible for ensuring that the buffer pointed to by nonce is at least len bytes in size.

RETURN VALUE

ne_mknonce returns zero on success. On error, a non-zero errno value is returned indicating the cause of the failure; the buffer contents are undefined.

EXAMPLE

The following example generates a 16-byte nonce and encodes it as a hexadecimal string.

    unsigned char buf[16];
    unsigned char hex[33];
    int i, err;

    err = ne_mknonce(buf, sizeof buf, 0);
    if (err) {
        fprintf(stderr, "ne_mknonce failed: %s\n", strerror(err));
        return -1;
    }

    for (i = 0; i < 16; i++)
        sprintf(hex + 2 * i, "%02x", buf[i]);
    hex[32] = '\0';

HISTORY

ne_mknonce is available in neon 0.37.0 and later.

COPYRIGHT
Copyright © 2001-2026 Joe Orton