17#ifndef ZEPHYR_INCLUDE_CRYPTO_H_
18#define ZEPHYR_INCLUDE_CRYPTO_H_
42#define CAP_OPAQUE_KEY_HNDL BIT(0)
43#define CAP_RAW_KEY BIT(1)
46#define CAP_KEY_LOADING_API BIT(2)
49#define CAP_INPLACE_OPS BIT(3)
50#define CAP_SEPARATE_IO_BUFS BIT(4)
56#define CAP_SYNC_OPS BIT(5)
57#define CAP_ASYNC_OPS BIT(6)
60#define CAP_AUTONONCE BIT(7)
63#define CAP_NO_IV_PREFIX BIT(8)
121 "Driver should support at least one key type: RAW/Opaque");
124 "Driver should support at least one IO buf type: Inplace/separate");
127 "Driver should support at least one op-type: sync/async");
176 __ASSERT(
flags != 0U,
"Keytype missing: RAW Key or OPAQUE handle");
178 "conflicting options for keytype");
181 __ASSERT(
flags != 0U,
"IO buffer type missing");
183 "conflicting options for IO buffer type");
186 __ASSERT(
flags != 0U,
"sync/async type missing");
188 "conflicting options for sync/async");
256 "session invoking a different mode handler");
277 "session invoking a different mode handler");
304 "session invoking a different mode handler");
326 "session invoking a different mode handler");
348 "session invoking a different mode handler");
395 __ASSERT(
flags != 0U,
"IO buffer type missing");
397 "conflicting options for IO buffer type");
400 __ASSERT(
flags != 0U,
"sync/async type missing");
402 "conflicting options for sync/async");
Crypto Cipher structure definitions.
static int cipher_block_op(struct cipher_ctx *ctx, struct cipher_pkt *pkt)
Perform single-block crypto operation (ECB cipher mode).
Definition: crypto.h:252
void(* cipher_completion_cb)(struct cipher_pkt *completed, int status)
Definition: cipher.h:242
static int cipher_begin_session(const struct device *dev, struct cipher_ctx *ctx, enum cipher_algo algo, enum cipher_mode mode, enum cipher_op optype)
Setup a crypto session.
Definition: crypto.h:162
cipher_op
Cipher Operation.
Definition: cipher.h:34
static int cipher_cbc_op(struct cipher_ctx *ctx, struct cipher_pkt *pkt, uint8_t *iv)
Perform Cipher Block Chaining (CBC) crypto operation.
Definition: crypto.h:273
static int cipher_gcm_op(struct cipher_ctx *ctx, struct cipher_aead_pkt *pkt, uint8_t *nonce)
Perform Galois/Counter Mode (GCM) crypto operation.
Definition: crypto.h:344
static int cipher_ccm_op(struct cipher_ctx *ctx, struct cipher_aead_pkt *pkt, uint8_t *nonce)
Perform Counter with CBC-MAC (CCM) mode crypto operation.
Definition: crypto.h:322
cipher_algo
Cipher Algorithm.
Definition: cipher.h:29
static int cipher_free_session(const struct device *dev, struct cipher_ctx *ctx)
Cleanup a crypto session.
Definition: crypto.h:204
static int cipher_callback_set(const struct device *dev, cipher_completion_cb cb)
Registers an async crypto op completion callback with the driver.
Definition: crypto.h:228
cipher_mode
Possible cipher mode options.
Definition: cipher.h:44
static int cipher_ctr_op(struct cipher_ctx *ctx, struct cipher_pkt *pkt, uint8_t *iv)
Perform Counter (CTR) mode crypto operation.
Definition: crypto.h:300
@ CRYPTO_CIPHER_MODE_GCM
Definition: cipher.h:49
@ CRYPTO_CIPHER_MODE_ECB
Definition: cipher.h:45
@ CRYPTO_CIPHER_MODE_CCM
Definition: cipher.h:48
@ CRYPTO_CIPHER_MODE_CTR
Definition: cipher.h:47
@ CRYPTO_CIPHER_MODE_CBC
Definition: cipher.h:46
void(* hash_completion_cb)(struct hash_pkt *completed, int status)
Definition: hash.h:114
static int hash_compute(struct hash_ctx *ctx, struct hash_pkt *pkt)
Perform a cryptographic hash function.
Definition: crypto.h:466
static int hash_begin_session(const struct device *dev, struct hash_ctx *ctx, enum hash_algo algo)
Setup a hash session.
Definition: crypto.h:384
static int hash_callback_set(const struct device *dev, hash_completion_cb cb)
Registers an async hash completion callback with the driver.
Definition: crypto.h:443
hash_algo
Hash algorithm.
Definition: hash.h:26
static int hash_free_session(const struct device *dev, struct hash_ctx *ctx)
Cleanup a hash session.
Definition: crypto.h:419
static int hash_update(struct hash_ctx *ctx, struct hash_pkt *pkt)
Perform a cryptographic multipart hash operation.
Definition: crypto.h:485
#define CAP_SYNC_OPS
These denotes if the output (completion of a cipher_xxx_op) is conveyed by the op function returning,...
Definition: crypto.h:56
#define CAP_INPLACE_OPS
Whether the output is placed in separate buffer or not.
Definition: crypto.h:49
#define CAP_ASYNC_OPS
Definition: crypto.h:57
#define CAP_OPAQUE_KEY_HNDL
Definition: crypto.h:42
#define CAP_SEPARATE_IO_BUFS
Definition: crypto.h:50
#define CAP_RAW_KEY
Definition: crypto.h:43
static int crypto_query_hwcaps(const struct device *dev)
Query the crypto hardware capabilities.
Definition: crypto.h:111
#define ENOTSUP
Unsupported value.
Definition: errno.h:115
flags
Definition: parser.h:96
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
Structure encoding IO parameters in AEAD (Authenticated Encryption with Associated Data) scenario lik...
Definition: cipher.h:217
struct cipher_pkt * pkt
Definition: cipher.h:219
Structure encoding session parameters.
Definition: cipher.h:110
const struct device * device
The device driver instance this crypto context relates to.
Definition: cipher.h:131
uint16_t flags
How certain fields are to be interpreted for this session.
Definition: cipher.h:169
struct cipher_ops ops
Place for driver to return function pointers to be invoked per cipher operation.
Definition: cipher.h:116
block_op_t block_crypt_hndlr
Definition: cipher.h:79
gcm_op_t gcm_crypt_hndlr
Definition: cipher.h:83
enum cipher_mode cipher_mode
Definition: cipher.h:76
cbc_op_t cbc_crypt_hndlr
Definition: cipher.h:80
ctr_op_t ctr_crypt_hndlr
Definition: cipher.h:81
ccm_op_t ccm_crypt_hndlr
Definition: cipher.h:82
Structure encoding IO parameters of one cryptographic operation like encrypt/decrypt.
Definition: cipher.h:180
struct cipher_ctx * ctx
Context this packet relates to.
Definition: cipher.h:208
Crypto driver API definition.
Definition: crypto.h:68
int(* query_hw_caps)(const struct device *dev)
Definition: crypto.h:69
int(* cipher_async_callback_set)(const struct device *dev, cipher_completion_cb cb)
Definition: crypto.h:80
int(* hash_begin_session)(const struct device *dev, struct hash_ctx *ctx, enum hash_algo algo)
Definition: crypto.h:84
int(* cipher_free_session)(const struct device *dev, struct cipher_ctx *ctx)
Definition: crypto.h:77
int(* hash_async_callback_set)(const struct device *dev, hash_completion_cb cb)
Definition: crypto.h:89
int(* hash_free_session)(const struct device *dev, struct hash_ctx *ctx)
Definition: crypto.h:87
int(* cipher_begin_session)(const struct device *dev, struct cipher_ctx *ctx, enum cipher_algo algo, enum cipher_mode mode, enum cipher_op op_type)
Definition: crypto.h:72
Runtime device structure (in ROM) per driver instance.
Definition: device.h:399
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:405
Structure encoding session parameters.
Definition: hash.h:47
hash_op_t hash_hndlr
Hash handler set up when the session begins.
Definition: hash.h:65
uint16_t flags
How certain fields are to be interpreted for this session.
Definition: hash.h:78
const struct device * device
The device driver instance this crypto context relates to.
Definition: hash.h:51
Structure encoding IO parameters of a hash operation.
Definition: hash.h:88
struct hash_ctx * ctx
Context this packet relates to.
Definition: hash.h:107