SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
SharkSSL.h File Reference
#include "TargConfig.h"
#include <ThreadLib.h>
#include <BaServerLib.h>
#include "SharkSSL_cfg.h"
#include <psa/crypto.h>
#include <stddef.h>
#include "SharkSslCrypto.h"
#include "SingleList.h"
#include "DoubleList.h"

Go to the source code of this file.

Data Structures

struct  SharkSsl
 A SharkSsl object is the coordinator for managing SharkSslCon objects (See SharkSsl_constructor for details). More...
 
struct  SharkSslCertDN
 Certificate KeyUsage and ExtendedKeyUsage flags and relative pseudofunctions. More...
 
struct  SharkSslCertInfo
 The peer's certificate information returned by SharkSslCon_getCertInfo. More...
 
struct  SharkSslCertStore
 SharkSslCertStore is a container object used when assembling a SharkSslCAList. More...
 

Macros

#define SHARKDBG_PRINTF(x)
 
#define SHARKSSL_BA   1
 
#define SHARKSSL_ALERT_LEVEL_WARNING   1
 SSL/TLS warning message. More...
 
#define SHARKSSL_ALERT_LEVEL_FATAL   2
 Fatal error message. More...
 
#define SHARKSSL_ALERT_CLOSE_NOTIFY   0
 SHARKSSL_ALERT_CLOSE_NOTIFY. More...
 
#define SHARKSSL_ALERT_UNEXPECTED_MESSAGE   10
 SHARKSSL_ALERT_UNEXPECTED_MESSAGE. More...
 
#define SHARKSSL_ALERT_BAD_RECORD_MAC   20
 SHARKSSL_ALERT_BAD_RECORD_MAC. More...
 
#define SHARKSSL_ALERT_DECRYPTION_FAILED   21
 SHARKSSL_ALERT_DECRYPTION_FAILED. More...
 
#define SHARKSSL_ALERT_RECORD_OVERFLOW   22
 SHARKSSL_ALERT_RECORD_OVERFLOW. More...
 
#define SHARKSSL_ALERT_DECOMPRESSION_FAILURE   30
 SHARKSSL_ALERT_DECOMPRESSION_FAILURE. More...
 
#define SHARKSSL_ALERT_HANDSHAKE_FAILURE   40
 SHARKSSL_ALERT_HANDSHAKE_FAILURE. More...
 
#define SHARKSSL_ALERT_BAD_CERTIFICATE   42
 SHARKSSL_ALERT_BAD_CERTIFICATE. More...
 
#define SHARKSSL_ALERT_UNSUPPORTED_CERTIFICATE   43
 SHARKSSL_ALERT_UNSUPPORTED_CERTIFICATE. More...
 
#define SHARKSSL_ALERT_CERTIFICATE_REVOKED   44
 SHARKSSL_ALERT_CERTIFICATE_REVOKED. More...
 
#define SHARKSSL_ALERT_CERTIFICATE_EXPIRED   45
 SHARKSSL_ALERT_CERTIFICATE_EXPIRED. More...
 
#define SHARKSSL_ALERT_CERTIFICATE_UNKNOWN   46
 SHARKSSL_ALERT_CERTIFICATE_UNKNOWN. More...
 
#define SHARKSSL_ALERT_ILLEGAL_PARAMETER   47
 SHARKSSL_ALERT_ILLEGAL_PARAMETER. More...
 
#define SHARKSSL_ALERT_UNKNOWN_CA   48
 SHARKSSL_ALERT_UNKNOWN_CA. More...
 
#define SHARKSSL_ALERT_ACCESS_DENIED   49
 SHARKSSL_ALERT_ACCESS_DENIED. More...
 
#define SHARKSSL_ALERT_DECODE_ERROR   50
 SHARKSSL_ALERT_DECODE_ERROR. More...
 
#define SHARKSSL_ALERT_DECRYPT_ERROR   51
 SHARKSSL_ALERT_DECRYPT_ERROR. More...
 
#define SHARKSSL_ALERT_EXPORT_RESTRICTION   60
 SHARKSSL_ALERT_EXPORT_RESTRICTION. More...
 
#define SHARKSSL_ALERT_PROTOCOL_VERSION   70
 SHARKSSL_ALERT_PROTOCOL_VERSION. More...
 
#define SHARKSSL_ALERT_INSUFFICIENT_SECURITY   71
 SHARKSSL_ALERT_INSUFFICIENT_SECURITY. More...
 
#define SHARKSSL_ALERT_INTERNAL_ERROR   80
 SHARKSSL_ALERT_INTERNAL_ERROR. More...
 
#define SHARKSSL_ALERT_USER_CANCELED   90
 SHARKSSL_ALERT_USER_CANCELED. More...
 
#define SHARKSSL_ALERT_NO_RENEGOTIATION   100
 SHARKSSL_ALERT_NO_RENEGOTIATION. More...
 
#define SHARKSSL_ALERT_MISSING_EXTENSION   109
 SHARKSSL_ALERT_MISSING_EXTENSION. More...
 
#define SHARKSSL_ALERT_UNSUPPORTED_EXTENSION   110
 SHARKSSL_ALERT_UNSUPPORTED_EXTENSION. More...
 
#define SHARKSSL_ALERT_UNRECOGNIZED_NAME   112
 SHARKSSL_ALERT_UNRECOGNIZED_NAME. More...
 
#define SHARKSSL_ALERT_GENERAL_ERROR   117
 SHARKSSL_ALERT_GENERAL_ERROR. More...
 
#define SHARKSSL_ALERT_NO_APPLICATION_PROTOCOL   120 /* RFC 7301 */
 SHARKSSL_ALERT_NO_APPLICATION_PROTOCOL. More...
 
#define TLS_AES_128_GCM_SHA256   0x1301
 TLS_AES_128_GCM_SHA256. More...
 
#define TLS_AES_256_GCM_SHA384   0x1302
 TLS_AES_256_GCM_SHA384. More...
 
#define TLS_CHACHA20_POLY1305_SHA256   0x1303
 TLS_CHACHA20_POLY1305_SHA256. More...
 
#define TLS_DHE_RSA_WITH_AES_128_GCM_SHA256   0x009E
 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256. More...
 
#define TLS_DHE_RSA_WITH_AES_256_GCM_SHA384   0x009F
 TLS_DHE_RSA_WITH_AES_256_GCM_SHA384. More...
 
#define TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256   0xC02B
 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256. More...
 
#define TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384   0xC02C
 TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384. More...
 
#define TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256   0xC02F
 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256. More...
 
#define TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384   0xC030
 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384. More...
 
#define TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256   0xCCA8
 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256. More...
 
#define TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256   0xCCA9
 TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256. More...
 
#define TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256   0xCCAA
 TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256. More...
 
#define SHARKSSL_PROTOCOL_UNKNOWN   0x00
 SHARKSSL_PROTOCOL_UNKNOWN. More...
 
#define SHARKSSL_PROTOCOL_TLS_1_2   0x33
 SHARKSSL_PROTOCOL_TLS_1_2. More...
 
#define SHARKSSL_PROTOCOL_TLS_1_3   0x34
 SHARKSSL_PROTOCOL_TLS_1_3. More...
 
#define SHARKSSL_PROTOCOL_MAJOR(p)   (p >> 4)
 
#define SHARKSSL_PROTOCOL_MINOR(p)   (p & 0xF)
 
#define SharkSslCertDN_constructor(o)   memset(o,0,sizeof(SharkSslCertDN))
 SharkSslCertDN constructor. More...
 
#define SharkSslCertDN_setCountryName(o, countryNameMA)    (o)->countryName=(const U8*)countryNameMA,(o)->countryNameLen=(U8)strlen(countryNameMA)
 setCountryName More...
 
#define SharkSslCertDN_setProvince(o, provinceMA)    (o)->province=(const U8*)provinceMA,(o)->provinceLen=(U8)strlen(provinceMA)
 setProvince More...
 
#define SharkSslCertDN_setLocality(o, localityMA)    (o)->locality=(const U8*)localityMA,(o)->localityLen=(U8)strlen(localityMA)
 setLocality More...
 
#define SharkSslCertDN_setOrganization(o, organizationMA)    (o)->organization=(const U8*)organizationMA,(o)->organizationLen=(U8)strlen(organizationMA)
 setOrganization More...
 
#define SharkSslCertDN_setUnit(o, unitMA)    (o)->unit=(const U8*)unitMA,(o)->unitLen=(U8)strlen(unitMA)
 setUnit More...
 
#define SharkSslCertDN_setCommonName(o, commonNameMA)    (o)->commonName=(const U8*)commonNameMA,(o)->commonNameLen=(U8)strlen(commonNameMA)
 setCommonName More...
 
#define SharkSslCertDN_setEmailAddress(o, emailAddressMA)    (o)->emailAddress=(const U8*)emailAddressMA,(o)->emailAddressLen=(U8)strlen(emailAddressMA)
 setEmailAddress More...
 
#define SharkSsl_setIntf(o, sharkSslIntf)   (o)->intf=sharkSslIntf
 
#define SharkSsl_getIntf(o)   (o)->intf
 
#define SharkSslCon_terminate(o)   SharkSsl_terminateCon(0, o)
 The SharkSslCon object must be reclaimed when you close the network connection. More...
 
#define SHARKSSL_KEY_UPDATE_NOT_REQUESTED   0
 Updates the local write keys without requesting a reciprocal update of the peer's write keys. More...
 
#define SHARKSSL_KEY_UPDATE_REQUESTED   1
 Updates the local write keys and requests a reciprocal update of the peer's write keys. More...
 
#define SharkSslCon_getAlertData(o)   SharkSslCon_getEncData(o)
 This function is used in conjunction with state SharkSslCon_AlertSend returned by function SharkSslCon_encrypt. More...
 
#define SharkSslCon_getAlertDataLen(o)   SharkSslCon_getEncDataLen(o)
 This function is used in conjunction with state SharkSslCon_AlertSend returned by function SharkSslCon_encrypt. More...
 
#define SharkSsl_setCAList(o, caList)   SharkSsl_setCAListEx((o), (caList), 0)
 Install an application-trusted CA list without validating its allocation extent. More...
 
#define SHARKSSL_SET_FAVOR_RSA   1
 Enable RSA preference in SharkSslCon_favorRSA. More...
 
#define SHARKSSL_CLEAR_FAVOR_RSA   0
 Disable RSA preference in SharkSslCon_favorRSA. More...
 
#define SharkSslCon_requestClientCert(o, caList)   SharkSslCon_requestClientCertEx((o), (caList), 0)
 Request client authentication with an application-trusted CA list. More...
 
#define SharkSslCon_setCertificateAuthorities(o, caList)   SharkSslCon_setCertificateAuthoritiesEx((o), (caList), 0)
 Configure the extension with an application-trusted CA list. More...
 
#define SHARKSSL_RSA_NO_PADDING   0
 SHARKSSL_RSA_NO_PADDING for raw RSA encryption (insecure). More...
 
#define SHARKSSL_RSA_PKCS1_PADDING   1
 SHARKSSL_RSA_PKCS1_PADDING for PKCS #1 v1.5. More...
 
#define _SHARKSSLRSAKEY_FREE   1
 
#define SHARKSSL_EC_CURVE_ID_SECP256R1   23
 To be used as hashlen parameter in sharkssl_ECDSA_ functions These are the hash lengths for the functions implemented in SharkSSL/RayCrypto. More...
 
#define SHARKSSL_EC_CURVE_ID_SECP384R1   24
 
#define SHARKSSL_EC_CURVE_ID_SECP521R1   25
 
#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP256R1   26
 
#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP384R1   27
 
#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP512R1   28
 
#define SHARKSSL_EC_CURVE_ID_CURVE25519   29
 
#define SHARKSSL_EC_CURVE_ID_CURVE448   30
 
#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP256R1TLS13   31
 
#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP384R1TLS13   32
 
#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP512R1TLS13   33
 
#define SHARKSSL_X25519_KEY_LEN   32
 
#define SharkSslECCKey_create(privKey, curveID)   SharkSslECCKey_createEx((privKey), (curveID), 0, 0)
 A macro for creating an ECC key using the SharkSSL library. More...
 
#define _SHARKSSLECCKEY_FREE   1
 
#define SharkSslKey_free   SharkSslRSAKey_free
 
#define SharkSslCert_vectSize(c)   SharkSslKey_vectSize((const SharkSslCert)c)
 
#define SharkSslCert_vectSize_keyInfo(c, t, p, a, b, x, y)   SharkSslKey_vectSize_keyInfo((const SharkSslKey)c, t, p, a, b, x, y)
 
#define SharkSslRSAKey_vectSize(k)   SharkSslKey_vectSize(k)
 
#define SharkSslRSAKey_vectSize_keyInfo(k, t, p, a, b, x, y)   SharkSslKey_vectSize_keyInfo((const SharkSslKey)k, t, p, a, b, x, y)
 
#define SharkSslECCKey_vectSize(k)   SharkSslKey_vectSize(k)
 
#define SharkSslECCKey_vectSize_keyInfo(k, t, p, a, b, x, y)   SharkSslKey_vectSize_keyInfo((const SharkSslKey)k, t, p, a, b, x, y)
 
#define SHARKSSL_KEYTYPE_RSA   0x00
 
#define SHARKSSL_KEYTYPE_EC   0x02
 
#define SharkSslCertStore_release(o)   SharkSslCertStore_destructor(o)
 Alias for SharkSslCertStore_destructor. More...
 

Typedefs

typedef struct SharkSslSession SharkSslSession
 SharkSslSession is an opaque handle returned by function SharkSslCon_acquireSession. More...
 
typedef U8 * SharkSslKey
 The SharkSslKey type. More...
 
typedef const U8 * SharkSslCert
 The SharkSSL Certificate is in a binary format optimized for speed and size. More...
 
typedef const U8 * SharkSslCAList
 The SharkSSL Certificate Authority (CA) List is in a binary format optimized for speed and size. More...
 
typedef struct SharkSslCon SharkSslCon
 SharkSslCon is an opaque handle returned by function SharkSsl_createCon. More...
 
typedef struct SharkSsl SharkSsl
 A SharkSsl object is the coordinator for managing SharkSslCon objects (See SharkSsl_constructor for details). More...
 
typedef U16 SharkSslSANLen
 Preserve 16-bit Subject Alternative Name lengths unless the configured handshake limit permits a certificate containing a larger extension. More...
 
typedef struct SharkSslCertDN SharkSslCertDN
 Certificate KeyUsage and ExtendedKeyUsage flags and relative pseudofunctions. More...
 
typedef struct SharkSslCertInfo SharkSslCertInfo
 The peer's certificate information returned by SharkSslCon_getCertInfo. More...
 
typedef int(* ALPNFunction) (SharkSslCon *, const char *, void *)
 
typedef U8 * SharkSslRSAKey
 SharkSslRSAKey is an alias for the SharkSslCert type and is a private/public key converted by sharkssl_PEM_to_RSAKey or the command line tool SharkSslParseKey. More...
 
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. More...
 
typedef int(* sharkssl_rngfunc) (void *handle, U8 *ptr, U16 len)
 
typedef struct SharkSslCertStore SharkSslCertStore
 SharkSslCertStore is a container object used when assembling a SharkSslCAList. More...
 

Enumerations

enum  SharkSsl_Role { SharkSsl_Unspecified , SharkSsl_Server , SharkSsl_Client }
 Select one of client or server mode when creating a SharkSsl object. More...
 
enum  SharkSslCon_RetVal {
  SharkSslCon_Error = 1 , SharkSslCon_AllocationError , SharkSslCon_Decrypted , SharkSslCon_Handshake ,
  SharkSslCon_NeedMoreData , SharkSslCon_AlertSend , SharkSslCon_AlertRecv , SharkSslCon_Encrypted ,
  SharkSslCon_HandshakeNotComplete , SharkSslCon_CertificateError
}
 The SharkSslCon_decrypt and SharkSslCon_encrypt return values. More...
 
enum  sharkssl_PEM_RetVal {
  SHARKSSL_PEM_OK = 0 , SHARKSSL_PEM_OK_PUBLIC = 1 , SHARKSSL_PEM_ALLOCATION_ERROR = - 3000 , SHARKSSL_PEM_KEY_PARSE_ERROR ,
  SHARKSSL_PEM_KEY_WRONG_IV , SHARKSSL_PEM_KEY_WRONG_LENGTH , SHARKSSL_PEM_KEY_PASSPHRASE_REQUIRED , SHARKSSL_PEM_KEY_UNRECOGNIZED_FORMAT ,
  SHARKSSL_PEM_KEY_UNSUPPORTED_FORMAT , SHARKSSL_PEM_KEY_UNSUPPORTED_MODULUS_LENGTH , SHARKSSL_PEM_KEY_UNSUPPORTED_EXPONENT_LENGTH , SHARKSSL_PEM_KEY_UNSUPPORTED_ENCRYPTION_TYPE ,
  SHARKSSL_PEM_KEY_CERT_MISMATCH , SHARKSSL_PEM_CERT_UNRECOGNIZED_FORMAT , SHARKSSL_PEM_CERT_UNSUPPORTED_TYPE , SHARKSSL_PEM_KEY_UNSUPPORTED_VERSION ,
  SHARKSSL_PEM_KEY_REQUIRED , SHARKSSL_PEM_KEY_PRIVATE_KEY_REQUIRED , SHARKSSL_PEM_INTERNAL_ERROR
}
 Return values from function sharkssl_PEM. More...
 
enum  sharkssl_RSA_RetVal {
  SHARKSSL_RSA_OK = 0 , SHARKSSL_RSA_ALLOCATION_ERROR = -3000 , SHARKSSL_RSA_INTERNAL_ERROR = -3100 , SHARKSSL_RSA_WRONG_PARAMETERS ,
  SHARKSSL_RSA_WRONG_KEY_FORMAT , SHARKSSL_RSA_WRONG_KEY_LENGTH , SHARKSSL_RSA_INPUT_DATA_LENGTH_TOO_BIG , SHARKSSL_RSA_INPUT_DATA_LENGTH_AND_KEY_LENGTH_MISMATCH ,
  SHARKSSL_RSA_PKCS1_PADDING_ERROR , SHARKSSL_RSA_KEY_NOT_PRIVATE , SHARKSSL_RSA_VERIFICATION_FAIL , SHARKSSL_RSA_WRONG_SIGNATURE ,
  SHARKSSL_RSA_WRONG_LABEL_LENGTH
}
 Return values from functions sharkssl_RSA_public_encrypt, sharkssl_RSA_private_decrypt, sharkssl_RSA_public_decrypt, sharkssl_RSA_private_encrypt, sharkssl_RSA_PKCS1V1_5_sign_hash, sharkssl_RSA_PKCS1V1_5_verify_hash. More...
 
enum  sharkssl_ECDSA_RetVal {
  SHARKSSL_ECDSA_OK = 0 , SHARKSSL_ECDSA_ALLOCATION_ERROR = -3200 , SHARKSSL_ECDSA_INTERNAL_ERROR = -3300 , SHARKSSL_ECDSA_WRONG_PARAMETERS ,
  SHARKSSL_ECDSA_WRONG_KEY_FORMAT , SHARKSSL_ECDSA_KEY_NOT_PRIVATE , SHARKSSL_ECDSA_KEY_NOT_PUBLIC , SHARKSSL_ECDSA_SIGLEN_TOO_SMALL ,
  SHARKSSL_ECDSA_VERIFICATION_FAIL , SHARKSSL_ECDSA_WRONG_SIGNATURE
}
 Return values from functions sharkssl_ECDSA_sign_hash, sharkssl_ECDSA_verify_hash. More...
 

Functions

SHARKSSL_API U16 SharkSslCert_len (SharkSslCert cert)
 Get certificate length. More...
 
U32 baGetUnixTime (void)
 Platform dependent function returning seconds since Jan 1 1970. More...
 
SHARKSSL_API int SharkSslASN1Create_CSR (struct SharkSslASN1Create *o, SharkSslKey privKey, U8 hashID, struct SharkSslCertDN *certDN, const char *SAN, struct SharkSslBitExtReq *keyUsage, struct SharkSslBitExtReq *nsCertType)
 CSR creation (all parameters are input parameters) More...
 
SHARKSSL_API int SharkSslASN1Create_key (struct SharkSslASN1Create *o, const SharkSslKey key)
 CSR signing policy and SharkSslCert_signCSR are declared in SharkSslCSR.h. More...
 
SHARKSSL_API void * sharkssl_mallocObject (size_t size)
 
SHARKSSL_API void sharkssl_freeObject (void *object)
 
SHARKSSL_API void SharkSsl_constructor (SharkSsl *o, SharkSsl_Role role, U16 cacheSize, U16 inBufStartSize, U16 outBufSize)
 A SharkSsl object is the coordinator for managing SharkSslCon objects. More...
 
SHARKSSL_API void SharkSsl_destructor (SharkSsl *o)
 Close the SharkSsl object. More...
 
SharkSslCon * SharkSsl_createCon (SharkSsl *o)
 Create a SharkSslCon object. More...
 
void SharkSsl_terminateCon (const SharkSsl *o, SharkSslCon *con)
 Terminate a SharkSslCon object created by function SharkSsl_createCon. More...
 
SHARKSSL_API U16 SharkSsl_getCacheSize (SharkSsl *o)
 Returns the SharkSsl session cache size. More...
 
SharkSslCon_RetVal SharkSslCon_decrypt (SharkSslCon *o, U16 readLen)
 Decrypt the received data copied into the SharkSslCon receive buffer (the buffer returned by SharkSslCon_getBuf). More...
 
SharkSslCon_RetVal SharkSslCon_encrypt (SharkSslCon *o, U8 *buf, U16 maxLen)
 Encrypt the data provided by parameter 'buf' or encrypt data in the SharkSslCon send buffer. More...
 
SHARKSSL_API SharkSslCon_RetVal SharkSslCon_close (SharkSslCon *o)
 Generates a close_notify alert and closes the local write direction. More...
 
SHARKSSL_API U8 SharkSslCon_keyUpdate (SharkSslCon *o, U8 requestUpdate)
 Creates a TLS 1.3 KeyUpdate message and advances the local write keys. More...
 
SHARKSSL_API int SharkSslCon_proactiveKeyUpdate (SharkSslCon *o)
 Apply the automatic AES-GCM KeyUpdate policy while the output buffer is free. More...
 
U8 SharkSslCon_isHandshakeComplete (SharkSslCon *o)
 Returns the following values: More...
 
U8 SharkSslCon_encryptMore (SharkSslCon *o)
 This function is used in conjunction with state SharkSslCon_Encrypted returned by function SharkSslCon_encrypt. More...
 
U8 SharkSslCon_decryptMore (SharkSslCon *o)
 This function is used in conjunction with state SharkSslCon_Decrypted returned by function SharkSslCon_decrypt. More...
 
U8 * SharkSslCon_getBuf (SharkSslCon *o)
 Returns a pointer to the SharkSslCon input/receive buffer. More...
 
U16 SharkSslCon_getBufLen (SharkSslCon *o)
 Returns the number of bytes currently available at the pointer returned by SharkSslCon_getBuf. More...
 
U16 SharkSslCon_copyDecData (SharkSslCon *o, U8 *buf, U16 maxLen)
 Copy decoded data to 'buf'. More...
 
SHARKSSL_API U16 SharkSslCon_getDecData (SharkSslCon *o, U8 **bufPtr)
 Get a pointer to the decoded data. More...
 
U8 * SharkSslCon_getHandshakeData (SharkSslCon *o)
 This function is used in conjunction with state SharkSslCon_Handshake returned by function SharkSslCon_encrypt. More...
 
U16 SharkSslCon_getHandshakeDataLen (SharkSslCon *o)
 This function is used in conjunction with state SharkSslCon_Handshake returned by function SharkSslCon_decrypt. More...
 
U16 SharkSslCon_setHandshakeDataSent (SharkSslCon *o, U16 length)
 This function is used in conjunction with SharkSslCon_getHandshakeData. More...
 
U8 * SharkSslCon_getEncData (SharkSslCon *o)
 This function is used in conjunction with state SharkSslCon_Encrypted returned by function SharkSslCon_encrypt. More...
 
U16 SharkSslCon_getEncDataLen (SharkSslCon *o)
 This function is used in conjunction with state SharkSslCon_Encrypted returned by function SharkSslCon_encrypt. More...
 
U8 * SharkSslCon_getEncBufPtr (SharkSslCon *o)
 This function is used in conjunction with SharkSslCon_encrypt when using the zero copy send API. More...
 
U16 SharkSslCon_getEncBufSize (SharkSslCon *o)
 Returns the length of the buffer returned by SharkSslCon_getEncBufPtr. More...
 
U8 SharkSslCon_getAlertLevel (SharkSslCon *o)
 This function is used in conjunction with state SharkSslCon_AlertSend returned by function SharkSslCon_encrypt or in conjunction with state SharkSslCon_AlertRecv returned by function SharkSslCon_decrypt. More...
 
U8 SharkSslCon_getAlertDescription (SharkSslCon *o)
 This function is used in conjunction with state SharkSslCon_AlertSend returned by function SharkSslCon_encrypt or in conjunction with state SharkSslCon_AlertRecv returned by function SharkSslCon_decrypt. More...
 
SHARKSSL_API U16 SharkSslCon_getCiphersuite (SharkSslCon *o)
 Returns the active session's chiper suite. More...
 
SHARKSSL_API U8 SharkSslCon_getProtocol (SharkSslCon *o)
 Returns the active session's protocol version. More...
 
SHARKSSL_API U8 SharkSslCon_setSNI (SharkSslCon *o, const char *name, U16 length)
 set Server Name Indication for TLS client connections More...
 
U8 SharkSslCon_certificateRequested (SharkSslCon *o)
 Returns TRUE if the server requested a certificate from the client to verify that the client's identity (authentication) More...
 
SHARKSSL_API SharkSslCertInfo * SharkSslCon_getCertInfo (SharkSslCon *o)
 Returns the peer's certificate if the handshaking has completed. More...
 
SHARKSSL_API int SharkSslCertInfo_parseCert (SharkSslCertInfo *o, const U8 *der, U32 len)
 Parse a DER certificate and return its certificate information. More...
 
SHARKSSL_API U8 SharkSsl_addCertificate (SharkSsl *o, SharkSslCert cert)
 Add a certificate to the SharkSsl object. More...
 
SHARKSSL_API U8 SharkSsl_addCertificatePSA (SharkSsl *o, SharkSslCert cert, psa_key_id_t psaKey)
 Add an RSA, EC, or EdDSA certificate with a provider-owned private signing key. More...
 
SHARKSSL_API U8 SharkSslCon_selectCertificatePSA (SharkSslCon *o, SharkSslCert cert)
 Select one PSA certificate already registered on this connection's SharkSsl object. More...
 
SHARKSSL_API U8 SharkSsl_setCAListEx (SharkSsl *o, SharkSslCAList caList, U32 caListLen)
 Set a Certificate Authority (CA) list so the SharkSSL object can perform certificate validation on the peer's certificate. More...
 
SHARKSSL_API U8 SharkSslCon_trustedCA (SharkSslCon *o)
 Returns TRUE if the certificate is valid and is signed with a root certificate trusted by SharkSSL. More...
 
U8 SharkSslCon_isCAListEmpty (SharkSslCon *o)
 
U8 SharkSslCon_favorRSA (SharkSslCon *o, U8 flag)
 Configures TLS 1.2 cipher-suite selection to favor RSA-authenticated suites when both RSA and ECDSA certificates are available. More...
 
U8 SharkSslCon_selectProtocol (SharkSslCon *o, U8 protocol)
 
SHARKSSL_API U8 SharkSslCon_isResumed (SharkSslCon *o)
 Returns 1 if the current session is a resumed one. More...
 
SHARKSSL_API U8 SharkSslSession_release (SharkSslSession *o, SharkSsl *s)
 Release a session created by function SharkSslCon_acquireSession. More...
 
SHARKSSL_API U8 SharkSslCon_releaseSession (SharkSslCon *o)
 experimental More...
 
SHARKSSL_API SharkSslSession * SharkSslCon_acquireSession (SharkSslCon *o)
 Request a SharkSslSession object from the client's session pool. More...
 
SHARKSSL_API U8 SharkSslCon_resumeSession (SharkSslCon *o, SharkSslSession *s)
 Resume an existing session. More...
 
SHARKSSL_API U32 SharkSslSession_getLatestAccessTime (SharkSslSession *o)
 Returns the last time the session was accessed. More...
 
SHARKSSL_API U8 SharkSslCon_requestClientCertEx (SharkSslCon *o, const void *caList, U32 caListLen)
 Request client-certificate authentication. More...
 
SHARKSSL_API U8 SharkSslCon_setCertificateAuthoritiesEx (SharkSslCon *o, const void *caList, U32 caListLen)
 Configure the TLS 1.3 Certificate Authorities extension specified in RFC 9846, Section 4.2.4. More...
 
SHARKSSL_API U8 SharkSslCon_setALPNProtocols (SharkSslCon *o, const char *protList)
 This function is used by client solutions to specify a list of application layer protocols according to RFC 7301 (ALPN). More...
 
SHARKSSL_API const char * SharkSslCon_getALPNProtocol (SharkSslCon *o)
 This function is used by client solutions to return the application layer protocol selected by the server among the ones specified through SharkSslCon_setALPNProtocols. More...
 
SHARKSSL_API U8 SharkSslCon_setALPNFunction (SharkSslCon *o, ALPNFunction func, void *pvoid)
 
SHARKSSL_API U8 SharkSslCon_selectCiphersuite (SharkSslCon *o, U16 cipherSuite)
 This function enables you to limit the number of ciphers at runtime. More...
 
SHARKSSL_API U8 SharkSslCon_clearCiphersuiteSelection (SharkSslCon *o)
 Clears the selection, thus enabling all ciphers. More...
 
SHARKSSL_API U8 SharkSslCon_renegotiate (SharkSslCon *o)
 This function enables you to renegotiate an already established SSL/TLS connection. More...
 
SHARKSSL_API sharkssl_PEM_RetVal sharkssl_PEM (const char *certPEM, const char *keyPEM, const char *passphrase, SharkSslCert *sharkSslCert)
 Create a SharkSslCert from PEM data. More...
 
SHARKSSL_API int sharkssl_PEM_PBKDF2 (U8 *dk, const char *passphrase, const char *salt, U32 saltLen, U32 iterations, U16 dkLen, U8 hashID)
 sharkssl_PEM_PBKDF2 (output, passphrase, salt, salt_len, iterations, dkLen, hashID) Derives a key from a passphrase using the PBKDF2 algorithm as specified in RFC 8018 section 5.2. More...
 
SHARKSSL_API SharkSslRSAKey sharkssl_PEM_to_RSAKey (const char *PEMKey, const char *passphrase)
 Convert an RSA private or public key in PEM format to the SharkSslRSAKey format. More...
 
SHARKSSL_API SharkSslKey sharkssl_PEM_extractPublicKey (const char *certPEM)
 Extract the public key form a certificate in PEM format. More...
 
SHARKSSL_API SharkSslKey sharkssl_PEM_extractPublicKey_ext (const char *certPEM, U8 *keyType)
 
SHARKSSL_API void SharkSslRSAKey_free (SharkSslRSAKey key)
 Release a SharkSslRSAKey allocated by functions sharkssl_PEM_to_RSAKey and sharkssl_PEM_extractPublicKey. More...
 
SHARKSSL_API int SharkSslRSAKey_create (SharkSslRSAKey *privKey, U16 keyLength)
 RSA key creation. More...
 
SHARKSSL_API U8 * SharkSslRSAKey_getPublic (SharkSslRSAKey privKey)
 RSA public key extraction from a private key. More...
 
SHARKSSL_API U16 SharkSslRSAKey_size (SharkSslRSAKey key)
 Returns the private or public key's modulus size in bytes. More...
 
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_public_encrypt (SharkSslRSAKey pubkey, const U8 *in, int len, U8 *out, int padding)
 Encrypt data using the public key or private key. More...
 
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_private_decrypt (SharkSslRSAKey privkey, const U8 *in, int len, U8 *out, int padding)
 Decrypt ciphertext using the private key. More...
 
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_PKCS1V1_5_sign_hash (SharkSslRSAKey privkey, U8 *sig, U16 *siglen, const U8 *hash, U8 hashID)
 Sign a hash using a private RSA key. More...
 
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_PKCS1V1_5_verify_hash (SharkSslRSAKey pubkey, U8 *sig, U16 siglen, const U8 *hash, U8 hashID)
 Verify a signature hash using a public RSA key. More...
 
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_private_decrypt_OAEP (SharkSslRSAKey privkey, U8 *in, int len, U8 hashID, U8 *out, const char *label, U16 labelLen)
 Decrypt ciphertext using the private key, padding is OAEP per RFC 8017. More...
 
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_public_encrypt_OAEP (SharkSslRSAKey pubkey, const U8 *in, int len, U8 hashID, U8 *out, const char *label, U16 labelLen)
 Encrypt cleartext using the public key, padding is OAEP per RFC 8017. More...
 
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_private_encrypt (SharkSslRSAKey privkey, const U8 *in, int len, U8 *out, int padding)
 Sign a message digest using the private key. More...
 
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_public_decrypt (SharkSslRSAKey pubkey, const U8 *in, int len, U8 *out, int padding)
 Bring back a message digest using the public key or private key. More...
 
SHARKSSL_API int sharkssl_X25519_createKeyPair (U8 privateKey[SHARKSSL_X25519_KEY_LEN], U8 publicKey[SHARKSSL_X25519_KEY_LEN])
 Create an X25519 private/public key pair. More...
 
SHARKSSL_API int sharkssl_X25519_sharedSecret (const U8 privateKey[SHARKSSL_X25519_KEY_LEN], const U8 peerPublicKey[SHARKSSL_X25519_KEY_LEN], U8 sharedSecret[SHARKSSL_X25519_KEY_LEN])
 Calculate an X25519 shared secret. More...
 
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 int SharkSslECCKey_createEx (SharkSslECCKey *privKey, U16 curveID, void *rngHandle, sharkssl_rngfunc rngFunc)
 Creates an ECC key using the SharkSSL library. More...
 
SHARKSSL_API void SharkSslECCKey_free (SharkSslECCKey key)
 Release a SharkSslECCKey allocated by functions sharkssl_PEM_to_ECCKey or SharkSslECCKey_create. 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, const U8 *hash, U8 hashID)
 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, const U8 *hash, U8 hashID)
 Verify a message using the ECC public key and a hash algorithm. More...
 
SHARKSSL_API U16 SharkSslKey_vectSize (const SharkSslKey key)
 Returns the private or public key's "vector size" in bytes. More...
 
SHARKSSL_API U16 SharkSslKey_vectSize_keyInfo (const SharkSslKey key, U8 *keyType, U8 *isKeyPrivate, U8 **d1, U16 *d1Len, U8 **d2, U16 *d2Len)
 Returns the private or public key's "vector size" in bytes. More...
 
SHARKSSL_API void SharkSslCertStore_constructor (SharkSslCertStore *o)
 Initialize a SharkSslCertStore object. More...
 
SHARKSSL_API void SharkSslCertStore_destructor (SharkSslCertStore *o)
 Cleanup all memory used by the SharkSslCAList object. More...
 
SHARKSSL_API U16 SharkSslCertStore_add (SharkSslCertStore *o, const char *cert, U32 certlen)
 Add one or more certificates to the CA store. More...
 
SHARKSSL_API U8 SharkSslCertStore_assemble (SharkSslCertStore *o, SharkSslCAList *outList)
 Assemble all certificates added by calling SharkSslCertStore_add. More...
 
SHARKSSL_API U32 sharkssl_B64Decode (U8 *outStr, U32 outStrSize, const char *b64beg, const char *b64end)
 

Detailed Description

TLS objects, certificate/session operations, and public-key interfaces.

See Choose a SharkSSL API for the complete header map and Manage a TLS Connection for object ownership, transport integration, and error conventions.

Macro Definition Documentation

◆ _SHARKSSLECCKEY_FREE

#define _SHARKSSLECCKEY_FREE   1

◆ SHARKDBG_PRINTF

#define SHARKDBG_PRINTF (   x)

◆ SHARKSSL_BA

#define SHARKSSL_BA   1

◆ SHARKSSL_EC_CURVE_ID_BRAINPOOLP256R1

#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP256R1   26

◆ SHARKSSL_EC_CURVE_ID_BRAINPOOLP256R1TLS13

#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP256R1TLS13   31

◆ SHARKSSL_EC_CURVE_ID_BRAINPOOLP384R1

#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP384R1   27

◆ SHARKSSL_EC_CURVE_ID_BRAINPOOLP384R1TLS13

#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP384R1TLS13   32

◆ SHARKSSL_EC_CURVE_ID_BRAINPOOLP512R1

#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP512R1   28

◆ SHARKSSL_EC_CURVE_ID_BRAINPOOLP512R1TLS13

#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP512R1TLS13   33

◆ SHARKSSL_EC_CURVE_ID_CURVE25519

#define SHARKSSL_EC_CURVE_ID_CURVE25519   29

◆ SHARKSSL_EC_CURVE_ID_CURVE448

#define SHARKSSL_EC_CURVE_ID_CURVE448   30

◆ SHARKSSL_EC_CURVE_ID_SECP256R1

#define SHARKSSL_EC_CURVE_ID_SECP256R1   23

To be used as hashlen parameter in sharkssl_ECDSA_ functions These are the hash lengths for the functions implemented in SharkSSL/RayCrypto.

SHARKSSL_MD5_HASH_LEN SHARKSSL_SHA1_HASH_LEN SHARKSSL_SHA256_HASH_LEN 16SHARKSSL_SHA384_HASH_LEN SHARKSSL_SHA512_HASH_LEN SHARKSSL_POLY1305_HASH_LEN

◆ SHARKSSL_EC_CURVE_ID_SECP384R1

#define SHARKSSL_EC_CURVE_ID_SECP384R1   24

◆ SHARKSSL_EC_CURVE_ID_SECP521R1

#define SHARKSSL_EC_CURVE_ID_SECP521R1   25

◆ SHARKSSL_KEYTYPE_EC

#define SHARKSSL_KEYTYPE_EC   0x02

◆ SHARKSSL_KEYTYPE_RSA

#define SHARKSSL_KEYTYPE_RSA   0x00

◆ SHARKSSL_X25519_KEY_LEN

#define SHARKSSL_X25519_KEY_LEN   32

◆ SharkSslCert_vectSize

#define SharkSslCert_vectSize (   c)    SharkSslKey_vectSize((const SharkSslCert)c)

◆ SharkSslCert_vectSize_keyInfo

#define SharkSslCert_vectSize_keyInfo (   c,
  t,
  p,
  a,
  b,
  x,
  y 
)    SharkSslKey_vectSize_keyInfo((const SharkSslKey)c, t, p, a, b, x, y)

◆ SharkSslECCKey_vectSize

#define SharkSslECCKey_vectSize (   k)    SharkSslKey_vectSize(k)

◆ SharkSslECCKey_vectSize_keyInfo

#define SharkSslECCKey_vectSize_keyInfo (   k,
  t,
  p,
  a,
  b,
  x,
  y 
)    SharkSslKey_vectSize_keyInfo((const SharkSslKey)k, t, p, a, b, x, y)

◆ SharkSslKey_free

#define SharkSslKey_free   SharkSslRSAKey_free

◆ SharkSslRSAKey_vectSize

#define SharkSslRSAKey_vectSize (   k)    SharkSslKey_vectSize(k)

◆ SharkSslRSAKey_vectSize_keyInfo

#define SharkSslRSAKey_vectSize_keyInfo (   k,
  t,
  p,
  a,
  b,
  x,
  y 
)    SharkSslKey_vectSize_keyInfo((const SharkSslKey)k, t, p, a, b, x, y)

Typedef Documentation

◆ sharkssl_rngfunc

typedef int(* sharkssl_rngfunc) (void *handle, U8 *ptr, U16 len)

◆ SharkSslSANLen

typedef U16 SharkSslSANLen

Preserve 16-bit Subject Alternative Name lengths unless the configured handshake limit permits a certificate containing a larger extension.

Function Documentation

◆ sharkssl_B64Decode()

SHARKSSL_API U32 sharkssl_B64Decode ( U8 *  outStr,
U32  outStrSize,
const char *  b64beg,
const char *  b64end 
)