libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
Mnemonic Key Generation

Functions

LWS_VISIBLE LWS_EXTERN int lws_mnemonic_generate (struct lws_context *ctx, const uint8_t *entropy, char *dest, size_t dest_len)
 
LWS_VISIBLE LWS_EXTERN int lws_mnemonic_to_entropy (struct lws_context *ctx, const char *src, uint8_t *dest)
 

Detailed Description

Mnemonic Key Generation

Lws provides an API to convert 128-bit entropy (e.g. AES-128 keys) to and from a 12-word English mnemonic phrase following the BIP-39 standard.

This is useful for providing a human-readable/writable backup of a key.

Function Documentation

◆ lws_mnemonic_generate()

LWS_VISIBLE LWS_EXTERN int lws_mnemonic_generate ( struct lws_context * ctx,
const uint8_t * entropy,
char * dest,
size_t dest_len )

#include <include/libwebsockets/lws-mnemonic.h>

lws_mnemonic_generate() - Generate a mnemonic phrase from entropy

Parameters
ctxlws_context (used for random if needed, or SHA256)
entropy16 bytes of entropy (e.g. an AES-128 key)
destbuffer to receive the NUL-terminated mnemonic string
dest_lensize of the dest buffer (should be at least 128 bytes)

Converts 128 bits of entropy into a 12-word mnemonic phrase. Returns 0 on success, or non-zero on error.

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_mnemonic_to_entropy()

LWS_VISIBLE LWS_EXTERN int lws_mnemonic_to_entropy ( struct lws_context * ctx,
const char * src,
uint8_t * dest )

#include <include/libwebsockets/lws-mnemonic.h>

lws_mnemonic_to_entropy() - Recover entropy from a mnemonic phrase

Parameters
ctxlws_context (used for SHA256)
srcthe mnemonic phrase (12 words separated by single spaces)
dest16-byte buffer to receive the recovered entropy

Converts a 12-word mnemonic phrase back into 128 bits of entropy. Validates the BIP-39 checksum. Returns 0 on success, or non-zero if the phrase is invalid or checksum fails.