Skip to content

wc_lms.h

Functions

Name
int wc_LmsKey_Init(LmsKey * key, void * heap, int devId)
Initializes an LmsKey object. Must be called before any other LMS/HSS operation. Use wc_LmsKey_Free() to release resources when done.
int wc_LmsKey_InitId(LmsKey * key, const unsigned char * id, int len, void * heap, int devId)
Initializes an LmsKey with a device_side key identifier. Equivalent to wc_LmsKey_Init() but also stashes a binary id that a crypto callback can use to look up the underlying key material on the device. Only available when wolfSSL is built with WOLF_PRIVATE_KEY_ID.
int wc_LmsKey_InitLabel(LmsKey * key, const char * label, void * heap, int devId)
Initializes an LmsKey with a device_side key label. Equivalent to wc_LmsKey_Init() but also stashes a label string that a crypto callback can use to look up the underlying key material on the device. Only available when wolfSSL is built with WOLF_PRIVATE_KEY_ID.
int wc_LmsKey_SetLmsParm(LmsKey * key, enum wc_LmsParm lmsParm)
Selects a predefined LMS/HSS parameter set by name. The enum wc_LmsParm encodes the tree depth (levels), per-tree height, Winternitz parameter and hash family in a single value. See the wc_LmsParm definition for the list of names available in a given build.
int wc_LmsKey_SetParameters(LmsKey * key, int levels, int height, int winternitz)
Sets the LMS/HSS parameters individually. The default SHA_256/256 hash is used. For finer control over the hash family use wc_LmsKey_SetParameters_ex().
int wc_LmsKey_SetParameters_ex(LmsKey * key, int levels, int height, int winternitz, int hash)
Sets the LMS/HSS parameters individually with an explicit hash family selector.
int wc_LmsKey_GetParameters(const LmsKey * key, int * levels, int * height, int * winternitz)
Retrieves the LMS/HSS parameters previously set on this key.
int wc_LmsKey_GetParameters_ex(const LmsKey * key, int * levels, int * height, int * winternitz, int * hash)
Retrieves the LMS/HSS parameters and hash family selector from this key.
int wc_LmsKey_SetWriteCb(LmsKey * key, wc_lms_write_private_key_cb write_cb)
Registers the callback that wolfSSL invokes to persist updated private key state. Because LMS/HSS is stateful, the application MUST persist the private key after each successful sign before the signature is released to a peer; otherwise a crash or restart can lead to one-time key reuse and break the scheme.
int wc_LmsKey_SetReadCb(LmsKey * key, wc_lms_read_private_key_cb read_cb)
Registers the callback that wolfSSL invokes to load persisted private key state. Used by wc_LmsKey_Reload() to bring a saved key back into memory for further signing.
int wc_LmsKey_SetContext(LmsKey * key, void * context)
Sets the opaque context pointer passed to both the read and write private-key callbacks. Typically used to carry a file handle, database connection, or other persistence-layer state.
int wc_LmsKey_MakeKey(LmsKey * key, WC_RNG * rng)
Generates a fresh LMS/HSS key pair. Parameters must already be set (via wc_LmsKey_SetLmsParm() or wc_LmsKey_SetParameters()) and read/write callbacks must be registered. The newly generated private key is persisted via the write callback before the function returns; on success the key transitions to state WC_LMS_STATE_OK.
int wc_LmsKey_Reload(LmsKey * key)
Reloads a previously generated LMS/HSS private key from persistent storage using the registered read callback, restoring the key to a state where it can sign further messages. On success the key is in state WC_LMS_STATE_OK.
int wc_LmsKey_GetPrivLen(const LmsKey * key, word32 * len)
Returns the size in bytes of the encoded private key for the parameter set selected on this key.
int wc_LmsKey_GetPubLen(const LmsKey * key, word32 * len)
Returns the size in bytes of the LMS/HSS public key for the parameter set selected on this key.
int wc_LmsKey_GetSigLen(const LmsKey * key, word32 * len)
Returns the LMS/HSS signature size in bytes for the parameter set selected on this key.
int wc_LmsKey_Sign(LmsKey * key, byte * sig, word32 * sigSz, const byte * msg, int msgSz)
Signs msg with the LMS/HSS private key in key. On entry sigSz is the size of the sig buffer; on success it is updated to the bytes written.
int wc_LmsKey_SigsLeft(LmsKey * key)
Returns the number of one-time signatures still available from this key. When the count reaches zero the key can no longer sign and should be retired.
void wc_LmsKey_Free(LmsKey * key)
Releases resources held by an LmsKey. Safe to call with a NULL pointer. After this call the key is in state WC_LMS_STATE_FREED and must be re-initialized before reuse.
int wc_LmsKey_ExportPub(LmsKey * keyDst, const LmsKey * keySrc)
Copies the public part of keySrc into keyDst. The destination key inherits the same parameters and may be used for verification; it does not carry the private key state and cannot sign. Useful for handing a verifier the minimal data it needs.
int wc_LmsKey_ExportPub_ex(LmsKey * keyDst, const LmsKey * keySrc, void * heap, int devId)
Like wc_LmsKey_ExportPub() but the destination key is initialized fresh with the supplied heap and devId.
int wc_LmsKey_ExportPubRaw(const LmsKey * key, byte * out, word32 * outLen)
Exports the LMS/HSS public key as a raw byte string. On entry *outLen is the size of out; on success it is updated to the bytes written.
int wc_LmsKey_ImportPubRaw(LmsKey * key, const byte * in, word32 inLen)
Imports a raw LMS/HSS public key into key. The key must be in state WC_LMS_STATE_INITED. Parameter information is recovered from the encoded header, after which the key transitions to state WC_LMS_STATE_VERIFYONLY.
int wc_LmsKey_Verify(LmsKey * key, const byte * sig, word32 sigSz, const byte * msg, int msgSz)
Verifies an LMS/HSS signature against msg using the public key held in key. The function returns 0 only when the signature is valid; any other value indicates the signature was rejected.
const char * wc_LmsKey_ParmToStr(enum wc_LmsParm lmsParm)
Returns a static, NUL-terminated string describing an LMS parameter set. Useful for logging and diagnostics.
int wc_LmsKey_GetKid(LmsKey * key, const byte ** kid, word32 * kidSz)
Returns a pointer to the 16_byte LMS Key Identifier (I) embedded in the private key, together with its length. The returned pointer aliases internal key memory and is valid only until the key is freed.
const byte * wc_LmsKey_GetKidFromPrivRaw(const byte * priv, word32 privSz)
Returns a pointer to the LMS Key Identifier (I) within a raw encoded private key buffer, without requiring an LmsKey object. Used to look up the matching state record in persistent storage during reload.

Functions Documentation

function wc_LmsKey_Init

int wc_LmsKey_Init(
    LmsKey * key,
    void * heap,
    int devId
)

Initializes an LmsKey object. Must be called before any other LMS/HSS operation. Use wc_LmsKey_Free() to release resources when done.

Parameters:

  • key Pointer to the LmsKey to initialize.
  • heap Heap hint for dynamic memory allocation. May be NULL.
  • devId Device identifier for hardware crypto callbacks. Use INVALID_DEVID for software-only.

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if key is NULL.

LMS (Leighton-Micali Signatures) and the HSS multi-tree composition (RFC 8554, NIST SP 800-208) are STATEFUL hash-based signature schemes: each call to wc_LmsKey_Sign() consumes a one_time component of the private key, and reusing a one_time key breaks the security of the scheme. Applications MUST persist the private key state between sign calls; see wc_LmsKey_SetWriteCb() and wc_LmsKey_SetReadCb().

After init the key is in state WC_LMS_STATE_INITED. The parameters must be set with wc_LmsKey_SetLmsParm() or wc_LmsKey_SetParameters() before generating or reloading a key.

Example

LmsKey key;
int ret;

ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
if (ret != 0) {
    // error initializing key
}
wc_LmsKey_SetLmsParm(&key, WC_LMS_PARM_L2_H10_W8);
// ... use key ...
wc_LmsKey_Free(&key);

function wc_LmsKey_InitId

int wc_LmsKey_InitId(
    LmsKey * key,
    const unsigned char * id,
    int len,
    void * heap,
    int devId
)

Initializes an LmsKey with a device-side key identifier. Equivalent to wc_LmsKey_Init() but also stashes a binary id that a crypto callback can use to look up the underlying key material on the device. Only available when wolfSSL is built with WOLF_PRIVATE_KEY_ID.

Parameters:

  • key Pointer to the LmsKey to initialize.
  • id Pointer to the device-side key identifier bytes. May be NULL when len is 0.
  • len Number of bytes in id; must be in [0, LMS_MAX_ID_LEN].
  • heap Heap hint for dynamic memory allocation.
  • devId Device identifier for the crypto callback.

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if key is NULL, or id is NULL while len > 0.
  • BUFFER_E if len is negative or greater than LMS_MAX_ID_LEN.

The id is copied into the key object; the caller may free its buffer immediately after this call returns.

function wc_LmsKey_InitLabel

int wc_LmsKey_InitLabel(
    LmsKey * key,
    const char * label,
    void * heap,
    int devId
)

Initializes an LmsKey with a device-side key label. Equivalent to wc_LmsKey_Init() but also stashes a label string that a crypto callback can use to look up the underlying key material on the device. Only available when wolfSSL is built with WOLF_PRIVATE_KEY_ID.

Parameters:

  • key Pointer to the LmsKey to initialize.
  • label NUL-terminated device-side key label.
  • heap Heap hint for dynamic memory allocation.
  • devId Device identifier for the crypto callback.

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if key or label is NULL.
  • BUFFER_E if label is empty or longer than LMS_MAX_LABEL_LEN.

function wc_LmsKey_SetLmsParm

int wc_LmsKey_SetLmsParm(
    LmsKey * key,
    enum wc_LmsParm lmsParm
)

Selects a predefined LMS/HSS parameter set by name. The enum wc_LmsParm encodes the tree depth (levels), per-tree height, Winternitz parameter and hash family in a single value. See the wc_LmsParm definition for the list of names available in a given build.

Parameters:

  • key Pointer to an LmsKey in state WC_LMS_STATE_INITED.
  • lmsParm A wc_LmsParm constant (e.g. WC_LMS_PARM_L2_H10_W8).

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if key is NULL, or if lmsParm is not recognized or names a parameter set that was not compiled in.
  • BAD_STATE_E if key is not in state WC_LMS_STATE_INITED.

Example

LmsKey key;

wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
wc_LmsKey_SetLmsParm(&key, WC_LMS_PARM_L2_H10_W8);

function wc_LmsKey_SetParameters

int wc_LmsKey_SetParameters(
    LmsKey * key,
    int levels,
    int height,
    int winternitz
)

Sets the LMS/HSS parameters individually. The default SHA-256/256 hash is used. For finer control over the hash family use wc_LmsKey_SetParameters_ex().

Parameters:

  • key Pointer to an LmsKey in state WC_LMS_STATE_INITED.
  • levels Number of Merkle-tree levels in the HSS chain.
  • height Height of each individual Merkle tree.
  • winternitz Winternitz parameter (1, 2, 4 or 8).

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if key is NULL, or if the requested parameter combination is not supported in this build.
  • BAD_STATE_E if key is not in state WC_LMS_STATE_INITED.

The combination of parameters must match one of the allowed sets in RFC 8554:

  • levels: 1..8
  • height: 5, 10, 15, 20 (and 25 in some builds)
  • winternitz: 1, 2, 4, or 8

The maximum number of signatures available from a key is 2^(levels * height).

function wc_LmsKey_SetParameters_ex

int wc_LmsKey_SetParameters_ex(
    LmsKey * key,
    int levels,
    int height,
    int winternitz,
    int hash
)

Sets the LMS/HSS parameters individually with an explicit hash family selector.

Parameters:

  • key Pointer to an LmsKey in state WC_LMS_STATE_INITED.
  • levels Number of Merkle-tree levels.
  • height Height of each tree.
  • winternitz Winternitz parameter (1, 2, 4 or 8).
  • hash Hash family selector identifying SHA-256/256, SHA-256/192, SHAKE256/256 or SHAKE256/192, as supported by the build.

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if key is NULL, or if the requested parameter combination is not supported in this build.
  • BAD_STATE_E if key is not in state WC_LMS_STATE_INITED.

function wc_LmsKey_GetParameters

int wc_LmsKey_GetParameters(
    const LmsKey * key,
    int * levels,
    int * height,
    int * winternitz
)

Retrieves the LMS/HSS parameters previously set on this key.

Parameters:

  • key Pointer to an LmsKey with parameters set.
  • levels Receives the number of tree levels.
  • height Receives the per-tree height.
  • winternitz Receives the Winternitz parameter.

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if any pointer is NULL or no parameters are set.

function wc_LmsKey_GetParameters_ex

int wc_LmsKey_GetParameters_ex(
    const LmsKey * key,
    int * levels,
    int * height,
    int * winternitz,
    int * hash
)

Retrieves the LMS/HSS parameters and hash family selector from this key.

Parameters:

  • key Pointer to an LmsKey with parameters set.
  • levels Receives the number of tree levels.
  • height Receives the per-tree height.
  • winternitz Receives the Winternitz parameter.
  • hash Receives the hash family selector.

See: wc_LmsKey_SetParameters_ex

Return:

  • 0 on success.
  • BAD_FUNC_ARG if any pointer is NULL or no parameters are set.

function wc_LmsKey_SetWriteCb

int wc_LmsKey_SetWriteCb(
    LmsKey * key,
    wc_lms_write_private_key_cb write_cb
)

Registers the callback that wolfSSL invokes to persist updated private key state. Because LMS/HSS is stateful, the application MUST persist the private key after each successful sign before the signature is released to a peer; otherwise a crash or restart can lead to one-time key reuse and break the scheme.

Parameters:

  • key Pointer to an LmsKey.
  • write_cb Callback invoked to persist the private key.

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if key or write_cb is NULL.

The callback receives the encoded private key bytes and returns one of the wc_LmsRc codes. WC_LMS_RC_SAVED_TO_NV_MEMORY signals a durable write; other return codes are treated as failures.

function wc_LmsKey_SetReadCb

int wc_LmsKey_SetReadCb(
    LmsKey * key,
    wc_lms_read_private_key_cb read_cb
)

Registers the callback that wolfSSL invokes to load persisted private key state. Used by wc_LmsKey_Reload() to bring a saved key back into memory for further signing.

Parameters:

  • key Pointer to an LmsKey.
  • read_cb Callback invoked to load the private key.

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if key or read_cb is NULL.

function wc_LmsKey_SetContext

int wc_LmsKey_SetContext(
    LmsKey * key,
    void * context
)

Sets the opaque context pointer passed to both the read and write private-key callbacks. Typically used to carry a file handle, database connection, or other persistence-layer state.

Parameters:

  • key Pointer to an LmsKey.
  • context Application-defined pointer; may be NULL.

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if key is NULL.

function wc_LmsKey_MakeKey

int wc_LmsKey_MakeKey(
    LmsKey * key,
    WC_RNG * rng
)

Generates a fresh LMS/HSS key pair. Parameters must already be set (via wc_LmsKey_SetLmsParm() or wc_LmsKey_SetParameters()) and read/write callbacks must be registered. The newly generated private key is persisted via the write callback before the function returns; on success the key transitions to state WC_LMS_STATE_OK.

Parameters:

  • key Pointer to an LmsKey in state WC_LMS_STATE_PARMSET with callbacks set.
  • rng Pointer to an initialized WC_RNG.

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if any required pointer is NULL.
  • MEMORY_E on allocation failure.

Key generation runtime grows quickly with the first tree's height: a 3-level h=5 tree is much faster than a 1-level h=15 tree even though both yield the same total signature count.

Example

LmsKey key;
WC_RNG rng;

wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
wc_LmsKey_SetLmsParm(&key, WC_LMS_PARM_L2_H10_W8);
wc_LmsKey_SetWriteCb(&key, my_write_cb);
wc_LmsKey_SetReadCb(&key, my_read_cb);
wc_LmsKey_SetContext(&key, &my_storage);
wc_InitRng(&rng);

if (wc_LmsKey_MakeKey(&key, &rng) != 0) {
    // error generating key
}

function wc_LmsKey_Reload

int wc_LmsKey_Reload(
    LmsKey * key
)

Reloads a previously generated LMS/HSS private key from persistent storage using the registered read callback, restoring the key to a state where it can sign further messages. On success the key is in state WC_LMS_STATE_OK.

Parameters:

  • key Pointer to an LmsKey with parameters and read callback set.

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if any required pointer is NULL.
  • WC_LMS_RC_* mapped error if the read callback fails.

The same parameters set at key-generation time must be reapplied to the LmsKey before calling Reload (the persisted blob is just the private key bytes; the parameter set is metadata the application owns).

function wc_LmsKey_GetPrivLen

int wc_LmsKey_GetPrivLen(
    const LmsKey * key,
    word32 * len
)

Returns the size in bytes of the encoded private key for the parameter set selected on this key.

Parameters:

  • key Pointer to an LmsKey with parameters set.
  • len Receives the private key size in bytes.

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if key or len is NULL.

function wc_LmsKey_GetPubLen

int wc_LmsKey_GetPubLen(
    const LmsKey * key,
    word32 * len
)

Returns the size in bytes of the LMS/HSS public key for the parameter set selected on this key.

Parameters:

  • key Pointer to an LmsKey with parameters set.
  • len Receives the public key size in bytes.

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if key or len is NULL.

function wc_LmsKey_GetSigLen

int wc_LmsKey_GetSigLen(
    const LmsKey * key,
    word32 * len
)

Returns the LMS/HSS signature size in bytes for the parameter set selected on this key.

Parameters:

  • key Pointer to an LmsKey with parameters set.
  • len Receives the signature size in bytes.

See: wc_LmsKey_Sign

Return:

  • 0 on success.
  • BAD_FUNC_ARG if key or len is NULL.

function wc_LmsKey_Sign

int wc_LmsKey_Sign(
    LmsKey * key,
    byte * sig,
    word32 * sigSz,
    const byte * msg,
    int msgSz
)

Signs msg with the LMS/HSS private key in key. On entry sigSz is the size of the sig buffer; on success it is updated to the bytes written.

Parameters:

  • key Pointer to an LmsKey in state WC_LMS_STATE_OK.
  • sig Buffer that receives the signature.
  • sigSz In: size of sig. Out: bytes written.
  • msg Message to sign.
  • msgSz Length of msg in bytes.

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if any required pointer is NULL.
  • BUFFER_E if *sigSz is smaller than the signature size.
  • -1 (or similar) if all one-time keys have been used.

Each successful sign call consumes a one-time component of the private key. The updated key state is persisted via the registered write callback BEFORE the new signature is returned to the caller. If the write callback fails the sign call fails and the signature is not released. When the supply of one-time keys is exhausted the key transitions to state WC_LMS_STATE_NOSIGS and further sign attempts return SIG_OTHER_E (or similar) – query wc_LmsKey_SigsLeft() to detect this condition in advance.

function wc_LmsKey_SigsLeft

int wc_LmsKey_SigsLeft(
    LmsKey * key
)

Returns the number of one-time signatures still available from this key. When the count reaches zero the key can no longer sign and should be retired.

Parameters:

  • key Pointer to an LmsKey in state WC_LMS_STATE_OK.

See: wc_LmsKey_Sign

Return:

  • Non-negative number of remaining signatures on success.
  • Negative error code on failure (e.g. BAD_FUNC_ARG if key is NULL).

function wc_LmsKey_Free

void wc_LmsKey_Free(
    LmsKey * key
)

Releases resources held by an LmsKey. Safe to call with a NULL pointer. After this call the key is in state WC_LMS_STATE_FREED and must be re-initialized before reuse.

Parameters:

  • key Pointer to the LmsKey to free.

See: wc_LmsKey_Init

function wc_LmsKey_ExportPub

int wc_LmsKey_ExportPub(
    LmsKey * keyDst,
    const LmsKey * keySrc
)

Copies the public part of keySrc into keyDst. The destination key inherits the same parameters and may be used for verification; it does not carry the private key state and cannot sign. Useful for handing a verifier the minimal data it needs.

Parameters:

  • keyDst Pointer to an initialized destination LmsKey.
  • keySrc Pointer to an LmsKey with the public key.

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if keyDst or keySrc is NULL.

function wc_LmsKey_ExportPub_ex

int wc_LmsKey_ExportPub_ex(
    LmsKey * keyDst,
    const LmsKey * keySrc,
    void * heap,
    int devId
)

Like wc_LmsKey_ExportPub() but the destination key is initialized fresh with the supplied heap and devId.

Parameters:

  • keyDst Pointer to an LmsKey to populate.
  • keySrc Pointer to an LmsKey with the public key.
  • heap Heap hint for keyDst.
  • devId Device identifier for keyDst.

See: wc_LmsKey_ExportPub

Return:

  • 0 on success.
  • BAD_FUNC_ARG if keyDst or keySrc is NULL.

function wc_LmsKey_ExportPubRaw

int wc_LmsKey_ExportPubRaw(
    const LmsKey * key,
    byte * out,
    word32 * outLen
)

Exports the LMS/HSS public key as a raw byte string. On entry *outLen is the size of out; on success it is updated to the bytes written.

Parameters:

  • key Pointer to an LmsKey.
  • out Buffer that receives the public key.
  • outLen In: size of out. Out: bytes written.

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if any required pointer is NULL.
  • BUFFER_E if *outLen is smaller than the public key size.

function wc_LmsKey_ImportPubRaw

int wc_LmsKey_ImportPubRaw(
    LmsKey * key,
    const byte * in,
    word32 inLen
)

Imports a raw LMS/HSS public key into key. The key must be in state WC_LMS_STATE_INITED. Parameter information is recovered from the encoded header, after which the key transitions to state WC_LMS_STATE_VERIFYONLY.

Parameters:

  • key Pointer to an LmsKey in WC_LMS_STATE_INITED.
  • in Raw public key bytes.
  • inLen Length of in in bytes.

See:

Return:

  • 0 on success.
  • BAD_FUNC_ARG if any required pointer is NULL.
  • BUFFER_E if inLen is too small.

function wc_LmsKey_Verify

int wc_LmsKey_Verify(
    LmsKey * key,
    const byte * sig,
    word32 sigSz,
    const byte * msg,
    int msgSz
)

Verifies an LMS/HSS signature against msg using the public key held in key. The function returns 0 only when the signature is valid; any other value indicates the signature was rejected.

Parameters:

  • key Pointer to an LmsKey with the public key set.
  • sig Signature bytes to verify.
  • sigSz Length of sig in bytes.
  • msg Message that was signed.
  • msgSz Length of msg in bytes.

See:

Return:

  • 0 on a valid signature.
  • BAD_FUNC_ARG if any required pointer is NULL.
  • SIG_VERIFY_E (or similar) if the signature is invalid or malformed.

function wc_LmsKey_ParmToStr

const char * wc_LmsKey_ParmToStr(
    enum wc_LmsParm lmsParm
)

Returns a static, NUL-terminated string describing an LMS parameter set. Useful for logging and diagnostics.

Parameters:

  • lmsParm A wc_LmsParm constant.

See: wc_LmsKey_SetLmsParm

Return:

  • Pointer to a static string on success.
  • NULL if lmsParm is not recognized.

function wc_LmsKey_GetKid

int wc_LmsKey_GetKid(
    LmsKey * key,
    const byte ** kid,
    word32 * kidSz
)

Returns a pointer to the 16-byte LMS Key Identifier (I) embedded in the private key, together with its length. The returned pointer aliases internal key memory and is valid only until the key is freed.

Parameters:

  • key Pointer to an LmsKey with a private key.
  • kid Receives a pointer to the I bytes.
  • kidSz Receives the length (16 / WC_LMS_I_LEN).

See: wc_LmsKey_GetKidFromPrivRaw

Return:

  • 0 on success.
  • BAD_FUNC_ARG if any required pointer is NULL.

function wc_LmsKey_GetKidFromPrivRaw

const byte * wc_LmsKey_GetKidFromPrivRaw(
    const byte * priv,
    word32 privSz
)

Returns a pointer to the LMS Key Identifier (I) within a raw encoded private key buffer, without requiring an LmsKey object. Used to look up the matching state record in persistent storage during reload.

Parameters:

  • priv Encoded private key bytes.
  • privSz Length of priv in bytes.

See: wc_LmsKey_GetKid

Return:

  • Pointer to the I bytes within priv on success.
  • NULL if priv is NULL or privSz is too small to contain a valid header.

Source code


int wc_LmsKey_Init(LmsKey* key, void* heap, int devId);

int wc_LmsKey_InitId(LmsKey* key, const unsigned char* id, int len,
    void* heap, int devId);

int wc_LmsKey_InitLabel(LmsKey* key, const char* label, void* heap,
    int devId);

int wc_LmsKey_SetLmsParm(LmsKey* key, enum wc_LmsParm lmsParm);

int wc_LmsKey_SetParameters(LmsKey* key, int levels, int height,
    int winternitz);

int wc_LmsKey_SetParameters_ex(LmsKey* key, int levels, int height,
    int winternitz, int hash);

int wc_LmsKey_GetParameters(const LmsKey* key, int* levels, int* height,
    int* winternitz);

int wc_LmsKey_GetParameters_ex(const LmsKey* key, int* levels, int* height,
    int* winternitz, int* hash);

int wc_LmsKey_SetWriteCb(LmsKey* key, wc_lms_write_private_key_cb write_cb);

int wc_LmsKey_SetReadCb(LmsKey* key, wc_lms_read_private_key_cb read_cb);

int wc_LmsKey_SetContext(LmsKey* key, void* context);

int wc_LmsKey_MakeKey(LmsKey* key, WC_RNG* rng);

int wc_LmsKey_Reload(LmsKey* key);

int wc_LmsKey_GetPrivLen(const LmsKey* key, word32* len);

int wc_LmsKey_GetPubLen(const LmsKey* key, word32* len);

int wc_LmsKey_GetSigLen(const LmsKey* key, word32* len);

int wc_LmsKey_Sign(LmsKey* key, byte* sig, word32* sigSz, const byte* msg,
    int msgSz);

int wc_LmsKey_SigsLeft(LmsKey* key);

void wc_LmsKey_Free(LmsKey* key);

int wc_LmsKey_ExportPub(LmsKey* keyDst, const LmsKey* keySrc);

int wc_LmsKey_ExportPub_ex(LmsKey* keyDst, const LmsKey* keySrc, void* heap,
    int devId);

int wc_LmsKey_ExportPubRaw(const LmsKey* key, byte* out, word32* outLen);

int wc_LmsKey_ImportPubRaw(LmsKey* key, const byte* in, word32 inLen);

int wc_LmsKey_Verify(LmsKey* key, const byte* sig, word32 sigSz,
    const byte* msg, int msgSz);

const char* wc_LmsKey_ParmToStr(enum wc_LmsParm lmsParm);

int wc_LmsKey_GetKid(LmsKey* key, const byte** kid, word32* kidSz);

const byte* wc_LmsKey_GetKidFromPrivRaw(const byte* priv, word32 privSz);

Updated on 2026-07-16 at 03:12:19 +0000