ne_mknonce(3)

ne_mknonce3

Generate a nonce

Usage

#include <ne_string.h>

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

Overview

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.

Examples

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.

From neon 0.37.1-1 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.