SharkSSL™ Embedded SSL/TLS Stack
ECDSA sign/verify functions

Detailed Description

See Signing and Verifying Binaries for an example of how to use the ECDSA ECDSA sign/verify functions.

Typedefs

typedef U8 * SharkSslECCKey
 SharkSslECCKey is an alias for the SharkSslCert type and is a private/public key converted by sharkssl_PEM_to_ECCKey or the command line tool SharkSslParseKey.
 

Functions

SHARKSSL_API SharkSslECCKey sharkssl_PEM_to_ECCKey (const char *PEMKey, const char *passphrase)
 Convert an ECC private or public key in PEM format to the SharkSslECCKey format. More...
 
SHARKSSL_API U16 sharkssl_ECDSA_siglen (SharkSslECCKey privkey)
 Returns the maximum length (in bytes) of a DER-encoded ECDSA signature generated with the private key 'privkey'. More...
 
SHARKSSL_API sharkssl_ECDSA_RetVal sharkssl_ECDSA_sign_hash (SharkSslECCKey privkey, U8 *sig, U16 *siglen, U8 *hash, U8 hashlen)
 Generate the signature using the ECC private key and a hash. More...
 
SHARKSSL_API sharkssl_ECDSA_RetVal sharkssl_ECDSA_verify_hash (SharkSslECCKey pubkey, U8 *sig, U16 siglen, U8 *hash, U8 hashlen)
 Verify a message using the ECC public key and a hash algorithm. More...
 

Function Documentation

◆ sharkssl_ECDSA_siglen()

SHARKSSL_API U16 sharkssl_ECDSA_siglen ( SharkSslECCKey  privkey)

Returns the maximum length (in bytes) of a DER-encoded ECDSA signature generated with the private key 'privkey'.

This function is typically used in combination with sharkssl_ECDSA_sign_hash to compute the maximum length of the signature and to allocate a buffer large enough to hold the signature 'sig'.

Parameters
privkeyis the private key in SharkSslECCKey format.

◆ sharkssl_ECDSA_sign_hash()

SHARKSSL_API sharkssl_ECDSA_RetVal sharkssl_ECDSA_sign_hash ( SharkSslECCKey  privkey,
U8 *  sig,
U16 *  siglen,
U8 *  hash,
U8  hashlen 
)

Generate the signature using the ECC private key and a hash.

Parameters
privkeyis the private key in SharkSslECCKey format.
sigis a pointer to the buffer where the DER-encoded ECDSA signature will be generated. The size of this buffer must not be smaller than the value returned by sharkssl_ECDSA_siglen for param 'privkey'. The length of this buffer, which may be larger than required, is provided in the next parameter (siglen).
siglenis parameter "sig"'s length and is provided as an input parameter. The signature length will be returned as output parameter.
hashthe message digest obtained from a hash function e.g. SHA256.
hashlenthe length of the message digest (see above).
Returns
SHARKSSL_ECDSA_OK if the signature generation is successful, or one of the sharkssl_ECDSA_RetVal error codes.

◆ sharkssl_ECDSA_verify_hash()

SHARKSSL_API sharkssl_ECDSA_RetVal sharkssl_ECDSA_verify_hash ( SharkSslECCKey  pubkey,
U8 *  sig,
U16  siglen,
U8 *  hash,
U8  hashlen 
)

Verify a message using the ECC public key and a hash algorithm.

Parameters
pubkeyis the public key in SharkSslECCKey format.
sigis a pointer to the DER-encoded ECDSA signature that is to be verified.
siglenis parameter "sig"'s length.
hashthe message digest obtained from a hash function e.g. SHA256.
hashlenthe length of the message digest (see above).
Returns
SHARKSSL_ECDSA_OK if the signature verification is successful, or one of the sharkssl_ECDSA_RetVal error codes.

◆ sharkssl_PEM_to_ECCKey()

SHARKSSL_API SharkSslECCKey sharkssl_PEM_to_ECCKey ( const char *  PEMKey,
const char *  passphrase 
)

Convert an ECC private or public key in PEM format to the SharkSslECCKey format.

Note: the converted value must be released by calling SharkSslECCKey_free, when no longer needed.

example:

{
SharkSslECCKey ECCKey;
...
ECCKey = sharksslPEM_to_ECCKey(key, pass);
if (ECCKey)
{
...
void SharkSslECCKey_free(ECCKey);
}
}
U8 * SharkSslECCKey
SharkSslECCKey is an alias for the SharkSslCert type and is a private/public key converted by sharkss...
Definition: SharkSSL.h:2197
SHARKSSL_API void SharkSslECCKey_free(SharkSslECCKey key)
Release a SharkSslECCKey allocated by functions sharkssl_PEM_to_ECCKey or #SharkSslECCKey_create.
Returns
the private/public key in SharkSslECCKey format or NULL if the conversion fails.