123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- #ifndef ZEPHYR_INCLUDE_CRYPTO_CIPHER_STRUCTS_H_
- #define ZEPHYR_INCLUDE_CRYPTO_CIPHER_STRUCTS_H_
- #include <device.h>
- #include <sys/util.h>
- enum cipher_algo {
- CRYPTO_CIPHER_ALGO_AES = 1,
- };
- enum cipher_op {
- CRYPTO_CIPHER_OP_DECRYPT = 0,
- CRYPTO_CIPHER_OP_ENCRYPT = 1,
- };
- enum cipher_mode {
- CRYPTO_CIPHER_MODE_ECB = 1,
- CRYPTO_CIPHER_MODE_CBC = 2,
- CRYPTO_CIPHER_MODE_CTR = 3,
- CRYPTO_CIPHER_MODE_CCM = 4,
- CRYPTO_CIPHER_MODE_GCM = 5,
- };
- struct cipher_aead_pkt;
- struct cipher_ctx;
- struct cipher_pkt;
- typedef int (*block_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt);
- typedef int (*cbc_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt,
- uint8_t *iv);
- typedef int (*ctr_op_t)(struct cipher_ctx *ctx, struct cipher_pkt *pkt,
- uint8_t *ctr);
- typedef int (*ccm_op_t)(struct cipher_ctx *ctx, struct cipher_aead_pkt *pkt,
- uint8_t *nonce);
- typedef int (*gcm_op_t)(struct cipher_ctx *ctx, struct cipher_aead_pkt *pkt,
- uint8_t *nonce);
- struct cipher_ops {
- enum cipher_mode cipher_mode;
- union {
- block_op_t block_crypt_hndlr;
- cbc_op_t cbc_crypt_hndlr;
- ctr_op_t ctr_crypt_hndlr;
- ccm_op_t ccm_crypt_hndlr;
- gcm_op_t gcm_crypt_hndlr;
- };
- };
- struct ccm_params {
- uint16_t tag_len;
- uint16_t nonce_len;
- };
- struct ctr_params {
-
- uint32_t ctr_len;
- };
- struct gcm_params {
- uint16_t tag_len;
- uint16_t nonce_len;
- };
- struct cipher_ctx {
-
- struct cipher_ops ops;
-
- union {
-
- uint8_t *bit_stream;
-
- void *handle;
- } key;
-
- const struct device *device;
-
- void *drv_sessn_state;
-
- void *app_sessn_state;
-
- union {
- struct ccm_params ccm_info;
- struct ctr_params ctr_info;
- struct gcm_params gcm_info;
- } mode_params;
-
- uint16_t keylen;
-
- uint16_t flags;
- };
- #define CAP_OPAQUE_KEY_HNDL BIT(0)
- #define CAP_RAW_KEY BIT(1)
- #define CAP_KEY_LOADING_API BIT(2)
- #define CAP_INPLACE_OPS BIT(3)
- #define CAP_SEPARATE_IO_BUFS BIT(4)
- #define CAP_SYNC_OPS BIT(5)
- #define CAP_ASYNC_OPS BIT(6)
- #define CAP_AUTONONCE BIT(7)
- #define CAP_NO_IV_PREFIX BIT(8)
- struct cipher_pkt {
-
- uint8_t *in_buf;
-
- int in_len;
-
- uint8_t *out_buf;
-
- int out_buf_max;
-
- int out_len;
-
- struct cipher_ctx *ctx;
- };
- struct cipher_aead_pkt {
-
- struct cipher_pkt *pkt;
-
- uint8_t *ad;
-
- uint32_t ad_len;
-
- uint8_t *tag;
- };
- typedef void (*crypto_completion_cb)(struct cipher_pkt *completed, int status);
- #endif
|