Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
cipher.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
17#ifndef ZEPHYR_INCLUDE_CRYPTO_CIPHER_H_
18#define ZEPHYR_INCLUDE_CRYPTO_CIPHER_H_
19
20#include <zephyr/device.h>
21#include <zephyr/sys/util.h>
32
38
51
52/* Forward declarations */
53struct cipher_aead_pkt;
54struct cipher_ctx;
55struct cipher_pkt;
56
57typedef int (*block_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt);
58
59/* Function signatures for encryption/ decryption using standard cipher modes
60 * like CBC, CTR, CCM.
61 */
62typedef int (*cbc_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt,
63 uint8_t *iv);
64
65typedef int (*ctr_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt,
66 uint8_t *ctr);
67
68typedef int (*ccm_op_t)(struct cipher_ctx *ctx, struct cipher_aead_pkt *pkt,
69 uint8_t *nonce);
70
71typedef int (*gcm_op_t)(struct cipher_ctx *ctx, struct cipher_aead_pkt *pkt,
72 uint8_t *nonce);
73
86
91
92struct ctr_params {
93 /* CTR mode counter is a split counter composed of iv and counter
94 * such that ivlen + ctr_len = keylen
95 */
97};
98
103
111
117
119 union {
120 /* Cryptographic key to be used in this session */
122 /* For cases where key is protected and is not
123 * available to caller
124 */
125 void *handle;
127
131 const struct device *device;
132
141
147
152 union {
157
162
170};
171
181
184
187
193
198
203
209};
210
218 /* IO buffers for encryption. This has to be supplied by the app. */
220
225
228
234};
235
236/* Prototype for the application function to be invoked by the crypto driver
237 * on completion of an async request. The app may get the session context
238 * via the pkt->ctx field. For CCM ops the encompassing AEAD packet may be
239 * accessed via container_of(). The type of a packet can be determined via
240 * pkt->ctx.ops.mode .
241 */
242typedef void (*cipher_completion_cb)(struct cipher_pkt *completed, int status);
243
247#endif /* ZEPHYR_INCLUDE_CRYPTO_CIPHER_H_ */
void(* cipher_completion_cb)(struct cipher_pkt *completed, int status)
Definition cipher.h:242
cipher_op
Cipher Operation.
Definition cipher.h:34
int(* ccm_op_t)(struct cipher_ctx *ctx, struct cipher_aead_pkt *pkt, uint8_t *nonce)
Definition cipher.h:68
int(* block_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt)
Definition cipher.h:57
cipher_algo
Cipher Algorithm.
Definition cipher.h:29
int(* cbc_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt, uint8_t *iv)
Definition cipher.h:62
int(* ctr_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt, uint8_t *ctr)
Definition cipher.h:65
int(* gcm_op_t)(struct cipher_ctx *ctx, struct cipher_aead_pkt *pkt, uint8_t *nonce)
Definition cipher.h:71
cipher_mode
Possible cipher mode options.
Definition cipher.h:44
@ CRYPTO_CIPHER_OP_DECRYPT
Definition cipher.h:35
@ CRYPTO_CIPHER_OP_ENCRYPT
Definition cipher.h:36
@ CRYPTO_CIPHER_ALGO_AES
Definition cipher.h:30
@ 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
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Definition cipher.h:87
uint16_t tag_len
Definition cipher.h:88
uint16_t nonce_len
Definition cipher.h:89
Structure encoding IO parameters in AEAD (Authenticated Encryption with Associated Data) scenario lik...
Definition cipher.h:217
uint8_t * ad
Start address for Associated Data.
Definition cipher.h:224
uint32_t ad_len
Size of Associated Data.
Definition cipher.h:227
uint8_t * tag
Start address for the auth hash.
Definition cipher.h:233
struct cipher_pkt * pkt
Definition cipher.h:219
Structure encoding session parameters.
Definition cipher.h:110
void * app_sessn_state
Place for the user app to put info relevant stuff for resuming when completion callback happens for a...
Definition cipher.h:146
uint16_t keylen
Cryptographic keylength in bytes.
Definition cipher.h:161
struct ccm_params ccm_info
Definition cipher.h:153
const struct device * device
The device driver instance this crypto context relates to.
Definition cipher.h:131
union cipher_ctx::@178 mode_params
Cypher mode parameters, which remain constant for all ops in a session.
uint16_t flags
How certain fields are to be interpreted for this session.
Definition cipher.h:169
void * drv_sessn_state
If the driver supports multiple simultaneously crypto sessions, this will identify the specific drive...
Definition cipher.h:140
void * handle
Definition cipher.h:125
struct ctr_params ctr_info
Definition cipher.h:154
struct gcm_params gcm_info
Definition cipher.h:155
const uint8_t * bit_stream
Definition cipher.h:121
struct cipher_ops ops
Place for driver to return function pointers to be invoked per cipher operation.
Definition cipher.h:116
union cipher_ctx::@177 key
To be populated by the app before calling begin_session()
Definition cipher.h:74
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
uint8_t * in_buf
Start address of input buffer.
Definition cipher.h:183
int out_buf_max
Size of the out_buf area allocated by the application.
Definition cipher.h:197
uint8_t * out_buf
Start of the output buffer, to be allocated by the application.
Definition cipher.h:192
int out_len
To be populated by driver on return from cipher_xxx_op() and holds the size of the actual result.
Definition cipher.h:202
int in_len
Bytes to be operated upon.
Definition cipher.h:186
Definition cipher.h:92
uint32_t ctr_len
Definition cipher.h:96
Runtime device structure (in ROM) per driver instance.
Definition device.h:411
Definition cipher.h:99
uint16_t tag_len
Definition cipher.h:100
uint16_t nonce_len
Definition cipher.h:101
Misc utilities.