SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
SharkSslPSADriver.h File Reference
#include "psa/crypto.h"

Go to the source code of this file.

Data Structures

struct  SharkSslPSAKeyDriver
 Optional opaque-key driver for volatile HMAC, PASSWORD and PEPPER keys. More...
 

Macros

#define SHARKSSL_PSA_DRIVER_LOCATION_VENDOR_MIN   ((psa_key_location_t)0x800000)
 
#define SHARKSSL_PSA_DRIVER_LOCATION_VENDOR_MAX   ((psa_key_location_t)0xffffff)
 
#define SHARKSSL_PSA_DRIVER_HANDLE_NULL   ((uint64_t)0)
 
#define SHARKSSL_PSA_DRIVER_OPERATION_HANDLE_NULL   ((uint64_t)0)
 
#define SHARKSSL_PSA_DRIVER_MAX_LOCATIONS   4
 

Typedefs

typedef struct SharkSslPSAKeyDriver SharkSslPSAKeyDriver
 Optional opaque-key driver for volatile HMAC, PASSWORD and PEPPER keys. More...
 

Functions

psa_status_t SharkSslPSAKeyDriver_set (const SharkSslPSAKeyDriver *o, psa_key_location_t location)
 Register or replace one location; pass NULL to unregister it. More...
 

Detailed Description

See Choose a SharkSSL API for build scope and the owning API layer.

Macro Definition Documentation

◆ SHARKSSL_PSA_DRIVER_HANDLE_NULL

#define SHARKSSL_PSA_DRIVER_HANDLE_NULL   ((uint64_t)0)

◆ SHARKSSL_PSA_DRIVER_LOCATION_VENDOR_MAX

#define SHARKSSL_PSA_DRIVER_LOCATION_VENDOR_MAX   ((psa_key_location_t)0xffffff)

◆ SHARKSSL_PSA_DRIVER_LOCATION_VENDOR_MIN

#define SHARKSSL_PSA_DRIVER_LOCATION_VENDOR_MIN   ((psa_key_location_t)0x800000)

◆ SHARKSSL_PSA_DRIVER_MAX_LOCATIONS

#define SHARKSSL_PSA_DRIVER_MAX_LOCATIONS   4

◆ SHARKSSL_PSA_DRIVER_OPERATION_HANDLE_NULL

#define SHARKSSL_PSA_DRIVER_OPERATION_HANDLE_NULL   ((uint64_t)0)

Typedef Documentation

◆ SharkSslPSAKeyDriver

Optional opaque-key driver for volatile HMAC, PASSWORD and PEPPER keys.

The provider retains only the attributes and a nonzero driver-owned handle. Key generation occurs entirely in the driver. Import consumes the caller's standard key encoding; the provider does not retain those bytes. This interface does not provide persistent external keys or export. An optional copy callback duplicates a volatile key inside the same driver location without revealing its material to the provider. The returned handle must be distinct from the source handle and remain independently valid after either key is destroyed. A failed copy leaves the output handle null and creates no driver key. attach_key resolves a driver-provisioned key by an opaque label. This profile requires the caller to supply a supported type, byte-aligned size, policy and volatile external lifetime; the driver verifies compatibility. A successful attach returns a unique live handle without creating key material. A failed attach leaves the handle null and no live binding. destroy_key releases an attached handle without erasing the provisioned material; it must support an explicit retry after a failed release.

Initialize the entire callback table to zero before assigning its fields. Callbacks run under the provider key-store mutex and must not call PSA or registration functions. The provider copies this table; its context must remain alive until unregistered. Successful import/generate transfers one unique, nonzero live handle to the provider. Failed creation leaves the output handle null and no driver key allocated. destroy success releases the handle; failure must retain a handle that can be retried, even if physical deletion is uncertain. A retry must report success once deletion or absence is confirmed. The provider disables use after the first failed destroy and retains the handle for an explicit retry.

mac_compute receives validated policy and an exact, non-wildcard algorithm. It must return precisely PSA_MAC_LENGTH(type, bits, alg) bytes on success. Partial results and results with an invalid length are never published. The multipart MAC callbacks are optional as a group. mac_setup receives a validated usage and algorithm and returns a nonzero operation handle on success. A failed setup leaves the output handle null and creates no state. Update and failed finish callbacks leave the operation available for abort; successful finish consumes it. mac_abort consumes the operation handle even when it reports an error. Operation handles remain unique while active. Driver implementations own entropy, secret erasure and hardware protection, and must enforce volatile lifetime across reset and application termination. A software test driver does not establish secure-element isolation. pbkdf2_block is required for opaque PASSWORD and PEPPER keys. Each callback computes one complete digest-size block for a concrete supported PBKDF2-HMAC algorithm and reports exactly output_size bytes. The provider never receives the opaque root; it may pass the other password and salt components to the driver. A callback failure clears caller output and invalidates the PSA derivation operation. Driver and application must be rebuilt with this table.

Function Documentation

◆ SharkSslPSAKeyDriver_set()

psa_status_t SharkSslPSAKeyDriver_set ( const SharkSslPSAKeyDriver *  o,
psa_key_location_t  location 
)

Register or replace one location; pass NULL to unregister it.

Only primary secure-element and vendor-defined locations are accepted. Registration needs an empty key store and no active key dependencies; otherwise BAD_STATE leaves all registrations unchanged. destroy_key, one operation callback and at least one creation callback are mandatory. Multipart MAC callbacks must be supplied as a complete group or omitted. Missing methods are unsupported.

Parameters
oconst SharkSslPSAKeyDriver *; zero-initialized then populated callback table to copy, or NULL to unregister this location. Its context remains borrowed.
locationpsa_key_location_t; PSA_KEY_LOCATION_PRIMARY_SECURE_ELEMENT or an inclusive vendor location from 0x800000 to 0xffffff.
Returns
psa_status_t: PSA_SUCCESS; PSA_ERROR_INVALID_ARGUMENT for an invalid location/table; PSA_ERROR_BAD_STATE for live keys/dependencies; PSA_ERROR_INSUFFICIENT_MEMORY when all registration slots are occupied; PSA_ERROR_GENERIC_ERROR on lock failure.