This package includes the SharkSSL lite library and header files.

Dependents:   WebSocket-Client-Example SharkMQ-LED-Demo

Embed: (wiki syntax)

« Back to documentation index

ECDSA sign/verify functions

ECDSA sign/verify functions
[RayCryptoApi]

See [Signing and Verifying Binaries](signing) for an example of how to use the ECDSA ECDSA sign/verify functions. More...

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](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.
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'.
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.
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.

Detailed Description

See [Signing and Verifying Binaries](signing) for an example of how to use the ECDSA ECDSA sign/verify functions.


Typedef Documentation

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](SharkSslParseKey).

Definition at line 1833 of file SharkSSL.h.


Function Documentation

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_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 succesful, or one of the sharkssl_ECDSA_RetVal error codes.
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 succesful, or one of the sharkssl_ECDSA_RetVal error codes.
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);
      }
   }
Returns:
the private/public key in SharkSslECCKey format or NULL if the conversion fails.