Zephyr API Documentation 4.4.0
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
16
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>
26
31
37
53
54/* Forward declarations */
55struct cipher_aead_pkt;
56struct cipher_ctx;
57struct cipher_pkt;
58
59typedef int (*block_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt);
60
61/* Function signatures for encryption/ decryption using standard cipher modes
62 * like CBC, CTR, CCM.
63 */
64typedef int (*cbc_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt, uint8_t *iv);
65
66typedef int (*ctr_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt, uint8_t *ctr);
67
68typedef int (*ccm_op_t)(struct cipher_ctx *ctx, struct cipher_aead_pkt *pkt, uint8_t *nonce);
69
70typedef int (*gcm_op_t)(struct cipher_ctx *ctx, struct cipher_aead_pkt *pkt, uint8_t *nonce);
71
72typedef int (*ctr_drbg_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt, uint8_t *ctr);
73
84typedef int (*cfb_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt,
85 uint8_t *iv);
86
97typedef int (*ofb_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt,
98 uint8_t *iv);
99
123
128
130 /* CTR mode counter is a split counter composed of iv and counter
131 * such that ivlen + ctr_len = keylen
132 */
134};
135
140
142 /* CTR-DRBG mode counter is a split counter composed of iv and counter
143 * such that ivlen + ctr_len = keylen
144 */
146};
147
155
161
163 union {
164 /* Cryptographic key to be used in this session */
166 /* For cases where key is protected and is not
167 * available to caller
168 */
169 void *handle;
171
175 const struct device *device;
176
185
191
196 union {
202
207
215};
216
226
229
232
238
243
248
254};
255
263 /* IO buffers for encryption. This has to be supplied by the app. */
265
270
273
279};
280
281/* Prototype for the application function to be invoked by the crypto driver
282 * on completion of an async request. The app may get the session context
283 * via the pkt->ctx field. For CCM ops the encompassing AEAD packet may be
284 * accessed via container_of(). The type of a packet can be determined via
285 * pkt->ctx.ops.mode .
286 */
287typedef void (*cipher_completion_cb)(struct cipher_pkt *completed, int status);
288
292#endif /* ZEPHYR_INCLUDE_CRYPTO_CIPHER_H_ */
void(* cipher_completion_cb)(struct cipher_pkt *completed, int status)
Definition cipher.h:287
cipher_op
Cipher Operation.
Definition cipher.h:33
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:59
int(* ofb_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt, uint8_t *iv)
Perform an OFB cipher operation.
Definition cipher.h:97
cipher_algo
Cipher Algorithm.
Definition cipher.h:28
int(* cbc_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt, uint8_t *iv)
Definition cipher.h:64
int(* ctr_drbg_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt, uint8_t *ctr)
Definition cipher.h:72
int(* cfb_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt, uint8_t *iv)
Perform a CFB cipher operation.
Definition cipher.h:84
int(* ctr_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt, uint8_t *ctr)
Definition cipher.h:66
int(* gcm_op_t)(struct cipher_ctx *ctx, struct cipher_aead_pkt *pkt, uint8_t *nonce)
Definition cipher.h:70
cipher_mode
Possible cipher mode options.
Definition cipher.h:43
@ CRYPTO_CIPHER_OP_DECRYPT
Definition cipher.h:34
@ CRYPTO_CIPHER_OP_ENCRYPT
Definition cipher.h:35
@ CRYPTO_CIPHER_ALGO_AES
Definition cipher.h:29
@ CRYPTO_CIPHER_MODE_CTR_DRBG
Definition cipher.h:51
@ CRYPTO_CIPHER_MODE_GCM
Galois/Counter mode.
Definition cipher.h:48
@ CRYPTO_CIPHER_MODE_ECB
Electronic Codebook mode.
Definition cipher.h:44
@ CRYPTO_CIPHER_MODE_CCM
Counter with CBC-MAC mode.
Definition cipher.h:47
@ CRYPTO_CIPHER_MODE_CTR
Counter mode.
Definition cipher.h:46
@ CRYPTO_CIPHER_MODE_CBC
Cipher Block Chaining mode.
Definition cipher.h:45
@ CRYPTO_CIPHER_MODE_OFB
Output Feedback mode.
Definition cipher.h:50
@ CRYPTO_CIPHER_MODE_CFB
Cipher Feedback mode.
Definition cipher.h:49
__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:124
uint16_t tag_len
Definition cipher.h:125
uint16_t nonce_len
Definition cipher.h:126
Structure encoding IO parameters in AEAD (Authenticated Encryption with Associated Data) scenario lik...
Definition cipher.h:262
uint8_t * ad
Start address for Associated Data.
Definition cipher.h:269
uint32_t ad_len
Size of Associated Data.
Definition cipher.h:272
uint8_t * tag
Start address for the auth hash.
Definition cipher.h:278
struct cipher_pkt * pkt
Definition cipher.h:264
Structure encoding session parameters.
Definition cipher.h:154
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:190
uint16_t keylen
Cryptographic keylength in bytes.
Definition cipher.h:206
struct ccm_params ccm_info
Definition cipher.h:197
union cipher_ctx::@252266264254052346115200201223263334036213076237 key
To be populated by the app before calling begin_session().
const struct device * device
The device driver instance this crypto context relates to.
Definition cipher.h:175
uint16_t flags
How certain fields are to be interpreted for this session.
Definition cipher.h:214
void * drv_sessn_state
If the driver supports multiple simultaneously crypto sessions, this will identify the specific drive...
Definition cipher.h:184
void * handle
Definition cipher.h:169
struct ctr_params ctr_info
Definition cipher.h:198
struct gcm_params gcm_info
Definition cipher.h:199
union cipher_ctx::@154152356303000122313150276277376275054131233366 mode_params
Cypher mode parameters, which remain constant for all ops in a session.
struct ctr_drbg_params ctr_drbg_info
Definition cipher.h:200
const uint8_t * bit_stream
Definition cipher.h:165
struct cipher_ops ops
Place for driver to return function pointers to be invoked per cipher operation.
Definition cipher.h:160
Cipher operation handlers selected for a session.
Definition cipher.h:106
block_op_t block_crypt_hndlr
Definition cipher.h:111
gcm_op_t gcm_crypt_hndlr
Definition cipher.h:115
ctr_drbg_op_t ctr_drbg_crypt_hndlr
Definition cipher.h:120
enum cipher_mode cipher_mode
Definition cipher.h:108
cfb_op_t cfb_crypt_hndlr
Handler for CFB operations.
Definition cipher.h:117
cbc_op_t cbc_crypt_hndlr
Definition cipher.h:112
ctr_op_t ctr_crypt_hndlr
Definition cipher.h:113
ofb_op_t ofb_crypt_hndlr
Handler for OFB operations.
Definition cipher.h:119
ccm_op_t ccm_crypt_hndlr
Definition cipher.h:114
Structure encoding IO parameters of one cryptographic operation like encrypt/decrypt.
Definition cipher.h:225
struct cipher_ctx * ctx
Context this packet relates to.
Definition cipher.h:253
uint8_t * in_buf
Start address of input buffer.
Definition cipher.h:228
int out_buf_max
Size of the out_buf area allocated by the application.
Definition cipher.h:242
uint8_t * out_buf
Start of the output buffer, to be allocated by the application.
Definition cipher.h:237
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:247
int in_len
Bytes to be operated upon.
Definition cipher.h:231
Definition cipher.h:141
uint32_t ctr_len
Definition cipher.h:145
Definition cipher.h:129
uint32_t ctr_len
Definition cipher.h:133
Definition cipher.h:136
uint16_t tag_len
Definition cipher.h:137
uint16_t nonce_len
Definition cipher.h:138
Misc utilities.