My Project
Functions
Algorithms - ED25519

Functions

int wc_ed25519_make_public (ed25519_key *key, unsigned char *pubKey, word32 pubKeySz)
 This function generates the Ed25519 public key from the private key, stored in the ed25519_key object. It stores the public key in the buffer pubKey. More...
 
int wc_ed25519_make_key (WC_RNG *rng, int keysize, ed25519_key *key)
 This function generates a new Ed25519 key and stores it in key. More...
 
int wc_ed25519_sign_msg (const byte *in, word32 inlen, byte *out, word32 *outlen, ed25519_key *key)
 This function signs a message using an ed25519_key object to guarantee authenticity. More...
 
int wc_ed25519ctx_sign_msg (const byte *in, word32 inlen, byte *out, word32 *outlen, ed25519_key *key, const byte *context, byte contextLen)
 This function signs a message using an ed25519_key object to guarantee authenticity. The context is part of the data signed. More...
 
int wc_ed25519ph_sign_hash (const byte *hash, word32 hashLen, byte *out, word32 *outLen, ed25519_key *key, const byte *context, byte contextLen)
 This function signs a message digest using an ed25519_key object to guarantee authenticity. The context is included as part of the data signed. The message is pre-hashed before signature calculation. The hash algorithm used to create message digest must be SHAKE-256. More...
 
int wc_ed25519ph_sign_msg (const byte *in, word32 inlen, byte *out, word32 *outlen, ed25519_key *key, const byte *context, byte contextLen)
 This function signs a message using an ed25519_key object to guarantee authenticity. The context is included as part of the data signed. The message is pre-hashed before signature calculation. More...
 
int wc_ed25519_verify_msg (const byte *sig, word32 siglen, const byte *msg, word32 msgLen, int *ret, ed25519_key *key)
 This function verifies the Ed25519 signature of a message to ensure authenticity. It returns the answer through ret, with 1 corresponding to a valid signature, and 0 corresponding to an invalid signature. More...
 
int wc_ed25519ctx_verify_msg (const byte *sig, word32 siglen, const byte *msg, word32 msgLen, int *ret, ed25519_key *key, const byte *context, byte contextLen)
 This function verifies the Ed25519 signature of a message to ensure authenticity. The context is included as part of the data verified. It returns the answer through ret, with 1 corresponding to a valid signature, and 0 corresponding to an invalid signature. More...
 
int wc_ed25519ph_verify_hash (const byte *sig, word32 siglen, const byte *hash, word32 hashLen, int *ret, ed25519_key *key, const byte *context, byte contextLen)
 This function verifies the Ed25519 signature of the digest of a message to ensure authenticity. The context is included as part of the data verified. The hash is the pre-hashed message before signature calculation. The hash algorithm used to create message digest must be SHA-512. The answer is returned through ret, with 1 corresponding to a valid signature, and 0 corresponding to an invalid signature. More...
 
int wc_ed25519ph_verify_msg (const byte *sig, word32 siglen, const byte *msg, word32 msgLen, int *ret, ed25519_key *key, const byte *context, byte contextLen)
 This function verifies the Ed25519 signature of a message to ensure authenticity. The context is included as part of the data verified. The message is pre-hashed before verification. It returns the answer through ret, with 1 corresponding to a valid signature, and 0 corresponding to an invalid signature. More...
 
int wc_ed25519_init (ed25519_key *key)
 This function initializes an ed25519_key object for future use with message verification. More...
 
void wc_ed25519_free (ed25519_key *key)
 This function frees an Ed25519 object after it has been used. More...
 
int wc_ed25519_import_public (const byte *in, word32 inLen, ed25519_key *key)
 This function imports a public ed25519_key from a buffer containing the public key. This function will handle both compressed and uncompressed keys. The public key is checked that it matches the private key when one is present. More...
 
int wc_ed25519_import_public_ex (const byte *in, word32 inLen, ed25519_key *key, int trusted)
 This function imports a public ed25519_key from a buffer containing the public key. This function will handle both compressed and uncompressed keys. Check public key matches private key, when present, when not trusted. More...
 
int wc_ed25519_import_private_only (const byte *priv, word32 privSz, ed25519_key *key)
 This function imports an Ed25519 private key only from a buffer. More...
 
int wc_ed25519_import_private_key (const byte *priv, word32 privSz, const byte *pub, word32 pubSz, ed25519_key *key)
 This function imports a public/private Ed25519 key pair from a pair of buffers. This function will handle both compressed and uncompressed keys. The public key is assumed to be untrusted and is checked against the private key. More...
 
int wc_ed25519_import_private_key_ex (const byte *priv, word32 privSz, const byte *pub, word32 pubSz, ed25519_key *key, int trusted)
 This function imports a public/private Ed25519 key pair from a pair of buffers. This function will handle both compressed and uncompressed keys. The public is checked against private key if not trusted. More...
 
int wc_ed25519_export_public (ed25519_key *key, byte *out, word32 *outLen)
 This function exports the private key from an ed25519_key structure. It stores the public key in the buffer out, and sets the bytes written to this buffer in outLen. More...
 
int wc_ed25519_export_private_only (ed25519_key *key, byte *out, word32 *outLen)
 This function exports only the private key from an ed25519_key structure. It stores the private key in the buffer out, and sets the bytes written to this buffer in outLen. More...
 
int wc_ed25519_export_private (ed25519_key *key, byte *out, word32 *outLen)
 This function exports the key pair from an ed25519_key structure. It stores the key pair in the buffer out, and sets the bytes written to this buffer in outLen. More...
 
int wc_ed25519_export_key (ed25519_key *key, byte *priv, word32 *privSz, byte *pub, word32 *pubSz)
 This function exports the private and public key separately from an ed25519_key structure. It stores the private key in the buffer priv, and sets the bytes written to this buffer in privSz. It stores the public key in the buffer pub, and sets the bytes written to this buffer in pubSz. More...
 
int wc_ed25519_check_key (ed25519_key *key)
 This function checks the public key in ed25519_key structure matches the private key. More...
 
int wc_ed25519_size (ed25519_key *key)
 This function returns the size of an Ed25519 - 32 bytes. More...
 
int wc_ed25519_priv_size (ed25519_key *key)
 This function returns the private key size (secret + public) in bytes. More...
 
int wc_ed25519_pub_size (ed25519_key *key)
 This function returns the compressed key size in bytes (public key). More...
 
int wc_ed25519_sig_size (ed25519_key *key)
 This function returns the size of an Ed25519 signature (64 in bytes). More...
 

Detailed Description

Function Documentation

◆ wc_ed25519_check_key()

int wc_ed25519_check_key ( ed25519_key *  key)

This function checks the public key in ed25519_key structure matches the private key.

Returns
0 Returned if the private and public key matched.
BAD_FUNC_ARG Returned if the given key is NULL.
PUBLIC_KEY_E Returned if the no public key available or is invalid.
Parameters
[in]keyPointer to an ed25519_key structure holding a private and public key.

Example

int ret;
byte priv[] = { initialize with 57 byte private key };
byte pub[] = { initialize with the corresponding public key };
ed25519_key key;
wc_ed25519_init_key(&key);
wc_ed25519_import_private_key_ex(priv, sizeof(priv), pub, sizeof(pub), &key,
1);
if (ret != 0) {
// error checking key
}
int wc_ed25519_import_private_key_ex(const byte *priv, word32 privSz, const byte *pub, word32 pubSz, ed25519_key *key, int trusted)
This function imports a public/private Ed25519 key pair from a pair of buffers. This function will ha...
int wc_ed25519_check_key(ed25519_key *key)
This function checks the public key in ed25519_key structure matches the private key.
See also
wc_ed25519_import_private_key
wc_ed25519_import_private_key_ex

◆ wc_ed25519_export_key()

int wc_ed25519_export_key ( ed25519_key *  key,
byte *  priv,
word32 *  privSz,
byte *  pub,
word32 *  pubSz 
)

This function exports the private and public key separately from an ed25519_key structure. It stores the private key in the buffer priv, and sets the bytes written to this buffer in privSz. It stores the public key in the buffer pub, and sets the bytes written to this buffer in pubSz.

Returns
0 Returned upon successfully exporting the key pair.
BAD_FUNC_ARG Returned if any of the input values evaluate to NULL.
BUFFER_E Returned if the buffer provided is not large enough to store the key pair.
Parameters
[in]keyPointer to an ed25519_key structure from which to export the key pair.
[out]privPointer to the buffer in which to store the private key.
[in,out]privSzPointer to a word32 object with the size available in out. Set with the number of bytes written to out after successfully exporting the private key.
[out]pubPointer to the buffer in which to store the public key.
[in,out]pubSzPointer to a word32 object with the size available in out. Set with the number of bytes written to out after successfully exporting the public key.

Example

int ret;
ed25519_key key;
// initialize key, make key
char pub[32];
word32 pubSz = sizeof(pub);
char priv[32];
word32 privSz = sizeof(priv);
ret = wc_ed25519_export_key(&key, priv, &pubSz, pub, &pubSz);
if (ret != 0) {
// error exporting public key
}
int wc_ed25519_export_key(ed25519_key *key, byte *priv, word32 *privSz, byte *pub, word32 *pubSz)
This function exports the private and public key separately from an ed25519_key structure....
See also
wc_ed25519_export_private
wc_ed25519_export_public

◆ wc_ed25519_export_private()

int wc_ed25519_export_private ( ed25519_key *  key,
byte *  out,
word32 *  outLen 
)

This function exports the key pair from an ed25519_key structure. It stores the key pair in the buffer out, and sets the bytes written to this buffer in outLen.

Returns
0 Returned upon successfully exporting the key pair.
BAD_FUNC_ARG Returned if any of the input values evaluate to NULL.
BUFFER_E Returned if the buffer provided is not large enough to store the key pair.
Parameters
[in]keyPointer to an ed25519_key structure from which to export the key pair.
[out]outPointer to the buffer in which to store the key pair.
[in,out]outLenPointer to a word32 object with the size available in out. Set with the number of bytes written to out after successfully exporting the key pair.

Example

ed25519_key key;
WC_RNG rng;
wc_InitRng(&rng);
wc_ed25519_make_key(&rng, 32, &key); // initialize 32 byte Ed25519 key
byte out[64]; // out needs to be a sufficient buffer size
word32 outLen = sizeof(out);
int key_size = wc_ed25519_export_private(&key, out, &outLen);
if (key_size == BUFFER_E) {
// Check size of out compared to outLen to see if function reset outLen
}
int wc_ed25519_init(ed25519_key *key)
This function initializes an ed25519_key object for future use with message verification.
int wc_ed25519_make_key(WC_RNG *rng, int keysize, ed25519_key *key)
This function generates a new Ed25519 key and stores it in key.
int wc_ed25519_export_private(ed25519_key *key, byte *out, word32 *outLen)
This function exports the key pair from an ed25519_key structure. It stores the key pair in the buffe...
int wc_InitRng(WC_RNG *)
Gets the seed (from OS) and key cipher for rng. rng->drbg (deterministic random bit generator) alloca...
See also
wc_ed25519_import_private_key
wc_ed25519_import_private_key_ex
wc_ed25519_export_private_only

◆ wc_ed25519_export_private_only()

int wc_ed25519_export_private_only ( ed25519_key *  key,
byte *  out,
word32 *  outLen 
)

This function exports only the private key from an ed25519_key structure. It stores the private key in the buffer out, and sets the bytes written to this buffer in outLen.

Returns
0 Returned upon successfully exporting the private key.
BAD_FUNC_ARG Returned if any of the input values evaluate to NULL.
BUFFER_E Returned if the buffer provided is not large enough to store the private key.
Parameters
[in]keyPointer to an ed25519_key structure from which to export the private key.
[out]outPointer to the buffer in which to store the private key.
[in,out]outLenPointer to a word32 object with the size available in out. Set with the number of bytes written to out after successfully exporting the private key.

Example

int ret;
ed25519_key key;
// initialize key, make key
char priv[32]; // 32 bytes because only private key
word32 privSz = sizeof(priv);
ret = wc_ed25519_export_private_only(&key, priv, &privSz);
if (ret != 0) {
// error exporting private key
}
int wc_ed25519_export_private_only(ed25519_key *key, byte *out, word32 *outLen)
This function exports only the private key from an ed25519_key structure. It stores the private key i...
See also
wc_ed25519_export_public
wc_ed25519_import_private_key
wc_ed25519_import_private_key_ex

◆ wc_ed25519_export_public()

int wc_ed25519_export_public ( ed25519_key *  key,
byte *  out,
word32 *  outLen 
)

This function exports the private key from an ed25519_key structure. It stores the public key in the buffer out, and sets the bytes written to this buffer in outLen.

Returns
0 Returned upon successfully exporting the public key.
BAD_FUNC_ARG Returned if any of the input values evaluate to NULL.
BUFFER_E Returned if the buffer provided is not large enough to store the private key. Upon returning this error, the function sets the size required in outLen.
Parameters
[in]keyPointer to an ed25519_key structure from which to export the public key.
[out]outPointer to the buffer in which to store the public key.
[in,out]outLenPointer to a word32 object with the size available in out. Set with the number of bytes written to out after successfully exporting the public key.

Example

int ret;
ed25519_key key;
// initialize key, make key
char pub[32];
word32 pubSz = sizeof(pub);
ret = wc_ed25519_export_public(&key, pub, &pubSz);
if (ret != 0) {
// error exporting public key
}
int wc_ed25519_export_public(ed25519_key *key, byte *out, word32 *outLen)
This function exports the private key from an ed25519_key structure. It stores the public key in the ...
See also
wc_ed25519_import_public
wc_ed25519_import_public_ex
wc_ed25519_export_private_only

◆ wc_ed25519_free()

void wc_ed25519_free ( ed25519_key *  key)

This function frees an Ed25519 object after it has been used.

Parameters
[in,out]keyPointer to the ed25519_key object to free

Example

ed25519_key key;
// initialize key and perform secure exchanges
...
wc_ed25519_free(&key);
See also
wc_ed25519_init

◆ wc_ed25519_import_private_key()

int wc_ed25519_import_private_key ( const byte *  priv,
word32  privSz,
const byte *  pub,
word32  pubSz,
ed25519_key *  key 
)

This function imports a public/private Ed25519 key pair from a pair of buffers. This function will handle both compressed and uncompressed keys. The public key is assumed to be untrusted and is checked against the private key.

Returns
0 Returned on successfully importing the ed25519_key.
BAD_FUNC_ARG Returned if priv or key evaluate to NULL; or if either privSz is not equal to ED25519_KEY_SIZE nor ED25519_PRV_KEY_SIZE, or pubSz is less than ED25519_PUB_KEY_SIZE.
Parameters
[in]privPointer to the buffer containing the private key.
[in]privSzLength of the private key.
[in]pubPointer to the buffer containing the public key.
[in]pubSzLength of the public key.
[in,out]keyPointer to the ed25519_key object in which to store the imported private/public key pair.

Example

int ret;
byte priv[] = { initialize with 32 byte private key };
byte pub[] = { initialize with the corresponding public key };
ed25519_key key;
wc_ed25519_init_key(&key);
ret = wc_ed25519_import_private_key(priv, sizeof(priv), pub, sizeof(pub),
&key);
if (ret != 0) {
// error importing key
}
int wc_ed25519_import_private_key(const byte *priv, word32 privSz, const byte *pub, word32 pubSz, ed25519_key *key)
This function imports a public/private Ed25519 key pair from a pair of buffers. This function will ha...
See also
wc_ed25519_import_public
wc_ed25519_import_public_ex
wc_ed25519_import_private_only
wc_ed25519_import_private_key_ex
wc_ed25519_export_private

◆ wc_ed25519_import_private_key_ex()

int wc_ed25519_import_private_key_ex ( const byte *  priv,
word32  privSz,
const byte *  pub,
word32  pubSz,
ed25519_key *  key,
int  trusted 
)

This function imports a public/private Ed25519 key pair from a pair of buffers. This function will handle both compressed and uncompressed keys. The public is checked against private key if not trusted.

Returns
0 Returned on successfully importing the ed25519_key.
BAD_FUNC_ARG Returned if priv or key evaluate to NULL; or if either privSz is not equal to ED25519_KEY_SIZE nor ED25519_PRV_KEY_SIZE, or pubSz is less than ED25519_PUB_KEY_SIZE.
Parameters
[in]privPointer to the buffer containing the private key.
[in]privSzLength of the private key.
[in]pubPointer to the buffer containing the public key.
[in]pubSzLength of the public key.
[in,out]keyPointer to the ed25519_key object in which to store the imported private/public key pair.
[in]trustedPublic key data is trusted or not.

Example

int ret;
byte priv[] = { initialize with 32 byte private key };
byte pub[] = { initialize with the corresponding public key };
ed25519_key key;
wc_ed25519_init_key(&key);
ret = wc_ed25519_import_private_key(priv, sizeof(priv), pub, sizeof(pub),
&key, 1);
if (ret != 0) {
// error importing key
}
See also
wc_ed25519_import_public
wc_ed25519_import_public_ex
wc_ed25519_import_private_only
wc_ed25519_import_private_key
wc_ed25519_export_private

◆ wc_ed25519_import_private_only()

int wc_ed25519_import_private_only ( const byte *  priv,
word32  privSz,
ed25519_key *  key 
)

This function imports an Ed25519 private key only from a buffer.

Returns
0 Returned on successfully importing the Ed25519 key.
BAD_FUNC_ARG Returned if priv or key evaluate to NULL, or if privSz is not equal to ED25519_KEY_SIZE.
Parameters
[in]privPointer to the buffer containing the private key.
[in]privSzLength of the private key.
[in,out]keyPointer to the ed25519_key object in which to store the imported private key.

Example

int ret;
byte priv[] = { initialize with 32 byte private key };
ed25519_key key;
wc_ed25519_init_key(&key);
ret = wc_ed25519_import_private_only(priv, sizeof(priv), &key);
if (ret != 0) {
// error importing private key
}
int wc_ed25519_import_private_only(const byte *priv, word32 privSz, ed25519_key *key)
This function imports an Ed25519 private key only from a buffer.
See also
wc_ed25519_import_public
wc_ed25519_import_public_ex
wc_ed25519_import_private_key
wc_ed25519_import_private_key_ex
wc_ed25519_export_private_only

◆ wc_ed25519_import_public()

int wc_ed25519_import_public ( const byte *  in,
word32  inLen,
ed25519_key *  key 
)

This function imports a public ed25519_key from a buffer containing the public key. This function will handle both compressed and uncompressed keys. The public key is checked that it matches the private key when one is present.

Returns
0 Returned on successfully importing the ed25519_key.
BAD_FUNC_ARG Returned if in or key evaluate to NULL, or inLen is less than the size of an Ed25519 key.
Parameters
[in]inPointer to the buffer containing the public key.
[in]inLenLength of the buffer containing the public key.
[in,out]keyPointer to the ed25519_key object in which to store the public key.

Example

int ret;
byte pub[] = { initialize Ed25519 public key };
ed_25519 key;
wc_ed25519_init_key(&key);
ret = wc_ed25519_import_public(pub, sizeof(pub), &key);
if (ret != 0) {
// error importing key
}
int wc_ed25519_import_public(const byte *in, word32 inLen, ed25519_key *key)
This function imports a public ed25519_key from a buffer containing the public key....
See also
wc_ed25519_import_public_ex
wc_ed25519_import_private_key
wc_ed25519_import_private_key_ex
wc_ed25519_export_public

◆ wc_ed25519_import_public_ex()

int wc_ed25519_import_public_ex ( const byte *  in,
word32  inLen,
ed25519_key *  key,
int  trusted 
)

This function imports a public ed25519_key from a buffer containing the public key. This function will handle both compressed and uncompressed keys. Check public key matches private key, when present, when not trusted.

Returns
0 Returned on successfully importing the ed25519_key.
BAD_FUNC_ARG Returned if in or key evaluate to NULL, or inLen is less than the size of an Ed25519 key.
Parameters
[in]inPointer to the buffer containing the public key.
[in]inLenLength of the buffer containing the public key.
[in,out]keyPointer to the ed25519_key object in which to store the public key.
[in]trustedPublic key data is trusted or not.

Example

int ret;
byte pub[] = { initialize Ed25519 public key };
ed_25519 key;
wc_ed25519_init_key(&key);
ret = wc_ed25519_import_public_ex(pub, sizeof(pub), &key, 1);
if (ret != 0) {
// error importing key
}
int wc_ed25519_import_public_ex(const byte *in, word32 inLen, ed25519_key *key, int trusted)
This function imports a public ed25519_key from a buffer containing the public key....
See also
wc_ed25519_import_public
wc_ed25519_import_private_key
wc_ed25519_import_private_key_ex
wc_ed25519_export_public

◆ wc_ed25519_init()

int wc_ed25519_init ( ed25519_key *  key)

This function initializes an ed25519_key object for future use with message verification.

Returns
0 Returned upon successfully initializing the ed25519_key object.
BAD_FUNC_ARG Returned if key is NULL.
Parameters
[in,out]keyPointer to the ed25519_key object to initialize.

Example

ed25519_key key;
See also
wc_ed25519_make_key
wc_ed25519_free

◆ wc_ed25519_make_key()

int wc_ed25519_make_key ( WC_RNG *  rng,
int  keysize,
ed25519_key *  key 
)

This function generates a new Ed25519 key and stores it in key.

Returns
0 Returned upon successfully making an ed25519_key.
BAD_FUNC_ARG Returned if rng or key evaluate to NULL, or if the specified key size is not 32 bytes (Ed25519 has 32 byte keys).
MEMORY_E Returned if there is an error allocating memory during function execution.
Parameters
[in]rngPointer to an initialized RNG object with which to generate the key.
[in]keysizeLength of key to generate. Should always be 32 for Ed25519.
[in,out]keyPointer to the ed25519_key for which to generate a key.

Example

int ret;
WC_RNG rng;
ed25519_key key;
wc_InitRng(&rng);
wc_ed25519_make_key(&rng, 32, &key);
if (ret != 0) {
// error making key
}
See also
wc_ed25519_init

◆ wc_ed25519_make_public()

int wc_ed25519_make_public ( ed25519_key *  key,
unsigned char *  pubKey,
word32  pubKeySz 
)

This function generates the Ed25519 public key from the private key, stored in the ed25519_key object. It stores the public key in the buffer pubKey.

Returns
0 Returned upon successfully making the public key.
BAD_FUNC_ARG Returned if key or pubKey evaluate to NULL, or if the specified key size is not 32 bytes (Ed25519 has 32 byte keys).
ECC_PRIV_KEY_E returned if the ed25519_key object does not have the private key in it.
MEMORY_E Returned if there is an error allocating memory during function execution.
Parameters
[in]keyPointer to the ed25519_key for which to generate a key.
[out]pubKeyPointer to the buffer in which to store the public key.
[in]pubKeySzSize of the public key. Should be ED25519_PUB_KEY_SIZE.

Example

int ret;
ed25519_key key;
byte priv[] = { initialize with 32 byte private key };
byte pub[32];
word32 pubSz = sizeof(pub);
wc_ed25519_import_private_only(priv, sizeof(priv), &key);
ret = wc_ed25519_make_public(&key, pub, &pubSz);
if (ret != 0) {
// error making public key
}
int wc_ed25519_make_public(ed25519_key *key, unsigned char *pubKey, word32 pubKeySz)
This function generates the Ed25519 public key from the private key, stored in the ed25519_key object...
See also
wc_ed25519_init
wc_ed25519_import_private_only
wc_ed25519_make_key

◆ wc_ed25519_priv_size()

int wc_ed25519_priv_size ( ed25519_key *  key)

This function returns the private key size (secret + public) in bytes.

Returns
ED25519_PRV_KEY_SIZE The size of the private key (64 bytes).
BAD_FUNC_ARG Returned if key argument is NULL.
Parameters
[in]keyPointer to an ed25519_key structure for which to get the key size.

Example

ed25519_key key;
WC_RNG rng;
wc_InitRng(&rng);
wc_ed25519_make_key(&rng, 32, &key); // initialize 32 byte Ed25519 key
int key_size = wc_ed25519_priv_size(&key);
int wc_ed25519_priv_size(ed25519_key *key)
This function returns the private key size (secret + public) in bytes.
See also
wc_ed25519_pub_size

◆ wc_ed25519_pub_size()

int wc_ed25519_pub_size ( ed25519_key *  key)

This function returns the compressed key size in bytes (public key).

Returns
ED25519_PUB_KEY_SIZE The size of the compressed public key (32 bytes).
BAD_FUNC_ARG Returns if key argument is NULL.
Parameters
[in]keyPointer to an ed25519_key structure for which to get the key size.

Example

ed25519_key key;
WC_RNG rng;
wc_InitRng(&rng);
wc_ed25519_make_key(&rng, 32, &key); // initialize 32 byte Ed25519 key
int key_size = wc_ed25519_pub_size(&key);
int wc_ed25519_pub_size(ed25519_key *key)
This function returns the compressed key size in bytes (public key).
See also
wc_ed25519_priv_size

◆ wc_ed25519_sig_size()

int wc_ed25519_sig_size ( ed25519_key *  key)

This function returns the size of an Ed25519 signature (64 in bytes).

Returns
ED25519_SIG_SIZE The size of an Ed25519 signature (64 bytes).
BAD_FUNC_ARG Returns if key argument is NULL.
Parameters
[in]keyPointer to an ed25519_key structure for which to get the signature size.

Example

int sigSz;
ed25519_key key;
// initialize key, make key
sigSz = wc_ed25519_sig_size(&key);
if (sigSz == 0) {
// error determining sig size
}
int wc_ed25519_sig_size(ed25519_key *key)
This function returns the size of an Ed25519 signature (64 in bytes).
See also
wc_ed25519_sign_msg

◆ wc_ed25519_sign_msg()

int wc_ed25519_sign_msg ( const byte *  in,
word32  inlen,
byte *  out,
word32 *  outlen,
ed25519_key *  key 
)

This function signs a message using an ed25519_key object to guarantee authenticity.

Returns
0 Returned upon successfully generating a signature for the message.
BAD_FUNC_ARG Returned if any of the input parameters evaluate to NULL, or if the output buffer is too small to store the generated signature.
MEMORY_E Returned if there is an error allocating memory during function execution.
Parameters
[in]inPointer to the buffer containing the message to sign.
[in]inlenLength of the message to sign.
[out]outBuffer in which to store the generated signature.
[in,out]outlenMaximum length of the output buffer. Will store the bytes written to out upon successfully generating a message signature.
[in]keyPointer to a private ed25519_key with which to generate the signature.

Example

ed25519_key key;
WC_RNG rng;
int ret, sigSz;
byte sig[64]; // will hold generated signature
sigSz = sizeof(sig);
byte message[] = { initialize with message };
wc_InitRng(&rng); // initialize rng
wc_ed25519_init(&key); // initialize key
wc_ed25519_make_key(&rng, 32, &key); // make public/private key pair
ret = wc_ed25519_sign_msg(message, sizeof(message), sig, &sigSz, &key);
if (ret != 0) {
// error generating message signature
}
int wc_ed25519_sign_msg(const byte *in, word32 inlen, byte *out, word32 *outlen, ed25519_key *key)
This function signs a message using an ed25519_key object to guarantee authenticity.
See also
wc_ed25519ctx_sign_msg
wc_ed25519ph_sign_hash
wc_ed25519ph_sign_msg
wc_ed25519_verify_msg

◆ wc_ed25519_size()

int wc_ed25519_size ( ed25519_key *  key)

This function returns the size of an Ed25519 - 32 bytes.

Returns
ED25519_KEY_SIZE The size of a valid private key (32 bytes).
BAD_FUNC_ARG Returned if the given key is NULL.
Parameters
[in]keyPointer to an ed25519_key structure for which to get the key size.

Example

int keySz;
ed25519_key key;
// initialize key, make key
keySz = wc_ed25519_size(&key);
if (keySz == 0) {
// error determining key size
}
int wc_ed25519_size(ed25519_key *key)
This function returns the size of an Ed25519 - 32 bytes.
See also
wc_ed25519_make_key

◆ wc_ed25519_verify_msg()

int wc_ed25519_verify_msg ( const byte *  sig,
word32  siglen,
const byte *  msg,
word32  msgLen,
int *  ret,
ed25519_key *  key 
)

This function verifies the Ed25519 signature of a message to ensure authenticity. It returns the answer through ret, with 1 corresponding to a valid signature, and 0 corresponding to an invalid signature.

Returns
0 Returned upon successfully performing the signature verification and authentication.
BAD_FUNC_ARG Returned if any of the input parameters evaluate to NULL, or if the siglen does not match the actual length of a signature.
SIG_VERIFY_E Returned if verification completes, but the signature generated does not match the signature provided.
Parameters
[in]sigPointer to the buffer containing the signature to verify.
[in]siglenLength of the signature to verify.
[in]msgPointer to the buffer containing the message to verify.
[in]msgLenLength of the message to verify.
[out]retPointer to the result of the verification. 1 indicates the message was successfully verified.
[in]keyPointer to a public Ed25519 key with which to verify the signature.

Example

ed25519_key key;
int ret, verified = 0;
byte sig[] { initialize with received signature };
byte msg[] = { initialize with message };
// initialize key with received public key
ret = wc_ed25519_verify_msg(sig, sizeof(sig), msg, sizeof(msg), &verified,
&key);
if (ret < 0) {
// error performing verification
} else if (verified == 0)
// the signature is invalid
}
int wc_ed25519_verify_msg(const byte *sig, word32 siglen, const byte *msg, word32 msgLen, int *ret, ed25519_key *key)
This function verifies the Ed25519 signature of a message to ensure authenticity. It returns the answ...
See also
wc_ed25519ctx_verify_msg
wc_ed25519ph_verify_hash
wc_ed25519ph_verify_msg
wc_ed25519_sign_msg

◆ wc_ed25519ctx_sign_msg()

int wc_ed25519ctx_sign_msg ( const byte *  in,
word32  inlen,
byte *  out,
word32 *  outlen,
ed25519_key *  key,
const byte *  context,
byte  contextLen 
)

This function signs a message using an ed25519_key object to guarantee authenticity. The context is part of the data signed.

Returns
0 Returned upon successfully generating a signature for the message.
BAD_FUNC_ARG Returned any of the input parameters evaluate to NULL, or if the output buffer is too small to store the generated signature.
MEMORY_E Returned if there is an error allocating memory during function execution.
Parameters
[in]inPointer to the buffer containing the message to sign.
[in]inlenLength of the message to sign.
[out]outBuffer in which to store the generated signature.
[in,out]outlenMaximum length of the output buffer. Will store the bytes written to out upon successfully generating a message signature.
[in]keyPointer to a private ed25519_key with which to generate the signature.
[in]contextPointer to the buffer containing the context for which message is being signed.
[in]contextLenLength of the context buffer.

Example

ed25519_key key;
WC_RNG rng;
int ret, sigSz;
byte sig[64]; // will hold generated signature
sigSz = sizeof(sig);
byte message[] = { initialize with message };
byte context[] = { initialize with context of signing };
wc_InitRng(&rng); // initialize rng
wc_ed25519_init(&key); // initialize key
wc_ed25519_make_key(&rng, 32, &key); // make public/private key pair
ret = wc_ed25519ctx_sign_msg(message, sizeof(message), sig, &sigSz, &key,
context, sizeof(context));
if (ret != 0) {
// error generating message signature
}
int wc_ed25519ctx_sign_msg(const byte *in, word32 inlen, byte *out, word32 *outlen, ed25519_key *key, const byte *context, byte contextLen)
This function signs a message using an ed25519_key object to guarantee authenticity....
See also
wc_ed25519_sign_msg
wc_ed25519ph_sign_hash
wc_ed25519ph_sign_msg
wc_ed25519_verify_msg

◆ wc_ed25519ctx_verify_msg()

int wc_ed25519ctx_verify_msg ( const byte *  sig,
word32  siglen,
const byte *  msg,
word32  msgLen,
int *  ret,
ed25519_key *  key,
const byte *  context,
byte  contextLen 
)

This function verifies the Ed25519 signature of a message to ensure authenticity. The context is included as part of the data verified. It returns the answer through ret, with 1 corresponding to a valid signature, and 0 corresponding to an invalid signature.

Returns
0 Returned upon successfully performing the signature verification and authentication.
BAD_FUNC_ARG Returned if any of the input parameters evaluate to NULL, or if the siglen does not match the actual length of a signature.
SIG_VERIFY_E Returned if verification completes, but the signature generated does not match the signature provided.
Parameters
[in]sigPointer to the buffer containing the signature to verify.
[in]siglenLength of the signature to verify.
[in]msgPointer to the buffer containing the message to verify.
[in]msgLenLength of the message to verify.
[out]retPointer to the result of the verification. 1 indicates the message was successfully verified.
[in]keyPointer to a public Ed25519 key with which to verify the signature.
[in]contextPointer to the buffer containing the context for which the message was signed.
[in]contextLenLength of the context buffer.

Example

ed25519_key key;
int ret, verified = 0;
byte sig[] { initialize with received signature };
byte msg[] = { initialize with message };
byte context[] = { initialize with context of signature };
// initialize key with received public key
ret = wc_ed25519ctx_verify_msg(sig, sizeof(sig), msg, sizeof(msg),
&verified, &key, );
if (ret < 0) {
// error performing verification
} else if (verified == 0)
// the signature is invalid
}
int wc_ed25519ctx_verify_msg(const byte *sig, word32 siglen, const byte *msg, word32 msgLen, int *ret, ed25519_key *key, const byte *context, byte contextLen)
This function verifies the Ed25519 signature of a message to ensure authenticity. The context is incl...
See also
wc_ed25519_verify_msg
wc_ed25519ph_verify_hash
wc_ed25519ph_verify_msg
wc_ed25519_sign_msg

◆ wc_ed25519ph_sign_hash()

int wc_ed25519ph_sign_hash ( const byte *  hash,
word32  hashLen,
byte *  out,
word32 *  outLen,
ed25519_key *  key,
const byte *  context,
byte  contextLen 
)

This function signs a message digest using an ed25519_key object to guarantee authenticity. The context is included as part of the data signed. The message is pre-hashed before signature calculation. The hash algorithm used to create message digest must be SHAKE-256.

Returns
0 Returned upon successfully generating a signature for the message digest.
BAD_FUNC_ARG Returned any of the input parameters evaluate to NULL, or if the output buffer is too small to store the generated signature.
MEMORY_E Returned if there is an error allocating memory during function execution.
Parameters
[in]hashPointer to the buffer containing the hash of the message to sign.
[in]hashLenLength of the hash of the message to sign.
[out]outBuffer in which to store the generated signature.
[in,out]outlenMaximum length of the output buffer. Will store the bytes written to out upon successfully generating a message signature.
[in]keyPointer to a private ed25519_key with which to generate the signature.
[in]contextPointer to the buffer containing the context for which message is being signed.
[in]contextLenLength of the context buffer.

Example

ed25519_key key;
WC_RNG rng;
int ret, sigSz;
byte sig[64]; // will hold generated signature
sigSz = sizeof(sig);
byte hash[] = { initialize with SHA-512 hash of message };
byte context[] = { initialize with context of signing };
wc_InitRng(&rng); // initialize rng
wc_ed25519_init(&key); // initialize key
wc_ed25519_make_key(&rng, 32, &key); // make public/private key pair
ret = wc_ed25519ph_sign_hash(hash, sizeof(hash), sig, &sigSz, &key,
context, sizeof(context));
if (ret != 0) {
// error generating message signature
}
int wc_ed25519ph_sign_hash(const byte *hash, word32 hashLen, byte *out, word32 *outLen, ed25519_key *key, const byte *context, byte contextLen)
This function signs a message digest using an ed25519_key object to guarantee authenticity....
See also
wc_ed25519_sign_msg
wc_ed25519ctx_sign_msg
wc_ed25519ph_sign_msg
wc_ed25519_verify_msg

◆ wc_ed25519ph_sign_msg()

int wc_ed25519ph_sign_msg ( const byte *  in,
word32  inlen,
byte *  out,
word32 *  outlen,
ed25519_key *  key,
const byte *  context,
byte  contextLen 
)

This function signs a message using an ed25519_key object to guarantee authenticity. The context is included as part of the data signed. The message is pre-hashed before signature calculation.

Returns
0 Returned upon successfully generating a signature for the message.
BAD_FUNC_ARG Returned any of the input parameters evaluate to NULL, or if the output buffer is too small to store the generated signature.
MEMORY_E Returned if there is an error allocating memory during function execution.
Parameters
[in]inPointer to the buffer containing the message to sign.
[in]inlenLength of the message to sign.
[out]outBuffer in which to store the generated signature.
[in,out]outlenMaximum length of the output buffer. Will store the bytes written to out upon successfully generating a message signature.
[in]keyPointer to a private ed25519_key with which to generate the signature.
[in]contextPointer to the buffer containing the context for which message is being signed.
[in]contextLenLength of the context buffer.

Example

ed25519_key key;
WC_RNG rng;
int ret, sigSz;
byte sig[64]; // will hold generated signature
sigSz = sizeof(sig);
byte message[] = { initialize with message };
byte context[] = { initialize with context of signing };
wc_InitRng(&rng); // initialize rng
wc_ed25519_init(&key); // initialize key
wc_ed25519_make_key(&rng, 32, &key); // make public/private key pair
ret = wc_ed25519ph_sign_msg(message, sizeof(message), sig, &sigSz, &key,
context, sizeof(context));
if (ret != 0) {
// error generating message signature
}
int wc_ed25519ph_sign_msg(const byte *in, word32 inlen, byte *out, word32 *outlen, ed25519_key *key, const byte *context, byte contextLen)
This function signs a message using an ed25519_key object to guarantee authenticity....
See also
wc_ed25519_sign_msg
wc_ed25519ctx_sign_msg
wc_ed25519ph_sign_hash
wc_ed25519_verify_msg

◆ wc_ed25519ph_verify_hash()

int wc_ed25519ph_verify_hash ( const byte *  sig,
word32  siglen,
const byte *  hash,
word32  hashLen,
int *  ret,
ed25519_key *  key,
const byte *  context,
byte  contextLen 
)

This function verifies the Ed25519 signature of the digest of a message to ensure authenticity. The context is included as part of the data verified. The hash is the pre-hashed message before signature calculation. The hash algorithm used to create message digest must be SHA-512. The answer is returned through ret, with 1 corresponding to a valid signature, and 0 corresponding to an invalid signature.

Returns
0 Returned upon successfully performing the signature verification and authentication.
BAD_FUNC_ARG Returned if any of the input parameters evaluate to NULL, or if the siglen does not match the actual length of a signature.
SIG_VERIFY_E Returned if verification completes, but the signature generated does not match the signature provided.
Parameters
[in]sigPointer to the buffer containing the signature to verify.
[in]siglenLength of the signature to verify.
[in]hashPointer to the buffer containing the hash of the message to verify.
[in]hashLenLength of the hash to verify.
[out]retPointer to the result of the verification. 1 indicates the message was successfully verified.
[in]keyPointer to a public Ed25519 key with which to verify the signature.
[in]contextPointer to the buffer containing the context for which the message was signed.
[in]contextLenLength of the context buffer.

Example

ed25519_key key;
int ret, verified = 0;
byte sig[] { initialize with received signature };
byte hash[] = { initialize with SHA-512 hash of message };
byte context[] = { initialize with context of signature };
// initialize key with received public key
ret = wc_ed25519ph_verify_hash(sig, sizeof(sig), msg, sizeof(msg),
&verified, &key, );
if (ret < 0) {
// error performing verification
} else if (verified == 0)
// the signature is invalid
}
int wc_ed25519ph_verify_hash(const byte *sig, word32 siglen, const byte *hash, word32 hashLen, int *ret, ed25519_key *key, const byte *context, byte contextLen)
This function verifies the Ed25519 signature of the digest of a message to ensure authenticity....
See also
wc_ed25519_verify_msg
wc_ed25519ctx_verify_msg
wc_ed25519ph_verify_msg
wc_ed25519_sign_msg

◆ wc_ed25519ph_verify_msg()

int wc_ed25519ph_verify_msg ( const byte *  sig,
word32  siglen,
const byte *  msg,
word32  msgLen,
int *  ret,
ed25519_key *  key,
const byte *  context,
byte  contextLen 
)

This function verifies the Ed25519 signature of a message to ensure authenticity. The context is included as part of the data verified. The message is pre-hashed before verification. It returns the answer through ret, with 1 corresponding to a valid signature, and 0 corresponding to an invalid signature.

Returns
0 Returned upon successfully performing the signature verification and authentication.
BAD_FUNC_ARG Returned if any of the input parameters evaluate to NULL, or if the siglen does not match the actual length of a signature.
SIG_VERIFY_E Returned if verification completes, but the signature generated does not match the signature provided.
Parameters
[in]sigPointer to the buffer containing the signature to verify.
[in]siglenLength of the signature to verify.
[in]msgPointer to the buffer containing the message to verify.
[in]msgLenLength of the message to verify.
[out]retPointer to the result of the verification. 1 indicates the message was successfully verified.
[in]keyPointer to a public Ed25519 key with which to verify the signature.
[in]contextPointer to the buffer containing the context for which the message was signed.
[in]contextLenLength of the context buffer.

Example

ed25519_key key;
int ret, verified = 0;
byte sig[] { initialize with received signature };
byte msg[] = { initialize with message };
byte context[] = { initialize with context of signature };
// initialize key with received public key
ret = wc_ed25519ctx_verify_msg(sig, sizeof(sig), msg, sizeof(msg),
&verified, &key, );
if (ret < 0) {
// error performing verification
} else if (verified == 0)
// the signature is invalid
}
See also
wc_ed25519_verify_msg
wc_ed25519ph_verify_hash
wc_ed25519ph_verify_msg
wc_ed25519_sign_msg