---
name: "ne_mknonce"
section: "3"
platform: "linux"
package: "neon"
version: "0.37.1-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/ne_mknonce"
---

# ne\_mknonce(3)

generate a nonce

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