ne_mknonce
Prev | neon API reference | Next

## 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.

Prev | Up | Next
ne_strhash | Home | ne_strparam