Functions
Signature API

Functions

int wc_SignatureGetSize (enum wc_SignatureType sig_type, const void *key, word32 key_len)
 This function returns the maximum size of the resulting signature. More...
 
int wc_SignatureVerify (enum wc_HashType hash_type, enum wc_SignatureType sig_type, const byte *data, word32 data_len, const byte *sig, word32 sig_len, const void *key, word32 key_len)
 This function validates a signature by hashing the data and using the resulting hash and key to verify the signature. More...
 
int wc_SignatureGenerate (enum wc_HashType hash_type, enum wc_SignatureType sig_type, const byte *data, word32 data_len, byte *sig, word32 *sig_len, const void *key, word32 key_len, WC_RNG *rng)
 This function generates a signature from the data using a key. It first creates a hash of the data then signs the hash using the key. More...
 

Detailed Description

Function Documentation

int wc_SignatureGenerate ( enum wc_HashType  hash_type,
enum wc_SignatureType  sig_type,
const byte *  data,
word32  data_len,
byte *  sig,
word32 *  sig_len,
const void *  key,
word32  key_len,
WC_RNG *  rng 
)

This function generates a signature from the data using a key. It first creates a hash of the data then signs the hash using the key.

Returns
0 Success
SIG_TYPE_E -231, signature type not enabled/ available
BAD_FUNC_ARG -173, bad function argument provided
BUFFER_E -132, output buffer too small or input too large.
Parameters
hash_typeA hash type from the “enum wc_HashType” such as “WC_HASH_TYPE_SHA256”.
sig_typeA signature type enum value such as WC_SIGNATURE_TYPE_ECC or WC_SIGNATURE_TYPE_RSA.
dataPointer to buffer containing the data to hash.
data_lenLength of the data buffer.
sigPointer to buffer to output signature.
sig_lenLength of the signature output buffer.
keyPointer to a key structure such as ecc_key or RsaKey.
key_lenSize of the key structure.
rngPointer to an initialized RNG structure.

Example

1 int ret;
2 WC_RNG rng;
3 ecc_key eccKey;
4 
5 wc_InitRng(&rng);
6 wc_ecc_init(&eccKey);
7 
8 // Generate key
9 ret = wc_ecc_make_key(&rng, 32, &eccKey);
10 
11 // Get signature length and allocate buffer
12 sigLen = wc_SignatureGetSize(sig_type, &eccKey, sizeof(eccKey));
13 sigBuf = malloc(sigLen);
14 
15 // Perform signature verification using public key
16 ret = wc_SignatureGenerate(
17  WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
18  fileBuf, fileLen,
19  sigBuf, &sigLen,
20  &eccKey, sizeof(eccKey),
21  &rng);
22 printf("Signature Generation: %s
23 (%d)\n", (ret == 0) ? "Pass" : "Fail", ret);
24 
25 free(sigBuf);
26 wc_ecc_free(&eccKey);
27 wc_FreeRng(&rng);
See also
wc_SignatureGetSize
wc_SignatureVerify
int wc_SignatureGetSize ( enum wc_SignatureType  sig_type,
const void *  key,
word32  key_len 
)

This function returns the maximum size of the resulting signature.

Returns
Returns SIG_TYPE_E if sig_type is not supported. Returns BAD_FUNC_ARG if sig_type was invalid. A positive return value indicates the maximum size of a signature.
Parameters
sig_typeA signature type enum value such as WC_SIGNATURE_TYPE_ECC or WC_SIGNATURE_TYPE_RSA.
keyPointer to a key structure such as ecc_key or RsaKey.
key_lenSize of the key structure.

Example

1 // Get signature length
2 enum wc_SignatureType sig_type = WC_SIGNATURE_TYPE_ECC;
3 ecc_key eccKey;
4 word32 sigLen;
5 wc_ecc_init(&eccKey);
6 sigLen = wc_SignatureGetSize(sig_type, &eccKey, sizeof(eccKey));
7 if (sigLen > 0) {
8  // Success
9 }
See also
wc_HashGetDigestSize
wc_SignatureGenerate
wc_SignatureVerify
int wc_SignatureVerify ( enum wc_HashType  hash_type,
enum wc_SignatureType  sig_type,
const byte *  data,
word32  data_len,
const byte *  sig,
word32  sig_len,
const void *  key,
word32  key_len 
)

This function validates a signature by hashing the data and using the resulting hash and key to verify the signature.

Returns
0 Success
SIG_TYPE_E -231, signature type not enabled/ available
BAD_FUNC_ARG -173, bad function argument provided
BUFFER_E -132, output buffer too small or input too large.
Parameters
hash_typeA hash type from the “enum wc_HashType” such as “WC_HASH_TYPE_SHA256”.
sig_typeA signature type enum value such as WC_SIGNATURE_TYPE_ECC or WC_SIGNATURE_TYPE_RSA.
dataPointer to buffer containing the data to hash.
data_lenLength of the data buffer.
sigPointer to buffer to output signature.
sig_lenLength of the signature output buffer.
keyPointer to a key structure such as ecc_key or RsaKey.
key_lenSize of the key structure.

Example

1 int ret;
2 ecc_key eccKey;
3 
4 // Import the public key
5 wc_ecc_init(&eccKey);
6 ret = wc_ecc_import_x963(eccPubKeyBuf, eccPubKeyLen, &eccKey);
7 // Perform signature verification using public key
8 ret = wc_SignatureVerify(
9 WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
10 fileBuf, fileLen,
11 sigBuf, sigLen,
12 &eccKey, sizeof(eccKey));
13 printf("Signature Verification: %s
14 (%d)\n", (ret == 0) ? "Pass" : "Fail", ret);
15 wc_ecc_free(&eccKey);
See also
wc_SignatureGetSize
wc_SignatureGenerate