]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/ccree/ssi_aead.h
staging: ccree: fix pointer location
[karo-tx-linux.git] / drivers / staging / ccree / ssi_aead.h
1 /*
2  * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see <http://www.gnu.org/licenses/>.
15  */
16
17 /* \file ssi_aead.h
18  * ARM CryptoCell AEAD Crypto API
19  */
20
21 #ifndef __SSI_AEAD_H__
22 #define __SSI_AEAD_H__
23
24 #include <linux/kernel.h>
25 #include <crypto/algapi.h>
26 #include <crypto/ctr.h>
27
28
29 /* mac_cmp - HW writes 8 B but all bytes hold the same value */
30 #define ICV_CMP_SIZE 8
31 #define CCM_CONFIG_BUF_SIZE (AES_BLOCK_SIZE * 3)
32 #define MAX_MAC_SIZE MAX(SHA256_DIGEST_SIZE, AES_BLOCK_SIZE)
33
34
35 /* defines for AES GCM configuration buffer */
36 #define GCM_BLOCK_LEN_SIZE 8
37
38 #define GCM_BLOCK_RFC4_IV_OFFSET        4
39 #define GCM_BLOCK_RFC4_IV_SIZE          8  /* IV size for rfc's */
40 #define GCM_BLOCK_RFC4_NONCE_OFFSET     0
41 #define GCM_BLOCK_RFC4_NONCE_SIZE       4
42
43
44
45 /* Offsets into AES CCM configuration buffer */
46 #define CCM_B0_OFFSET 0
47 #define CCM_A0_OFFSET 16
48 #define CCM_CTR_COUNT_0_OFFSET 32
49 /* CCM B0 and CTR_COUNT constants. */
50 #define CCM_BLOCK_NONCE_OFFSET 1  /* Nonce offset inside B0 and CTR_COUNT */
51 #define CCM_BLOCK_NONCE_SIZE   3  /* Nonce size inside B0 and CTR_COUNT */
52 #define CCM_BLOCK_IV_OFFSET    4  /* IV offset inside B0 and CTR_COUNT */
53 #define CCM_BLOCK_IV_SIZE      8  /* IV size inside B0 and CTR_COUNT */
54
55 enum aead_ccm_header_size {
56         ccm_header_size_null = -1,
57         ccm_header_size_zero = 0,
58         ccm_header_size_2 = 2,
59         ccm_header_size_6 = 6,
60         ccm_header_size_max = S32_MAX
61 };
62
63 struct aead_req_ctx {
64         /* Allocate cache line although only 4 bytes are needed to
65          *  assure next field falls @ cache line
66          *  Used for both: digest HW compare and CCM/GCM MAC value
67          */
68         u8 mac_buf[MAX_MAC_SIZE] ____cacheline_aligned;
69         u8 ctr_iv[AES_BLOCK_SIZE] ____cacheline_aligned;
70
71         //used in gcm
72         u8 gcm_iv_inc1[AES_BLOCK_SIZE] ____cacheline_aligned;
73         u8 gcm_iv_inc2[AES_BLOCK_SIZE] ____cacheline_aligned;
74         u8 hkey[AES_BLOCK_SIZE] ____cacheline_aligned;
75         struct {
76                 u8 lenA[GCM_BLOCK_LEN_SIZE] ____cacheline_aligned;
77                 u8 lenC[GCM_BLOCK_LEN_SIZE];
78         } gcm_len_block;
79
80         u8 ccm_config[CCM_CONFIG_BUF_SIZE] ____cacheline_aligned;
81         unsigned int hw_iv_size ____cacheline_aligned; /*HW actual size input*/
82         u8 backup_mac[MAX_MAC_SIZE]; /*used to prevent cache coherence problem*/
83         u8 *backup_iv; /*store iv for generated IV flow*/
84         u8 *backup_giv; /*store iv for rfc3686(ctr) flow*/
85         dma_addr_t mac_buf_dma_addr; /* internal ICV DMA buffer */
86         dma_addr_t ccm_iv0_dma_addr; /* buffer for internal ccm configurations */
87         dma_addr_t icv_dma_addr; /* Phys. address of ICV */
88
89         //used in gcm
90         dma_addr_t gcm_iv_inc1_dma_addr; /* buffer for internal gcm configurations */
91         dma_addr_t gcm_iv_inc2_dma_addr; /* buffer for internal gcm configurations */
92         dma_addr_t hkey_dma_addr; /* Phys. address of hkey */
93         dma_addr_t gcm_block_len_dma_addr; /* Phys. address of gcm block len */
94         bool is_gcm4543;
95
96         u8 *icv_virt_addr; /* Virt. address of ICV */
97         struct async_gen_req_ctx gen_ctx;
98         struct ssi_mlli assoc;
99         struct ssi_mlli src;
100         struct ssi_mlli dst;
101         struct scatterlist *srcSgl;
102         struct scatterlist *dstSgl;
103         unsigned int srcOffset;
104         unsigned int dstOffset;
105         enum ssi_req_dma_buf_type assoc_buff_type;
106         enum ssi_req_dma_buf_type data_buff_type;
107         struct mlli_params mlli_params;
108         unsigned int cryptlen;
109         struct scatterlist ccm_adata_sg;
110         enum aead_ccm_header_size ccm_hdr_size;
111         unsigned int req_authsize;
112         enum drv_cipher_mode cipher_mode;
113         bool is_icv_fragmented;
114         bool is_single_pass;
115         bool plaintext_authenticate_only; //for gcm_rfc4543
116 };
117
118 int ssi_aead_alloc(struct ssi_drvdata *drvdata);
119 int ssi_aead_free(struct ssi_drvdata *drvdata);
120
121 #endif /*__SSI_AEAD_H__*/