Horia Geantă | 618b5dc | 2018-10-10 14:26:48 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2 | /* |
| 3 | * caam - Freescale FSL CAAM support for crypto API |
| 4 | * |
| 5 | * Copyright 2008-2011 Freescale Semiconductor, Inc. |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 6 | * Copyright 2016-2019 NXP |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 7 | * |
| 8 | * Based on talitos crypto API driver. |
| 9 | * |
| 10 | * relationship of job descriptors to shared descriptors (SteveC Dec 10 2008): |
| 11 | * |
| 12 | * --------------- --------------- |
| 13 | * | JobDesc #1 |-------------------->| ShareDesc | |
| 14 | * | *(packet 1) | | (PDB) | |
| 15 | * --------------- |------------->| (hashKey) | |
| 16 | * . | | (cipherKey) | |
| 17 | * . | |-------->| (operation) | |
| 18 | * --------------- | | --------------- |
| 19 | * | JobDesc #2 |------| | |
| 20 | * | *(packet 2) | | |
| 21 | * --------------- | |
| 22 | * . | |
| 23 | * . | |
| 24 | * --------------- | |
| 25 | * | JobDesc #3 |------------ |
| 26 | * | *(packet 3) | |
| 27 | * --------------- |
| 28 | * |
| 29 | * The SharedDesc never changes for a connection unless rekeyed, but |
| 30 | * each packet will likely be in a different place. So all we need |
| 31 | * to know to process the packet is where the input is, where the |
| 32 | * output goes, and what context we want to process with. Context is |
| 33 | * in the SharedDesc, packet references in the JobDesc. |
| 34 | * |
| 35 | * So, a job desc looks like: |
| 36 | * |
| 37 | * --------------------- |
| 38 | * | Header | |
| 39 | * | ShareDesc Pointer | |
| 40 | * | SEQ_OUT_PTR | |
| 41 | * | (output buffer) | |
Yuan Kang | 6ec4733 | 2012-06-22 19:48:43 -0500 | [diff] [blame] | 42 | * | (output length) | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 43 | * | SEQ_IN_PTR | |
| 44 | * | (input buffer) | |
Yuan Kang | 6ec4733 | 2012-06-22 19:48:43 -0500 | [diff] [blame] | 45 | * | (input length) | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 46 | * --------------------- |
| 47 | */ |
| 48 | |
| 49 | #include "compat.h" |
| 50 | |
| 51 | #include "regs.h" |
| 52 | #include "intern.h" |
| 53 | #include "desc_constr.h" |
| 54 | #include "jr.h" |
| 55 | #include "error.h" |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 56 | #include "sg_sw_sec4.h" |
Yuan Kang | 4c1ec1f | 2012-06-22 19:48:45 -0500 | [diff] [blame] | 57 | #include "key_gen.h" |
Horia Geantă | 8cea7b6 | 2016-11-22 15:44:09 +0200 | [diff] [blame] | 58 | #include "caamalg_desc.h" |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * crypto alg |
| 62 | */ |
| 63 | #define CAAM_CRA_PRIORITY 3000 |
| 64 | /* max key is sum of AES_MAX_KEY_SIZE, max split key size */ |
| 65 | #define CAAM_MAX_KEY_SIZE (AES_MAX_KEY_SIZE + \ |
Catalin Vasile | daebc46 | 2014-10-31 12:45:37 +0200 | [diff] [blame] | 66 | CTR_RFC3686_NONCE_SIZE + \ |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 67 | SHA512_DIGEST_SIZE * 2) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 68 | |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 69 | #define AEAD_DESC_JOB_IO_LEN (DESC_JOB_IO_LEN + CAAM_CMD_SZ * 2) |
| 70 | #define GCM_DESC_JOB_IO_LEN (AEAD_DESC_JOB_IO_LEN + \ |
| 71 | CAAM_CMD_SZ * 4) |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 72 | #define AUTHENC_DESC_JOB_IO_LEN (AEAD_DESC_JOB_IO_LEN + \ |
| 73 | CAAM_CMD_SZ * 5) |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 74 | |
Horia Geantă | d6bbd4e | 2018-11-08 15:36:30 +0200 | [diff] [blame] | 75 | #define CHACHAPOLY_DESC_JOB_IO_LEN (AEAD_DESC_JOB_IO_LEN + CAAM_CMD_SZ * 6) |
| 76 | |
Andrey Smirnov | 1a3daad | 2019-08-20 13:23:55 -0700 | [diff] [blame] | 77 | #define DESC_MAX_USED_BYTES (CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN_MIN) |
Herbert Xu | 87e51b0 | 2015-06-18 14:25:55 +0800 | [diff] [blame] | 78 | #define DESC_MAX_USED_LEN (DESC_MAX_USED_BYTES / CAAM_CMD_SZ) |
Kim Phillips | 4427b1b | 2011-05-14 22:08:17 -0500 | [diff] [blame] | 79 | |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 80 | struct caam_alg_entry { |
| 81 | int class1_alg_type; |
| 82 | int class2_alg_type; |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 83 | bool rfc3686; |
| 84 | bool geniv; |
Herbert Xu | 24586b5 | 2019-05-06 14:39:44 +0800 | [diff] [blame] | 85 | bool nodkp; |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | struct caam_aead_alg { |
| 89 | struct aead_alg aead; |
| 90 | struct caam_alg_entry caam; |
| 91 | bool registered; |
| 92 | }; |
| 93 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 94 | struct caam_skcipher_alg { |
| 95 | struct skcipher_alg skcipher; |
| 96 | struct caam_alg_entry caam; |
| 97 | bool registered; |
| 98 | }; |
| 99 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 100 | /* |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 101 | * per-session context |
| 102 | */ |
| 103 | struct caam_ctx { |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 104 | u32 sh_desc_enc[DESC_MAX_USED_LEN]; |
| 105 | u32 sh_desc_dec[DESC_MAX_USED_LEN]; |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 106 | u8 key[CAAM_MAX_KEY_SIZE]; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 107 | dma_addr_t sh_desc_enc_dma; |
| 108 | dma_addr_t sh_desc_dec_dma; |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 109 | dma_addr_t key_dma; |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 110 | enum dma_data_direction dir; |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 111 | struct device *jrdev; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 112 | struct alginfo adata; |
| 113 | struct alginfo cdata; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 114 | unsigned int authsize; |
| 115 | }; |
| 116 | |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 117 | static int aead_null_set_sh_desc(struct crypto_aead *aead) |
| 118 | { |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 119 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 120 | struct device *jrdev = ctx->jrdev; |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 121 | struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent); |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 122 | u32 *desc; |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 123 | int rem_bytes = CAAM_DESC_BYTES_MAX - AEAD_DESC_JOB_IO_LEN - |
| 124 | ctx->adata.keylen_pad; |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 125 | |
| 126 | /* |
| 127 | * Job Descriptor and Shared Descriptors |
| 128 | * must all fit into the 64-word Descriptor h/w Buffer |
| 129 | */ |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 130 | if (rem_bytes >= DESC_AEAD_NULL_ENC_LEN) { |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 131 | ctx->adata.key_inline = true; |
Arnd Bergmann | 9c0bc51 | 2016-11-30 22:01:59 +0100 | [diff] [blame] | 132 | ctx->adata.key_virt = ctx->key; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 133 | } else { |
| 134 | ctx->adata.key_inline = false; |
Arnd Bergmann | 9c0bc51 | 2016-11-30 22:01:59 +0100 | [diff] [blame] | 135 | ctx->adata.key_dma = ctx->key_dma; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 136 | } |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 137 | |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 138 | /* aead_encrypt shared descriptor */ |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 139 | desc = ctx->sh_desc_enc; |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 140 | cnstr_shdsc_aead_null_encap(desc, &ctx->adata, ctx->authsize, |
| 141 | ctrlpriv->era); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 142 | dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 143 | desc_bytes(desc), ctx->dir); |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 144 | |
| 145 | /* |
| 146 | * Job Descriptor and Shared Descriptors |
| 147 | * must all fit into the 64-word Descriptor h/w Buffer |
| 148 | */ |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 149 | if (rem_bytes >= DESC_AEAD_NULL_DEC_LEN) { |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 150 | ctx->adata.key_inline = true; |
Arnd Bergmann | 9c0bc51 | 2016-11-30 22:01:59 +0100 | [diff] [blame] | 151 | ctx->adata.key_virt = ctx->key; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 152 | } else { |
| 153 | ctx->adata.key_inline = false; |
Arnd Bergmann | 9c0bc51 | 2016-11-30 22:01:59 +0100 | [diff] [blame] | 154 | ctx->adata.key_dma = ctx->key_dma; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 155 | } |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 156 | |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 157 | /* aead_decrypt shared descriptor */ |
Horia Geantă | 8cea7b6 | 2016-11-22 15:44:09 +0200 | [diff] [blame] | 158 | desc = ctx->sh_desc_dec; |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 159 | cnstr_shdsc_aead_null_decap(desc, &ctx->adata, ctx->authsize, |
| 160 | ctrlpriv->era); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 161 | dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 162 | desc_bytes(desc), ctx->dir); |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 167 | static int aead_set_sh_desc(struct crypto_aead *aead) |
| 168 | { |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 169 | struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead), |
| 170 | struct caam_aead_alg, aead); |
Herbert Xu | add86d5 | 2015-05-11 17:47:50 +0800 | [diff] [blame] | 171 | unsigned int ivsize = crypto_aead_ivsize(aead); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 172 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 173 | struct device *jrdev = ctx->jrdev; |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 174 | struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent); |
Catalin Vasile | daebc46 | 2014-10-31 12:45:37 +0200 | [diff] [blame] | 175 | u32 ctx1_iv_off = 0; |
Horia Geantă | 8cea7b6 | 2016-11-22 15:44:09 +0200 | [diff] [blame] | 176 | u32 *desc, *nonce = NULL; |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 177 | u32 inl_mask; |
| 178 | unsigned int data_len[2]; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 179 | const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) == |
Catalin Vasile | daebc46 | 2014-10-31 12:45:37 +0200 | [diff] [blame] | 180 | OP_ALG_AAI_CTR_MOD128); |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 181 | const bool is_rfc3686 = alg->caam.rfc3686; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 182 | |
Horia Geantă | 2fdea25 | 2016-08-04 20:02:47 +0300 | [diff] [blame] | 183 | if (!ctx->authsize) |
| 184 | return 0; |
| 185 | |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 186 | /* NULL encryption / decryption */ |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 187 | if (!ctx->cdata.keylen) |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 188 | return aead_null_set_sh_desc(aead); |
| 189 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 190 | /* |
Catalin Vasile | daebc46 | 2014-10-31 12:45:37 +0200 | [diff] [blame] | 191 | * AES-CTR needs to load IV in CONTEXT1 reg |
| 192 | * at an offset of 128bits (16bytes) |
| 193 | * CONTEXT1[255:128] = IV |
| 194 | */ |
| 195 | if (ctr_mode) |
| 196 | ctx1_iv_off = 16; |
| 197 | |
| 198 | /* |
| 199 | * RFC3686 specific: |
| 200 | * CONTEXT1[255:128] = {NONCE, IV, COUNTER} |
| 201 | */ |
Horia Geantă | 8cea7b6 | 2016-11-22 15:44:09 +0200 | [diff] [blame] | 202 | if (is_rfc3686) { |
Catalin Vasile | daebc46 | 2014-10-31 12:45:37 +0200 | [diff] [blame] | 203 | ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE; |
Horia Geantă | 8cea7b6 | 2016-11-22 15:44:09 +0200 | [diff] [blame] | 204 | nonce = (u32 *)((void *)ctx->key + ctx->adata.keylen_pad + |
| 205 | ctx->cdata.keylen - CTR_RFC3686_NONCE_SIZE); |
| 206 | } |
Catalin Vasile | daebc46 | 2014-10-31 12:45:37 +0200 | [diff] [blame] | 207 | |
Horia Geantă | e9b4913 | 2019-07-31 16:08:11 +0300 | [diff] [blame] | 208 | /* |
| 209 | * In case |user key| > |derived key|, using DKP<imm,imm> |
| 210 | * would result in invalid opcodes (last bytes of user key) in |
| 211 | * the resulting descriptor. Use DKP<ptr,imm> instead => both |
| 212 | * virtual and dma key addresses are needed. |
| 213 | */ |
| 214 | ctx->adata.key_virt = ctx->key; |
| 215 | ctx->adata.key_dma = ctx->key_dma; |
| 216 | |
| 217 | ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad; |
| 218 | ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad; |
| 219 | |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 220 | data_len[0] = ctx->adata.keylen_pad; |
| 221 | data_len[1] = ctx->cdata.keylen; |
| 222 | |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 223 | if (alg->caam.geniv) |
| 224 | goto skip_enc; |
| 225 | |
Catalin Vasile | daebc46 | 2014-10-31 12:45:37 +0200 | [diff] [blame] | 226 | /* |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 227 | * Job Descriptor and Shared Descriptors |
| 228 | * must all fit into the 64-word Descriptor h/w Buffer |
| 229 | */ |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 230 | if (desc_inline_query(DESC_AEAD_ENC_LEN + |
| 231 | (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0), |
| 232 | AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask, |
| 233 | ARRAY_SIZE(data_len)) < 0) |
| 234 | return -EINVAL; |
| 235 | |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 236 | ctx->adata.key_inline = !!(inl_mask & 1); |
| 237 | ctx->cdata.key_inline = !!(inl_mask & 2); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 238 | |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 239 | /* aead_encrypt shared descriptor */ |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 240 | desc = ctx->sh_desc_enc; |
Horia Geantă | b189817 | 2017-03-17 12:06:02 +0200 | [diff] [blame] | 241 | cnstr_shdsc_aead_encap(desc, &ctx->cdata, &ctx->adata, ivsize, |
| 242 | ctx->authsize, is_rfc3686, nonce, ctx1_iv_off, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 243 | false, ctrlpriv->era); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 244 | dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 245 | desc_bytes(desc), ctx->dir); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 246 | |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 247 | skip_enc: |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 248 | /* |
| 249 | * Job Descriptor and Shared Descriptors |
| 250 | * must all fit into the 64-word Descriptor h/w Buffer |
| 251 | */ |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 252 | if (desc_inline_query(DESC_AEAD_DEC_LEN + |
| 253 | (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0), |
| 254 | AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask, |
| 255 | ARRAY_SIZE(data_len)) < 0) |
| 256 | return -EINVAL; |
| 257 | |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 258 | ctx->adata.key_inline = !!(inl_mask & 1); |
| 259 | ctx->cdata.key_inline = !!(inl_mask & 2); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 260 | |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 261 | /* aead_decrypt shared descriptor */ |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 262 | desc = ctx->sh_desc_dec; |
Horia Geantă | 8cea7b6 | 2016-11-22 15:44:09 +0200 | [diff] [blame] | 263 | cnstr_shdsc_aead_decap(desc, &ctx->cdata, &ctx->adata, ivsize, |
| 264 | ctx->authsize, alg->caam.geniv, is_rfc3686, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 265 | nonce, ctx1_iv_off, false, ctrlpriv->era); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 266 | dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 267 | desc_bytes(desc), ctx->dir); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 268 | |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 269 | if (!alg->caam.geniv) |
| 270 | goto skip_givenc; |
| 271 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 272 | /* |
| 273 | * Job Descriptor and Shared Descriptors |
| 274 | * must all fit into the 64-word Descriptor h/w Buffer |
| 275 | */ |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 276 | if (desc_inline_query(DESC_AEAD_GIVENC_LEN + |
| 277 | (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0), |
| 278 | AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask, |
| 279 | ARRAY_SIZE(data_len)) < 0) |
| 280 | return -EINVAL; |
| 281 | |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 282 | ctx->adata.key_inline = !!(inl_mask & 1); |
| 283 | ctx->cdata.key_inline = !!(inl_mask & 2); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 284 | |
| 285 | /* aead_givencrypt shared descriptor */ |
Horia Geantă | 1d2d87e | 2016-08-04 20:02:46 +0300 | [diff] [blame] | 286 | desc = ctx->sh_desc_enc; |
Horia Geantă | 8cea7b6 | 2016-11-22 15:44:09 +0200 | [diff] [blame] | 287 | cnstr_shdsc_aead_givencap(desc, &ctx->cdata, &ctx->adata, ivsize, |
| 288 | ctx->authsize, is_rfc3686, nonce, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 289 | ctx1_iv_off, false, ctrlpriv->era); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 290 | dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 291 | desc_bytes(desc), ctx->dir); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 292 | |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 293 | skip_givenc: |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 294 | return 0; |
| 295 | } |
| 296 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 297 | static int aead_setauthsize(struct crypto_aead *authenc, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 298 | unsigned int authsize) |
| 299 | { |
| 300 | struct caam_ctx *ctx = crypto_aead_ctx(authenc); |
| 301 | |
| 302 | ctx->authsize = authsize; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 303 | aead_set_sh_desc(authenc); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 304 | |
| 305 | return 0; |
| 306 | } |
| 307 | |
Tudor Ambarus | 3ef8d94 | 2014-10-23 16:11:23 +0300 | [diff] [blame] | 308 | static int gcm_set_sh_desc(struct crypto_aead *aead) |
| 309 | { |
Tudor Ambarus | 3ef8d94 | 2014-10-23 16:11:23 +0300 | [diff] [blame] | 310 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 311 | struct device *jrdev = ctx->jrdev; |
Horia Geantă | 87ec3a0 | 2018-01-29 10:38:36 +0200 | [diff] [blame] | 312 | unsigned int ivsize = crypto_aead_ivsize(aead); |
Tudor Ambarus | 3ef8d94 | 2014-10-23 16:11:23 +0300 | [diff] [blame] | 313 | u32 *desc; |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 314 | int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN - |
| 315 | ctx->cdata.keylen; |
Tudor Ambarus | 3ef8d94 | 2014-10-23 16:11:23 +0300 | [diff] [blame] | 316 | |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 317 | if (!ctx->cdata.keylen || !ctx->authsize) |
Tudor Ambarus | 3ef8d94 | 2014-10-23 16:11:23 +0300 | [diff] [blame] | 318 | return 0; |
| 319 | |
| 320 | /* |
| 321 | * AES GCM encrypt shared descriptor |
| 322 | * Job Descriptor and Shared Descriptor |
| 323 | * must fit into the 64-word Descriptor h/w Buffer |
| 324 | */ |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 325 | if (rem_bytes >= DESC_GCM_ENC_LEN) { |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 326 | ctx->cdata.key_inline = true; |
Arnd Bergmann | 9c0bc51 | 2016-11-30 22:01:59 +0100 | [diff] [blame] | 327 | ctx->cdata.key_virt = ctx->key; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 328 | } else { |
| 329 | ctx->cdata.key_inline = false; |
Arnd Bergmann | 9c0bc51 | 2016-11-30 22:01:59 +0100 | [diff] [blame] | 330 | ctx->cdata.key_dma = ctx->key_dma; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 331 | } |
Tudor Ambarus | 3ef8d94 | 2014-10-23 16:11:23 +0300 | [diff] [blame] | 332 | |
| 333 | desc = ctx->sh_desc_enc; |
Horia Geantă | 87ec3a0 | 2018-01-29 10:38:36 +0200 | [diff] [blame] | 334 | cnstr_shdsc_gcm_encap(desc, &ctx->cdata, ivsize, ctx->authsize, false); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 335 | dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 336 | desc_bytes(desc), ctx->dir); |
Tudor Ambarus | 3ef8d94 | 2014-10-23 16:11:23 +0300 | [diff] [blame] | 337 | |
| 338 | /* |
| 339 | * Job Descriptor and Shared Descriptors |
| 340 | * must all fit into the 64-word Descriptor h/w Buffer |
| 341 | */ |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 342 | if (rem_bytes >= DESC_GCM_DEC_LEN) { |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 343 | ctx->cdata.key_inline = true; |
Arnd Bergmann | 9c0bc51 | 2016-11-30 22:01:59 +0100 | [diff] [blame] | 344 | ctx->cdata.key_virt = ctx->key; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 345 | } else { |
| 346 | ctx->cdata.key_inline = false; |
Arnd Bergmann | 9c0bc51 | 2016-11-30 22:01:59 +0100 | [diff] [blame] | 347 | ctx->cdata.key_dma = ctx->key_dma; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 348 | } |
Tudor Ambarus | 3ef8d94 | 2014-10-23 16:11:23 +0300 | [diff] [blame] | 349 | |
| 350 | desc = ctx->sh_desc_dec; |
Horia Geantă | 87ec3a0 | 2018-01-29 10:38:36 +0200 | [diff] [blame] | 351 | cnstr_shdsc_gcm_decap(desc, &ctx->cdata, ivsize, ctx->authsize, false); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 352 | dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 353 | desc_bytes(desc), ctx->dir); |
Tudor Ambarus | 3ef8d94 | 2014-10-23 16:11:23 +0300 | [diff] [blame] | 354 | |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize) |
| 359 | { |
| 360 | struct caam_ctx *ctx = crypto_aead_ctx(authenc); |
Iuliana Prodan | 68a5139 | 2019-07-31 16:08:06 +0300 | [diff] [blame] | 361 | int err; |
| 362 | |
| 363 | err = crypto_gcm_check_authsize(authsize); |
| 364 | if (err) |
| 365 | return err; |
Tudor Ambarus | 3ef8d94 | 2014-10-23 16:11:23 +0300 | [diff] [blame] | 366 | |
| 367 | ctx->authsize = authsize; |
| 368 | gcm_set_sh_desc(authenc); |
| 369 | |
| 370 | return 0; |
| 371 | } |
| 372 | |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 373 | static int rfc4106_set_sh_desc(struct crypto_aead *aead) |
| 374 | { |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 375 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 376 | struct device *jrdev = ctx->jrdev; |
Horia Geantă | 87ec3a0 | 2018-01-29 10:38:36 +0200 | [diff] [blame] | 377 | unsigned int ivsize = crypto_aead_ivsize(aead); |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 378 | u32 *desc; |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 379 | int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN - |
| 380 | ctx->cdata.keylen; |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 381 | |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 382 | if (!ctx->cdata.keylen || !ctx->authsize) |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 383 | return 0; |
| 384 | |
| 385 | /* |
| 386 | * RFC4106 encrypt shared descriptor |
| 387 | * Job Descriptor and Shared Descriptor |
| 388 | * must fit into the 64-word Descriptor h/w Buffer |
| 389 | */ |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 390 | if (rem_bytes >= DESC_RFC4106_ENC_LEN) { |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 391 | ctx->cdata.key_inline = true; |
Arnd Bergmann | 9c0bc51 | 2016-11-30 22:01:59 +0100 | [diff] [blame] | 392 | ctx->cdata.key_virt = ctx->key; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 393 | } else { |
| 394 | ctx->cdata.key_inline = false; |
Arnd Bergmann | 9c0bc51 | 2016-11-30 22:01:59 +0100 | [diff] [blame] | 395 | ctx->cdata.key_dma = ctx->key_dma; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 396 | } |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 397 | |
| 398 | desc = ctx->sh_desc_enc; |
Horia Geantă | 87ec3a0 | 2018-01-29 10:38:36 +0200 | [diff] [blame] | 399 | cnstr_shdsc_rfc4106_encap(desc, &ctx->cdata, ivsize, ctx->authsize, |
| 400 | false); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 401 | dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 402 | desc_bytes(desc), ctx->dir); |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 403 | |
| 404 | /* |
| 405 | * Job Descriptor and Shared Descriptors |
| 406 | * must all fit into the 64-word Descriptor h/w Buffer |
| 407 | */ |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 408 | if (rem_bytes >= DESC_RFC4106_DEC_LEN) { |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 409 | ctx->cdata.key_inline = true; |
Arnd Bergmann | 9c0bc51 | 2016-11-30 22:01:59 +0100 | [diff] [blame] | 410 | ctx->cdata.key_virt = ctx->key; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 411 | } else { |
| 412 | ctx->cdata.key_inline = false; |
Arnd Bergmann | 9c0bc51 | 2016-11-30 22:01:59 +0100 | [diff] [blame] | 413 | ctx->cdata.key_dma = ctx->key_dma; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 414 | } |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 415 | |
| 416 | desc = ctx->sh_desc_dec; |
Horia Geantă | 87ec3a0 | 2018-01-29 10:38:36 +0200 | [diff] [blame] | 417 | cnstr_shdsc_rfc4106_decap(desc, &ctx->cdata, ivsize, ctx->authsize, |
| 418 | false); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 419 | dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 420 | desc_bytes(desc), ctx->dir); |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 421 | |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | static int rfc4106_setauthsize(struct crypto_aead *authenc, |
| 426 | unsigned int authsize) |
| 427 | { |
| 428 | struct caam_ctx *ctx = crypto_aead_ctx(authenc); |
Iuliana Prodan | 68a5139 | 2019-07-31 16:08:06 +0300 | [diff] [blame] | 429 | int err; |
| 430 | |
| 431 | err = crypto_rfc4106_check_authsize(authsize); |
| 432 | if (err) |
| 433 | return err; |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 434 | |
| 435 | ctx->authsize = authsize; |
| 436 | rfc4106_set_sh_desc(authenc); |
| 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
Tudor Ambarus | 5d0429a | 2014-10-30 18:55:07 +0200 | [diff] [blame] | 441 | static int rfc4543_set_sh_desc(struct crypto_aead *aead) |
| 442 | { |
Tudor Ambarus | 5d0429a | 2014-10-30 18:55:07 +0200 | [diff] [blame] | 443 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 444 | struct device *jrdev = ctx->jrdev; |
Horia Geantă | 87ec3a0 | 2018-01-29 10:38:36 +0200 | [diff] [blame] | 445 | unsigned int ivsize = crypto_aead_ivsize(aead); |
Tudor Ambarus | 5d0429a | 2014-10-30 18:55:07 +0200 | [diff] [blame] | 446 | u32 *desc; |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 447 | int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN - |
| 448 | ctx->cdata.keylen; |
Tudor Ambarus | 5d0429a | 2014-10-30 18:55:07 +0200 | [diff] [blame] | 449 | |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 450 | if (!ctx->cdata.keylen || !ctx->authsize) |
Tudor Ambarus | 5d0429a | 2014-10-30 18:55:07 +0200 | [diff] [blame] | 451 | return 0; |
| 452 | |
| 453 | /* |
| 454 | * RFC4543 encrypt shared descriptor |
| 455 | * Job Descriptor and Shared Descriptor |
| 456 | * must fit into the 64-word Descriptor h/w Buffer |
| 457 | */ |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 458 | if (rem_bytes >= DESC_RFC4543_ENC_LEN) { |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 459 | ctx->cdata.key_inline = true; |
Arnd Bergmann | 9c0bc51 | 2016-11-30 22:01:59 +0100 | [diff] [blame] | 460 | ctx->cdata.key_virt = ctx->key; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 461 | } else { |
| 462 | ctx->cdata.key_inline = false; |
Arnd Bergmann | 9c0bc51 | 2016-11-30 22:01:59 +0100 | [diff] [blame] | 463 | ctx->cdata.key_dma = ctx->key_dma; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 464 | } |
Tudor Ambarus | 5d0429a | 2014-10-30 18:55:07 +0200 | [diff] [blame] | 465 | |
| 466 | desc = ctx->sh_desc_enc; |
Horia Geantă | 87ec3a0 | 2018-01-29 10:38:36 +0200 | [diff] [blame] | 467 | cnstr_shdsc_rfc4543_encap(desc, &ctx->cdata, ivsize, ctx->authsize, |
| 468 | false); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 469 | dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 470 | desc_bytes(desc), ctx->dir); |
Tudor Ambarus | 5d0429a | 2014-10-30 18:55:07 +0200 | [diff] [blame] | 471 | |
| 472 | /* |
| 473 | * Job Descriptor and Shared Descriptors |
| 474 | * must all fit into the 64-word Descriptor h/w Buffer |
| 475 | */ |
Horia Geantă | 4cbe79c | 2016-11-22 15:44:06 +0200 | [diff] [blame] | 476 | if (rem_bytes >= DESC_RFC4543_DEC_LEN) { |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 477 | ctx->cdata.key_inline = true; |
Arnd Bergmann | 9c0bc51 | 2016-11-30 22:01:59 +0100 | [diff] [blame] | 478 | ctx->cdata.key_virt = ctx->key; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 479 | } else { |
| 480 | ctx->cdata.key_inline = false; |
Arnd Bergmann | 9c0bc51 | 2016-11-30 22:01:59 +0100 | [diff] [blame] | 481 | ctx->cdata.key_dma = ctx->key_dma; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 482 | } |
Tudor Ambarus | 5d0429a | 2014-10-30 18:55:07 +0200 | [diff] [blame] | 483 | |
| 484 | desc = ctx->sh_desc_dec; |
Horia Geantă | 87ec3a0 | 2018-01-29 10:38:36 +0200 | [diff] [blame] | 485 | cnstr_shdsc_rfc4543_decap(desc, &ctx->cdata, ivsize, ctx->authsize, |
| 486 | false); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 487 | dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 488 | desc_bytes(desc), ctx->dir); |
Tudor Ambarus | 5d0429a | 2014-10-30 18:55:07 +0200 | [diff] [blame] | 489 | |
Tudor Ambarus | 5d0429a | 2014-10-30 18:55:07 +0200 | [diff] [blame] | 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | static int rfc4543_setauthsize(struct crypto_aead *authenc, |
| 494 | unsigned int authsize) |
| 495 | { |
| 496 | struct caam_ctx *ctx = crypto_aead_ctx(authenc); |
| 497 | |
Iuliana Prodan | 68a5139 | 2019-07-31 16:08:06 +0300 | [diff] [blame] | 498 | if (authsize != 16) |
| 499 | return -EINVAL; |
| 500 | |
Tudor Ambarus | 5d0429a | 2014-10-30 18:55:07 +0200 | [diff] [blame] | 501 | ctx->authsize = authsize; |
| 502 | rfc4543_set_sh_desc(authenc); |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
Horia Geantă | d6bbd4e | 2018-11-08 15:36:30 +0200 | [diff] [blame] | 507 | static int chachapoly_set_sh_desc(struct crypto_aead *aead) |
| 508 | { |
| 509 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 510 | struct device *jrdev = ctx->jrdev; |
| 511 | unsigned int ivsize = crypto_aead_ivsize(aead); |
| 512 | u32 *desc; |
| 513 | |
| 514 | if (!ctx->cdata.keylen || !ctx->authsize) |
| 515 | return 0; |
| 516 | |
| 517 | desc = ctx->sh_desc_enc; |
| 518 | cnstr_shdsc_chachapoly(desc, &ctx->cdata, &ctx->adata, ivsize, |
Horia Geantă | c10a533 | 2018-11-08 15:36:31 +0200 | [diff] [blame] | 519 | ctx->authsize, true, false); |
Horia Geantă | d6bbd4e | 2018-11-08 15:36:30 +0200 | [diff] [blame] | 520 | dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, |
| 521 | desc_bytes(desc), ctx->dir); |
| 522 | |
| 523 | desc = ctx->sh_desc_dec; |
| 524 | cnstr_shdsc_chachapoly(desc, &ctx->cdata, &ctx->adata, ivsize, |
Horia Geantă | c10a533 | 2018-11-08 15:36:31 +0200 | [diff] [blame] | 525 | ctx->authsize, false, false); |
Horia Geantă | d6bbd4e | 2018-11-08 15:36:30 +0200 | [diff] [blame] | 526 | dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, |
| 527 | desc_bytes(desc), ctx->dir); |
| 528 | |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | static int chachapoly_setauthsize(struct crypto_aead *aead, |
| 533 | unsigned int authsize) |
| 534 | { |
| 535 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 536 | |
| 537 | if (authsize != POLY1305_DIGEST_SIZE) |
| 538 | return -EINVAL; |
| 539 | |
| 540 | ctx->authsize = authsize; |
| 541 | return chachapoly_set_sh_desc(aead); |
| 542 | } |
| 543 | |
| 544 | static int chachapoly_setkey(struct crypto_aead *aead, const u8 *key, |
| 545 | unsigned int keylen) |
| 546 | { |
| 547 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 548 | unsigned int ivsize = crypto_aead_ivsize(aead); |
| 549 | unsigned int saltlen = CHACHAPOLY_IV_SIZE - ivsize; |
| 550 | |
Eric Biggers | 1ca1b91 | 2018-11-16 17:26:21 -0800 | [diff] [blame] | 551 | if (keylen != CHACHA_KEY_SIZE + saltlen) { |
Horia Geantă | d6bbd4e | 2018-11-08 15:36:30 +0200 | [diff] [blame] | 552 | crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 553 | return -EINVAL; |
| 554 | } |
| 555 | |
| 556 | ctx->cdata.key_virt = key; |
| 557 | ctx->cdata.keylen = keylen - saltlen; |
| 558 | |
| 559 | return chachapoly_set_sh_desc(aead); |
| 560 | } |
| 561 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 562 | static int aead_setkey(struct crypto_aead *aead, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 563 | const u8 *key, unsigned int keylen) |
| 564 | { |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 565 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 566 | struct device *jrdev = ctx->jrdev; |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 567 | struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent); |
Horia Geanta | 4e6e0b2 | 2013-12-19 17:27:35 +0200 | [diff] [blame] | 568 | struct crypto_authenc_keys keys; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 569 | int ret = 0; |
| 570 | |
Horia Geanta | 4e6e0b2 | 2013-12-19 17:27:35 +0200 | [diff] [blame] | 571 | if (crypto_authenc_extractkeys(&keys, key, keylen) != 0) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 572 | goto badkey; |
| 573 | |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 574 | dev_dbg(jrdev, "keylen %d enckeylen %d authkeylen %d\n", |
Horia Geanta | 4e6e0b2 | 2013-12-19 17:27:35 +0200 | [diff] [blame] | 575 | keys.authkeylen + keys.enckeylen, keys.enckeylen, |
| 576 | keys.authkeylen); |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 577 | print_hex_dump_debug("key in @"__stringify(__LINE__)": ", |
| 578 | DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 579 | |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 580 | /* |
| 581 | * If DKP is supported, use it in the shared descriptor to generate |
| 582 | * the split key. |
| 583 | */ |
| 584 | if (ctrlpriv->era >= 6) { |
| 585 | ctx->adata.keylen = keys.authkeylen; |
| 586 | ctx->adata.keylen_pad = split_key_len(ctx->adata.algtype & |
| 587 | OP_ALG_ALGSEL_MASK); |
| 588 | |
| 589 | if (ctx->adata.keylen_pad + keys.enckeylen > CAAM_MAX_KEY_SIZE) |
| 590 | goto badkey; |
| 591 | |
| 592 | memcpy(ctx->key, keys.authkey, keys.authkeylen); |
| 593 | memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, |
| 594 | keys.enckeylen); |
| 595 | dma_sync_single_for_device(jrdev, ctx->key_dma, |
| 596 | ctx->adata.keylen_pad + |
| 597 | keys.enckeylen, ctx->dir); |
| 598 | goto skip_split_key; |
| 599 | } |
| 600 | |
Horia Geantă | 6655cb8 | 2016-11-22 15:44:10 +0200 | [diff] [blame] | 601 | ret = gen_split_key(ctx->jrdev, ctx->key, &ctx->adata, keys.authkey, |
| 602 | keys.authkeylen, CAAM_MAX_KEY_SIZE - |
| 603 | keys.enckeylen); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 604 | if (ret) { |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 605 | goto badkey; |
| 606 | } |
| 607 | |
| 608 | /* postpend encryption key to auth split key */ |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 609 | memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 610 | dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->adata.keylen_pad + |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 611 | keys.enckeylen, ctx->dir); |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 612 | |
| 613 | print_hex_dump_debug("ctx.key@"__stringify(__LINE__)": ", |
| 614 | DUMP_PREFIX_ADDRESS, 16, 4, ctx->key, |
| 615 | ctx->adata.keylen_pad + keys.enckeylen, 1); |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 616 | |
| 617 | skip_split_key: |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 618 | ctx->cdata.keylen = keys.enckeylen; |
Tudor-Dan Ambarus | 61dab97 | 2018-03-23 12:42:18 +0200 | [diff] [blame] | 619 | memzero_explicit(&keys, sizeof(keys)); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 620 | return aead_set_sh_desc(aead); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 621 | badkey: |
| 622 | crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN); |
Tudor-Dan Ambarus | 61dab97 | 2018-03-23 12:42:18 +0200 | [diff] [blame] | 623 | memzero_explicit(&keys, sizeof(keys)); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 624 | return -EINVAL; |
| 625 | } |
| 626 | |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 627 | static int des3_aead_setkey(struct crypto_aead *aead, const u8 *key, |
| 628 | unsigned int keylen) |
| 629 | { |
| 630 | struct crypto_authenc_keys keys; |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 631 | int err; |
| 632 | |
| 633 | err = crypto_authenc_extractkeys(&keys, key, keylen); |
| 634 | if (unlikely(err)) |
Ard Biesheuvel | a628c5a | 2019-08-15 12:00:48 +0300 | [diff] [blame] | 635 | return err; |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 636 | |
Ard Biesheuvel | a628c5a | 2019-08-15 12:00:48 +0300 | [diff] [blame] | 637 | err = verify_aead_des3_key(aead, keys.enckey, keys.enckeylen) ?: |
| 638 | aead_setkey(aead, key, keylen); |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 639 | |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 640 | memzero_explicit(&keys, sizeof(keys)); |
| 641 | return err; |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 642 | } |
| 643 | |
Tudor Ambarus | 3ef8d94 | 2014-10-23 16:11:23 +0300 | [diff] [blame] | 644 | static int gcm_setkey(struct crypto_aead *aead, |
| 645 | const u8 *key, unsigned int keylen) |
| 646 | { |
| 647 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 648 | struct device *jrdev = ctx->jrdev; |
Iuliana Prodan | 836d8f4 | 2019-07-31 16:08:05 +0300 | [diff] [blame] | 649 | int err; |
| 650 | |
| 651 | err = aes_check_keylen(keylen); |
| 652 | if (err) { |
| 653 | crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 654 | return err; |
| 655 | } |
Tudor Ambarus | 3ef8d94 | 2014-10-23 16:11:23 +0300 | [diff] [blame] | 656 | |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 657 | print_hex_dump_debug("key in @"__stringify(__LINE__)": ", |
| 658 | DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); |
Tudor Ambarus | 3ef8d94 | 2014-10-23 16:11:23 +0300 | [diff] [blame] | 659 | |
| 660 | memcpy(ctx->key, key, keylen); |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 661 | dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, ctx->dir); |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 662 | ctx->cdata.keylen = keylen; |
Tudor Ambarus | 3ef8d94 | 2014-10-23 16:11:23 +0300 | [diff] [blame] | 663 | |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 664 | return gcm_set_sh_desc(aead); |
Tudor Ambarus | 3ef8d94 | 2014-10-23 16:11:23 +0300 | [diff] [blame] | 665 | } |
| 666 | |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 667 | static int rfc4106_setkey(struct crypto_aead *aead, |
| 668 | const u8 *key, unsigned int keylen) |
| 669 | { |
| 670 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 671 | struct device *jrdev = ctx->jrdev; |
Iuliana Prodan | 836d8f4 | 2019-07-31 16:08:05 +0300 | [diff] [blame] | 672 | int err; |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 673 | |
Iuliana Prodan | 836d8f4 | 2019-07-31 16:08:05 +0300 | [diff] [blame] | 674 | err = aes_check_keylen(keylen - 4); |
| 675 | if (err) { |
| 676 | crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 677 | return err; |
| 678 | } |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 679 | |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 680 | print_hex_dump_debug("key in @"__stringify(__LINE__)": ", |
| 681 | DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 682 | |
| 683 | memcpy(ctx->key, key, keylen); |
| 684 | |
| 685 | /* |
| 686 | * The last four bytes of the key material are used as the salt value |
| 687 | * in the nonce. Update the AES key length. |
| 688 | */ |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 689 | ctx->cdata.keylen = keylen - 4; |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 690 | dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->cdata.keylen, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 691 | ctx->dir); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 692 | return rfc4106_set_sh_desc(aead); |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 693 | } |
| 694 | |
Tudor Ambarus | 5d0429a | 2014-10-30 18:55:07 +0200 | [diff] [blame] | 695 | static int rfc4543_setkey(struct crypto_aead *aead, |
| 696 | const u8 *key, unsigned int keylen) |
| 697 | { |
| 698 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 699 | struct device *jrdev = ctx->jrdev; |
Iuliana Prodan | 836d8f4 | 2019-07-31 16:08:05 +0300 | [diff] [blame] | 700 | int err; |
Tudor Ambarus | 5d0429a | 2014-10-30 18:55:07 +0200 | [diff] [blame] | 701 | |
Iuliana Prodan | 836d8f4 | 2019-07-31 16:08:05 +0300 | [diff] [blame] | 702 | err = aes_check_keylen(keylen - 4); |
| 703 | if (err) { |
| 704 | crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 705 | return err; |
| 706 | } |
Tudor Ambarus | 5d0429a | 2014-10-30 18:55:07 +0200 | [diff] [blame] | 707 | |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 708 | print_hex_dump_debug("key in @"__stringify(__LINE__)": ", |
| 709 | DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); |
Tudor Ambarus | 5d0429a | 2014-10-30 18:55:07 +0200 | [diff] [blame] | 710 | |
| 711 | memcpy(ctx->key, key, keylen); |
| 712 | |
| 713 | /* |
| 714 | * The last four bytes of the key material are used as the salt value |
| 715 | * in the nonce. Update the AES key length. |
| 716 | */ |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 717 | ctx->cdata.keylen = keylen - 4; |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 718 | dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->cdata.keylen, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 719 | ctx->dir); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 720 | return rfc4543_set_sh_desc(aead); |
Tudor Ambarus | 5d0429a | 2014-10-30 18:55:07 +0200 | [diff] [blame] | 721 | } |
| 722 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 723 | static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, |
Iuliana Prodan | 836d8f4 | 2019-07-31 16:08:05 +0300 | [diff] [blame] | 724 | unsigned int keylen, const u32 ctx1_iv_off) |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 725 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 726 | struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher); |
| 727 | struct caam_skcipher_alg *alg = |
| 728 | container_of(crypto_skcipher_alg(skcipher), typeof(*alg), |
| 729 | skcipher); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 730 | struct device *jrdev = ctx->jrdev; |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 731 | unsigned int ivsize = crypto_skcipher_ivsize(skcipher); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 732 | u32 *desc; |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 733 | const bool is_rfc3686 = alg->caam.rfc3686; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 734 | |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 735 | print_hex_dump_debug("key in @"__stringify(__LINE__)": ", |
| 736 | DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); |
Catalin Vasile | a5f57cf | 2014-10-31 12:45:36 +0200 | [diff] [blame] | 737 | |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 738 | ctx->cdata.keylen = keylen; |
Horia Geantă | 662f70e | 2017-12-19 12:16:05 +0200 | [diff] [blame] | 739 | ctx->cdata.key_virt = key; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 740 | ctx->cdata.key_inline = true; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 741 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 742 | /* skcipher_encrypt shared descriptor */ |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 743 | desc = ctx->sh_desc_enc; |
Horia Geantă | 9dbe307 | 2018-08-06 15:44:00 +0300 | [diff] [blame] | 744 | cnstr_shdsc_skcipher_encap(desc, &ctx->cdata, ivsize, is_rfc3686, |
| 745 | ctx1_iv_off); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 746 | dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 747 | desc_bytes(desc), ctx->dir); |
Horia Geantă | 8cea7b6 | 2016-11-22 15:44:09 +0200 | [diff] [blame] | 748 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 749 | /* skcipher_decrypt shared descriptor */ |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 750 | desc = ctx->sh_desc_dec; |
Horia Geantă | 9dbe307 | 2018-08-06 15:44:00 +0300 | [diff] [blame] | 751 | cnstr_shdsc_skcipher_decap(desc, &ctx->cdata, ivsize, is_rfc3686, |
| 752 | ctx1_iv_off); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 753 | dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 754 | desc_bytes(desc), ctx->dir); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 755 | |
Horia Geantă | 8cea7b6 | 2016-11-22 15:44:09 +0200 | [diff] [blame] | 756 | return 0; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 757 | } |
| 758 | |
Iuliana Prodan | 836d8f4 | 2019-07-31 16:08:05 +0300 | [diff] [blame] | 759 | static int aes_skcipher_setkey(struct crypto_skcipher *skcipher, |
| 760 | const u8 *key, unsigned int keylen) |
| 761 | { |
| 762 | int err; |
| 763 | |
| 764 | err = aes_check_keylen(keylen); |
| 765 | if (err) { |
| 766 | crypto_skcipher_set_flags(skcipher, |
| 767 | CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 768 | return err; |
| 769 | } |
| 770 | |
| 771 | return skcipher_setkey(skcipher, key, keylen, 0); |
| 772 | } |
| 773 | |
| 774 | static int rfc3686_skcipher_setkey(struct crypto_skcipher *skcipher, |
| 775 | const u8 *key, unsigned int keylen) |
| 776 | { |
| 777 | u32 ctx1_iv_off; |
| 778 | int err; |
| 779 | |
| 780 | /* |
| 781 | * RFC3686 specific: |
| 782 | * | CONTEXT1[255:128] = {NONCE, IV, COUNTER} |
| 783 | * | *key = {KEY, NONCE} |
| 784 | */ |
| 785 | ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE; |
| 786 | keylen -= CTR_RFC3686_NONCE_SIZE; |
| 787 | |
| 788 | err = aes_check_keylen(keylen); |
| 789 | if (err) { |
| 790 | crypto_skcipher_set_flags(skcipher, |
| 791 | CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 792 | return err; |
| 793 | } |
| 794 | |
| 795 | return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off); |
| 796 | } |
| 797 | |
| 798 | static int ctr_skcipher_setkey(struct crypto_skcipher *skcipher, |
| 799 | const u8 *key, unsigned int keylen) |
| 800 | { |
| 801 | u32 ctx1_iv_off; |
| 802 | int err; |
| 803 | |
| 804 | /* |
| 805 | * AES-CTR needs to load IV in CONTEXT1 reg |
| 806 | * at an offset of 128bits (16bytes) |
| 807 | * CONTEXT1[255:128] = IV |
| 808 | */ |
| 809 | ctx1_iv_off = 16; |
| 810 | |
| 811 | err = aes_check_keylen(keylen); |
| 812 | if (err) { |
| 813 | crypto_skcipher_set_flags(skcipher, |
| 814 | CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 815 | return err; |
| 816 | } |
| 817 | |
| 818 | return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off); |
| 819 | } |
| 820 | |
| 821 | static int arc4_skcipher_setkey(struct crypto_skcipher *skcipher, |
| 822 | const u8 *key, unsigned int keylen) |
| 823 | { |
| 824 | return skcipher_setkey(skcipher, key, keylen, 0); |
| 825 | } |
| 826 | |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 827 | static int des_skcipher_setkey(struct crypto_skcipher *skcipher, |
| 828 | const u8 *key, unsigned int keylen) |
| 829 | { |
Ard Biesheuvel | a628c5a | 2019-08-15 12:00:48 +0300 | [diff] [blame] | 830 | return verify_skcipher_des_key(skcipher, key) ?: |
| 831 | skcipher_setkey(skcipher, key, keylen, 0); |
| 832 | } |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 833 | |
Ard Biesheuvel | a628c5a | 2019-08-15 12:00:48 +0300 | [diff] [blame] | 834 | static int des3_skcipher_setkey(struct crypto_skcipher *skcipher, |
| 835 | const u8 *key, unsigned int keylen) |
| 836 | { |
| 837 | return verify_skcipher_des3_key(skcipher, key) ?: |
| 838 | skcipher_setkey(skcipher, key, keylen, 0); |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 839 | } |
| 840 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 841 | static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, |
| 842 | unsigned int keylen) |
Catalin Vasile | c6415a6 | 2015-10-02 13:13:18 +0300 | [diff] [blame] | 843 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 844 | struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher); |
Catalin Vasile | c6415a6 | 2015-10-02 13:13:18 +0300 | [diff] [blame] | 845 | struct device *jrdev = ctx->jrdev; |
Horia Geantă | 8cea7b6 | 2016-11-22 15:44:09 +0200 | [diff] [blame] | 846 | u32 *desc; |
Catalin Vasile | c6415a6 | 2015-10-02 13:13:18 +0300 | [diff] [blame] | 847 | |
| 848 | if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 849 | crypto_skcipher_set_flags(skcipher, CRYPTO_TFM_RES_BAD_KEY_LEN); |
Catalin Vasile | c6415a6 | 2015-10-02 13:13:18 +0300 | [diff] [blame] | 850 | dev_err(jrdev, "key size mismatch\n"); |
| 851 | return -EINVAL; |
| 852 | } |
| 853 | |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 854 | ctx->cdata.keylen = keylen; |
Horia Geantă | 662f70e | 2017-12-19 12:16:05 +0200 | [diff] [blame] | 855 | ctx->cdata.key_virt = key; |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 856 | ctx->cdata.key_inline = true; |
Catalin Vasile | c6415a6 | 2015-10-02 13:13:18 +0300 | [diff] [blame] | 857 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 858 | /* xts_skcipher_encrypt shared descriptor */ |
Catalin Vasile | c6415a6 | 2015-10-02 13:13:18 +0300 | [diff] [blame] | 859 | desc = ctx->sh_desc_enc; |
Horia Geantă | 9dbe307 | 2018-08-06 15:44:00 +0300 | [diff] [blame] | 860 | cnstr_shdsc_xts_skcipher_encap(desc, &ctx->cdata); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 861 | dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 862 | desc_bytes(desc), ctx->dir); |
Catalin Vasile | c6415a6 | 2015-10-02 13:13:18 +0300 | [diff] [blame] | 863 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 864 | /* xts_skcipher_decrypt shared descriptor */ |
Catalin Vasile | c6415a6 | 2015-10-02 13:13:18 +0300 | [diff] [blame] | 865 | desc = ctx->sh_desc_dec; |
Horia Geantă | 9dbe307 | 2018-08-06 15:44:00 +0300 | [diff] [blame] | 866 | cnstr_shdsc_xts_skcipher_decap(desc, &ctx->cdata); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 867 | dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 868 | desc_bytes(desc), ctx->dir); |
Catalin Vasile | c6415a6 | 2015-10-02 13:13:18 +0300 | [diff] [blame] | 869 | |
| 870 | return 0; |
| 871 | } |
| 872 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 873 | /* |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 874 | * aead_edesc - s/w-extended aead descriptor |
Horia Geantă | fa0c92d | 2017-02-10 14:07:19 +0200 | [diff] [blame] | 875 | * @src_nents: number of segments in input s/w scatterlist |
| 876 | * @dst_nents: number of segments in output s/w scatterlist |
Iuliana Prodan | ba4cf71 | 2019-02-08 15:50:07 +0200 | [diff] [blame] | 877 | * @mapped_src_nents: number of segments in input h/w link table |
| 878 | * @mapped_dst_nents: number of segments in output h/w link table |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 879 | * @sec4_sg_bytes: length of dma mapped sec4_sg space |
| 880 | * @sec4_sg_dma: bus physical mapped address of h/w link table |
Horia Geantă | 4ca7c7d | 2016-11-09 10:46:18 +0200 | [diff] [blame] | 881 | * @sec4_sg: pointer to h/w link table |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 882 | * @hw_desc: the h/w job descriptor followed by any referenced link tables |
| 883 | */ |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 884 | struct aead_edesc { |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 885 | int src_nents; |
| 886 | int dst_nents; |
Iuliana Prodan | ba4cf71 | 2019-02-08 15:50:07 +0200 | [diff] [blame] | 887 | int mapped_src_nents; |
| 888 | int mapped_dst_nents; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 889 | int sec4_sg_bytes; |
| 890 | dma_addr_t sec4_sg_dma; |
| 891 | struct sec4_sg_entry *sec4_sg; |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 892 | u32 hw_desc[]; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 893 | }; |
| 894 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 895 | /* |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 896 | * skcipher_edesc - s/w-extended skcipher descriptor |
Horia Geantă | fa0c92d | 2017-02-10 14:07:19 +0200 | [diff] [blame] | 897 | * @src_nents: number of segments in input s/w scatterlist |
| 898 | * @dst_nents: number of segments in output s/w scatterlist |
Iuliana Prodan | ba4cf71 | 2019-02-08 15:50:07 +0200 | [diff] [blame] | 899 | * @mapped_src_nents: number of segments in input h/w link table |
| 900 | * @mapped_dst_nents: number of segments in output h/w link table |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 901 | * @iv_dma: dma address of iv for checking continuity and link table |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 902 | * @sec4_sg_bytes: length of dma mapped sec4_sg space |
| 903 | * @sec4_sg_dma: bus physical mapped address of h/w link table |
Horia Geantă | 4ca7c7d | 2016-11-09 10:46:18 +0200 | [diff] [blame] | 904 | * @sec4_sg: pointer to h/w link table |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 905 | * @hw_desc: the h/w job descriptor followed by any referenced link tables |
Horia Geantă | 115957b | 2018-03-28 15:39:18 +0300 | [diff] [blame] | 906 | * and IV |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 907 | */ |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 908 | struct skcipher_edesc { |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 909 | int src_nents; |
| 910 | int dst_nents; |
Iuliana Prodan | ba4cf71 | 2019-02-08 15:50:07 +0200 | [diff] [blame] | 911 | int mapped_src_nents; |
| 912 | int mapped_dst_nents; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 913 | dma_addr_t iv_dma; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 914 | int sec4_sg_bytes; |
| 915 | dma_addr_t sec4_sg_dma; |
| 916 | struct sec4_sg_entry *sec4_sg; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 917 | u32 hw_desc[0]; |
| 918 | }; |
| 919 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 920 | static void caam_unmap(struct device *dev, struct scatterlist *src, |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 921 | struct scatterlist *dst, int src_nents, |
LABBE Corentin | 13fb8fd | 2015-09-23 13:55:27 +0200 | [diff] [blame] | 922 | int dst_nents, |
Horia Geantă | cf5448b | 2018-08-06 15:43:57 +0300 | [diff] [blame] | 923 | dma_addr_t iv_dma, int ivsize, dma_addr_t sec4_sg_dma, |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 924 | int sec4_sg_bytes) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 925 | { |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 926 | if (dst != src) { |
Horia Geantă | fa0c92d | 2017-02-10 14:07:19 +0200 | [diff] [blame] | 927 | if (src_nents) |
| 928 | dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE); |
Horia Geantă | 763069b | 2019-01-22 16:47:01 +0200 | [diff] [blame] | 929 | if (dst_nents) |
| 930 | dma_unmap_sg(dev, dst, dst_nents, DMA_FROM_DEVICE); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 931 | } else { |
Horia Geantă | fa0c92d | 2017-02-10 14:07:19 +0200 | [diff] [blame] | 932 | dma_unmap_sg(dev, src, src_nents, DMA_BIDIRECTIONAL); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 933 | } |
| 934 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 935 | if (iv_dma) |
Horia Geantă | 334d37c | 2019-06-10 16:30:59 +0300 | [diff] [blame] | 936 | dma_unmap_single(dev, iv_dma, ivsize, DMA_BIDIRECTIONAL); |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 937 | if (sec4_sg_bytes) |
| 938 | dma_unmap_single(dev, sec4_sg_dma, sec4_sg_bytes, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 939 | DMA_TO_DEVICE); |
| 940 | } |
| 941 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 942 | static void aead_unmap(struct device *dev, |
| 943 | struct aead_edesc *edesc, |
| 944 | struct aead_request *req) |
| 945 | { |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 946 | caam_unmap(dev, req->src, req->dst, |
Horia Geantă | cf5448b | 2018-08-06 15:43:57 +0300 | [diff] [blame] | 947 | edesc->src_nents, edesc->dst_nents, 0, 0, |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 948 | edesc->sec4_sg_dma, edesc->sec4_sg_bytes); |
| 949 | } |
| 950 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 951 | static void skcipher_unmap(struct device *dev, struct skcipher_edesc *edesc, |
| 952 | struct skcipher_request *req) |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 953 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 954 | struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); |
| 955 | int ivsize = crypto_skcipher_ivsize(skcipher); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 956 | |
| 957 | caam_unmap(dev, req->src, req->dst, |
LABBE Corentin | 13fb8fd | 2015-09-23 13:55:27 +0200 | [diff] [blame] | 958 | edesc->src_nents, edesc->dst_nents, |
Horia Geantă | cf5448b | 2018-08-06 15:43:57 +0300 | [diff] [blame] | 959 | edesc->iv_dma, ivsize, |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 960 | edesc->sec4_sg_dma, edesc->sec4_sg_bytes); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 961 | } |
| 962 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 963 | static void aead_encrypt_done(struct device *jrdev, u32 *desc, u32 err, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 964 | void *context) |
| 965 | { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 966 | struct aead_request *req = context; |
| 967 | struct aead_edesc *edesc; |
Horia Geantă | 1984aae | 2019-07-31 16:08:03 +0300 | [diff] [blame] | 968 | int ecode = 0; |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 969 | |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 970 | dev_dbg(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 971 | |
| 972 | edesc = container_of(desc, struct aead_edesc, hw_desc[0]); |
| 973 | |
| 974 | if (err) |
Horia Geantă | 1984aae | 2019-07-31 16:08:03 +0300 | [diff] [blame] | 975 | ecode = caam_jr_strstatus(jrdev, err); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 976 | |
| 977 | aead_unmap(jrdev, edesc, req); |
| 978 | |
| 979 | kfree(edesc); |
| 980 | |
Horia Geantă | 1984aae | 2019-07-31 16:08:03 +0300 | [diff] [blame] | 981 | aead_request_complete(req, ecode); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 982 | } |
| 983 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 984 | static void aead_decrypt_done(struct device *jrdev, u32 *desc, u32 err, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 985 | void *context) |
| 986 | { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 987 | struct aead_request *req = context; |
| 988 | struct aead_edesc *edesc; |
Horia Geantă | 1984aae | 2019-07-31 16:08:03 +0300 | [diff] [blame] | 989 | int ecode = 0; |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 990 | |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 991 | dev_dbg(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 992 | |
| 993 | edesc = container_of(desc, struct aead_edesc, hw_desc[0]); |
| 994 | |
| 995 | if (err) |
Horia Geantă | 1984aae | 2019-07-31 16:08:03 +0300 | [diff] [blame] | 996 | ecode = caam_jr_strstatus(jrdev, err); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 997 | |
| 998 | aead_unmap(jrdev, edesc, req); |
| 999 | |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1000 | kfree(edesc); |
| 1001 | |
Horia Geantă | 1984aae | 2019-07-31 16:08:03 +0300 | [diff] [blame] | 1002 | aead_request_complete(req, ecode); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1003 | } |
| 1004 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1005 | static void skcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err, |
| 1006 | void *context) |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1007 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1008 | struct skcipher_request *req = context; |
| 1009 | struct skcipher_edesc *edesc; |
| 1010 | struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); |
| 1011 | int ivsize = crypto_skcipher_ivsize(skcipher); |
Horia Geantă | 1984aae | 2019-07-31 16:08:03 +0300 | [diff] [blame] | 1012 | int ecode = 0; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1013 | |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 1014 | dev_dbg(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1015 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1016 | edesc = container_of(desc, struct skcipher_edesc, hw_desc[0]); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1017 | |
Marek Vasut | fa9659c | 2014-04-24 20:05:12 +0200 | [diff] [blame] | 1018 | if (err) |
Horia Geantă | 1984aae | 2019-07-31 16:08:03 +0300 | [diff] [blame] | 1019 | ecode = caam_jr_strstatus(jrdev, err); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1020 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1021 | skcipher_unmap(jrdev, edesc, req); |
David Gstir | 854b06f | 2017-06-28 15:27:10 +0200 | [diff] [blame] | 1022 | |
| 1023 | /* |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1024 | * The crypto API expects us to set the IV (req->iv) to the last |
Horia Geantă | 334d37c | 2019-06-10 16:30:59 +0300 | [diff] [blame] | 1025 | * ciphertext block (CBC mode) or last counter (CTR mode). |
| 1026 | * This is used e.g. by the CTS mode. |
David Gstir | 854b06f | 2017-06-28 15:27:10 +0200 | [diff] [blame] | 1027 | */ |
Horia Geantă | 1ccb39e | 2019-07-31 16:08:04 +0300 | [diff] [blame] | 1028 | if (ivsize && !ecode) { |
Horia Geantă | 334d37c | 2019-06-10 16:30:59 +0300 | [diff] [blame] | 1029 | memcpy(req->iv, (u8 *)edesc->sec4_sg + edesc->sec4_sg_bytes, |
| 1030 | ivsize); |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 1031 | print_hex_dump_debug("dstiv @"__stringify(__LINE__)": ", |
| 1032 | DUMP_PREFIX_ADDRESS, 16, 4, req->iv, |
| 1033 | edesc->src_nents > 1 ? 100 : ivsize, 1); |
Horia Geantă | 334d37c | 2019-06-10 16:30:59 +0300 | [diff] [blame] | 1034 | } |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 1035 | |
Sascha Hauer | 8a82451 | 2019-05-23 10:50:30 +0200 | [diff] [blame] | 1036 | caam_dump_sg("dst @" __stringify(__LINE__)": ", |
Sascha Hauer | bb992bc | 2019-05-16 16:24:42 +0200 | [diff] [blame] | 1037 | DUMP_PREFIX_ADDRESS, 16, 4, req->dst, |
| 1038 | edesc->dst_nents > 1 ? 100 : req->cryptlen, 1); |
| 1039 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1040 | kfree(edesc); |
| 1041 | |
Horia Geantă | 1984aae | 2019-07-31 16:08:03 +0300 | [diff] [blame] | 1042 | skcipher_request_complete(req, ecode); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1043 | } |
| 1044 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1045 | static void skcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err, |
| 1046 | void *context) |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1047 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1048 | struct skcipher_request *req = context; |
| 1049 | struct skcipher_edesc *edesc; |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1050 | struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); |
| 1051 | int ivsize = crypto_skcipher_ivsize(skcipher); |
Horia Geantă | 1984aae | 2019-07-31 16:08:03 +0300 | [diff] [blame] | 1052 | int ecode = 0; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1053 | |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 1054 | dev_dbg(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1055 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1056 | edesc = container_of(desc, struct skcipher_edesc, hw_desc[0]); |
Marek Vasut | fa9659c | 2014-04-24 20:05:12 +0200 | [diff] [blame] | 1057 | if (err) |
Horia Geantă | 1984aae | 2019-07-31 16:08:03 +0300 | [diff] [blame] | 1058 | ecode = caam_jr_strstatus(jrdev, err); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1059 | |
Sascha Hauer | bb992bc | 2019-05-16 16:24:42 +0200 | [diff] [blame] | 1060 | skcipher_unmap(jrdev, edesc, req); |
| 1061 | |
Horia Geantă | 334d37c | 2019-06-10 16:30:59 +0300 | [diff] [blame] | 1062 | /* |
| 1063 | * The crypto API expects us to set the IV (req->iv) to the last |
| 1064 | * ciphertext block (CBC mode) or last counter (CTR mode). |
| 1065 | * This is used e.g. by the CTS mode. |
| 1066 | */ |
Horia Geantă | 1ccb39e | 2019-07-31 16:08:04 +0300 | [diff] [blame] | 1067 | if (ivsize && !ecode) { |
Horia Geantă | 334d37c | 2019-06-10 16:30:59 +0300 | [diff] [blame] | 1068 | memcpy(req->iv, (u8 *)edesc->sec4_sg + edesc->sec4_sg_bytes, |
| 1069 | ivsize); |
| 1070 | |
| 1071 | print_hex_dump_debug("dstiv @" __stringify(__LINE__)": ", |
| 1072 | DUMP_PREFIX_ADDRESS, 16, 4, req->iv, |
| 1073 | ivsize, 1); |
| 1074 | } |
| 1075 | |
Sascha Hauer | 8a82451 | 2019-05-23 10:50:30 +0200 | [diff] [blame] | 1076 | caam_dump_sg("dst @" __stringify(__LINE__)": ", |
Horia Geantă | 972b812 | 2017-07-10 08:40:28 +0300 | [diff] [blame] | 1077 | DUMP_PREFIX_ADDRESS, 16, 4, req->dst, |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1078 | edesc->dst_nents > 1 ? 100 : req->cryptlen, 1); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1079 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1080 | kfree(edesc); |
| 1081 | |
Horia Geantă | 1984aae | 2019-07-31 16:08:03 +0300 | [diff] [blame] | 1082 | skcipher_request_complete(req, ecode); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1083 | } |
| 1084 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1085 | /* |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1086 | * Fill in aead job descriptor |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1087 | */ |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1088 | static void init_aead_job(struct aead_request *req, |
| 1089 | struct aead_edesc *edesc, |
| 1090 | bool all_contig, bool encrypt) |
| 1091 | { |
| 1092 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
| 1093 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 1094 | int authsize = ctx->authsize; |
| 1095 | u32 *desc = edesc->hw_desc; |
| 1096 | u32 out_options, in_options; |
| 1097 | dma_addr_t dst_dma, src_dma; |
| 1098 | int len, sec4_sg_index = 0; |
| 1099 | dma_addr_t ptr; |
| 1100 | u32 *sh_desc; |
| 1101 | |
| 1102 | sh_desc = encrypt ? ctx->sh_desc_enc : ctx->sh_desc_dec; |
| 1103 | ptr = encrypt ? ctx->sh_desc_enc_dma : ctx->sh_desc_dec_dma; |
| 1104 | |
| 1105 | len = desc_len(sh_desc); |
| 1106 | init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE); |
| 1107 | |
| 1108 | if (all_contig) { |
Iuliana Prodan | ba4cf71 | 2019-02-08 15:50:07 +0200 | [diff] [blame] | 1109 | src_dma = edesc->mapped_src_nents ? sg_dma_address(req->src) : |
| 1110 | 0; |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1111 | in_options = 0; |
| 1112 | } else { |
| 1113 | src_dma = edesc->sec4_sg_dma; |
Iuliana Prodan | ba4cf71 | 2019-02-08 15:50:07 +0200 | [diff] [blame] | 1114 | sec4_sg_index += edesc->mapped_src_nents; |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1115 | in_options = LDST_SGF; |
| 1116 | } |
| 1117 | |
| 1118 | append_seq_in_ptr(desc, src_dma, req->assoclen + req->cryptlen, |
| 1119 | in_options); |
| 1120 | |
| 1121 | dst_dma = src_dma; |
| 1122 | out_options = in_options; |
| 1123 | |
| 1124 | if (unlikely(req->src != req->dst)) { |
Iuliana Prodan | ba4cf71 | 2019-02-08 15:50:07 +0200 | [diff] [blame] | 1125 | if (!edesc->mapped_dst_nents) { |
Horia Geantă | 763069b | 2019-01-22 16:47:01 +0200 | [diff] [blame] | 1126 | dst_dma = 0; |
Horia Geantă | dcd9c76 | 2019-05-03 17:17:37 +0300 | [diff] [blame] | 1127 | out_options = 0; |
Iuliana Prodan | ba4cf71 | 2019-02-08 15:50:07 +0200 | [diff] [blame] | 1128 | } else if (edesc->mapped_dst_nents == 1) { |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1129 | dst_dma = sg_dma_address(req->dst); |
Pankaj Gupta | 42e95d1 | 2019-02-01 07:18:20 +0000 | [diff] [blame] | 1130 | out_options = 0; |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1131 | } else { |
| 1132 | dst_dma = edesc->sec4_sg_dma + |
| 1133 | sec4_sg_index * |
| 1134 | sizeof(struct sec4_sg_entry); |
| 1135 | out_options = LDST_SGF; |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | if (encrypt) |
| 1140 | append_seq_out_ptr(desc, dst_dma, |
| 1141 | req->assoclen + req->cryptlen + authsize, |
| 1142 | out_options); |
| 1143 | else |
| 1144 | append_seq_out_ptr(desc, dst_dma, |
| 1145 | req->assoclen + req->cryptlen - authsize, |
| 1146 | out_options); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | static void init_gcm_job(struct aead_request *req, |
| 1150 | struct aead_edesc *edesc, |
| 1151 | bool all_contig, bool encrypt) |
| 1152 | { |
| 1153 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
| 1154 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 1155 | unsigned int ivsize = crypto_aead_ivsize(aead); |
| 1156 | u32 *desc = edesc->hw_desc; |
Corentin LABBE | 7545e16 | 2017-08-22 10:08:09 +0200 | [diff] [blame] | 1157 | bool generic_gcm = (ivsize == GCM_AES_IV_SIZE); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1158 | unsigned int last; |
| 1159 | |
| 1160 | init_aead_job(req, edesc, all_contig, encrypt); |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 1161 | append_math_add_imm_u32(desc, REG3, ZERO, IMM, req->assoclen); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1162 | |
| 1163 | /* BUG This should not be specific to generic GCM. */ |
| 1164 | last = 0; |
| 1165 | if (encrypt && generic_gcm && !(req->assoclen + req->cryptlen)) |
| 1166 | last = FIFOLD_TYPE_LAST1; |
| 1167 | |
| 1168 | /* Read GCM IV */ |
| 1169 | append_cmd(desc, CMD_FIFO_LOAD | FIFOLD_CLASS_CLASS1 | IMMEDIATE | |
Corentin LABBE | 7545e16 | 2017-08-22 10:08:09 +0200 | [diff] [blame] | 1170 | FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1 | GCM_AES_IV_SIZE | last); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1171 | /* Append Salt */ |
| 1172 | if (!generic_gcm) |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 1173 | append_data(desc, ctx->key + ctx->cdata.keylen, 4); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1174 | /* Append IV */ |
| 1175 | append_data(desc, req->iv, ivsize); |
| 1176 | /* End of blank commands */ |
| 1177 | } |
| 1178 | |
Horia Geantă | d6bbd4e | 2018-11-08 15:36:30 +0200 | [diff] [blame] | 1179 | static void init_chachapoly_job(struct aead_request *req, |
| 1180 | struct aead_edesc *edesc, bool all_contig, |
| 1181 | bool encrypt) |
| 1182 | { |
| 1183 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
| 1184 | unsigned int ivsize = crypto_aead_ivsize(aead); |
| 1185 | unsigned int assoclen = req->assoclen; |
| 1186 | u32 *desc = edesc->hw_desc; |
| 1187 | u32 ctx_iv_off = 4; |
| 1188 | |
| 1189 | init_aead_job(req, edesc, all_contig, encrypt); |
| 1190 | |
| 1191 | if (ivsize != CHACHAPOLY_IV_SIZE) { |
| 1192 | /* IPsec specific: CONTEXT1[223:128] = {NONCE, IV} */ |
| 1193 | ctx_iv_off += 4; |
| 1194 | |
| 1195 | /* |
| 1196 | * The associated data comes already with the IV but we need |
| 1197 | * to skip it when we authenticate or encrypt... |
| 1198 | */ |
| 1199 | assoclen -= ivsize; |
| 1200 | } |
| 1201 | |
| 1202 | append_math_add_imm_u32(desc, REG3, ZERO, IMM, assoclen); |
| 1203 | |
| 1204 | /* |
| 1205 | * For IPsec load the IV further in the same register. |
| 1206 | * For RFC7539 simply load the 12 bytes nonce in a single operation |
| 1207 | */ |
| 1208 | append_load_as_imm(desc, req->iv, ivsize, LDST_CLASS_1_CCB | |
| 1209 | LDST_SRCDST_BYTE_CONTEXT | |
| 1210 | ctx_iv_off << LDST_OFFSET_SHIFT); |
| 1211 | } |
| 1212 | |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1213 | static void init_authenc_job(struct aead_request *req, |
| 1214 | struct aead_edesc *edesc, |
| 1215 | bool all_contig, bool encrypt) |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1216 | { |
| 1217 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1218 | struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead), |
| 1219 | struct caam_aead_alg, aead); |
| 1220 | unsigned int ivsize = crypto_aead_ivsize(aead); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1221 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 1222 | struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctx->jrdev->parent); |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 1223 | const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) == |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1224 | OP_ALG_AAI_CTR_MOD128); |
| 1225 | const bool is_rfc3686 = alg->caam.rfc3686; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1226 | u32 *desc = edesc->hw_desc; |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1227 | u32 ivoffset = 0; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1228 | |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1229 | /* |
| 1230 | * AES-CTR needs to load IV in CONTEXT1 reg |
| 1231 | * at an offset of 128bits (16bytes) |
| 1232 | * CONTEXT1[255:128] = IV |
| 1233 | */ |
| 1234 | if (ctr_mode) |
| 1235 | ivoffset = 16; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1236 | |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1237 | /* |
| 1238 | * RFC3686 specific: |
| 1239 | * CONTEXT1[255:128] = {NONCE, IV, COUNTER} |
| 1240 | */ |
| 1241 | if (is_rfc3686) |
| 1242 | ivoffset = 16 + CTR_RFC3686_NONCE_SIZE; |
Tudor Ambarus | bac68f2 | 2014-10-23 16:14:03 +0300 | [diff] [blame] | 1243 | |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1244 | init_aead_job(req, edesc, all_contig, encrypt); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1245 | |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 1246 | /* |
| 1247 | * {REG3, DPOVRD} = assoclen, depending on whether MATH command supports |
| 1248 | * having DPOVRD as destination. |
| 1249 | */ |
| 1250 | if (ctrlpriv->era < 3) |
| 1251 | append_math_add_imm_u32(desc, REG3, ZERO, IMM, req->assoclen); |
| 1252 | else |
| 1253 | append_math_add_imm_u32(desc, DPOVRD, ZERO, IMM, req->assoclen); |
| 1254 | |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 1255 | if (ivsize && ((is_rfc3686 && encrypt) || !alg->caam.geniv)) |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1256 | append_load_as_imm(desc, req->iv, ivsize, |
| 1257 | LDST_CLASS_1_CCB | |
| 1258 | LDST_SRCDST_BYTE_CONTEXT | |
| 1259 | (ivoffset << LDST_OFFSET_SHIFT)); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | /* |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1263 | * Fill in skcipher job descriptor |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1264 | */ |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1265 | static void init_skcipher_job(struct skcipher_request *req, |
| 1266 | struct skcipher_edesc *edesc, |
| 1267 | const bool encrypt) |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1268 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1269 | struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); |
| 1270 | struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher); |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 1271 | struct device *jrdev = ctx->jrdev; |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1272 | int ivsize = crypto_skcipher_ivsize(skcipher); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1273 | u32 *desc = edesc->hw_desc; |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1274 | u32 *sh_desc; |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 1275 | u32 in_options = 0, out_options = 0; |
| 1276 | dma_addr_t src_dma, dst_dma, ptr; |
| 1277 | int len, sec4_sg_index = 0; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1278 | |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 1279 | print_hex_dump_debug("presciv@"__stringify(__LINE__)": ", |
| 1280 | DUMP_PREFIX_ADDRESS, 16, 4, req->iv, ivsize, 1); |
| 1281 | dev_dbg(jrdev, "asked=%d, cryptlen%d\n", |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1282 | (int)edesc->src_nents > 1 ? 100 : req->cryptlen, req->cryptlen); |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 1283 | |
Sascha Hauer | 8a82451 | 2019-05-23 10:50:30 +0200 | [diff] [blame] | 1284 | caam_dump_sg("src @" __stringify(__LINE__)": ", |
Horia Geantă | 972b812 | 2017-07-10 08:40:28 +0300 | [diff] [blame] | 1285 | DUMP_PREFIX_ADDRESS, 16, 4, req->src, |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1286 | edesc->src_nents > 1 ? 100 : req->cryptlen, 1); |
| 1287 | |
| 1288 | sh_desc = encrypt ? ctx->sh_desc_enc : ctx->sh_desc_dec; |
| 1289 | ptr = encrypt ? ctx->sh_desc_enc_dma : ctx->sh_desc_dec_dma; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1290 | |
| 1291 | len = desc_len(sh_desc); |
| 1292 | init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE); |
| 1293 | |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 1294 | if (ivsize || edesc->mapped_src_nents > 1) { |
| 1295 | src_dma = edesc->sec4_sg_dma; |
| 1296 | sec4_sg_index = edesc->mapped_src_nents + !!ivsize; |
| 1297 | in_options = LDST_SGF; |
| 1298 | } else { |
| 1299 | src_dma = sg_dma_address(req->src); |
| 1300 | } |
| 1301 | |
| 1302 | append_seq_in_ptr(desc, src_dma, req->cryptlen + ivsize, in_options); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1303 | |
| 1304 | if (likely(req->src == req->dst)) { |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 1305 | dst_dma = src_dma + !!ivsize * sizeof(struct sec4_sg_entry); |
| 1306 | out_options = in_options; |
Horia Geantă | 334d37c | 2019-06-10 16:30:59 +0300 | [diff] [blame] | 1307 | } else if (!ivsize && edesc->mapped_dst_nents == 1) { |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 1308 | dst_dma = sg_dma_address(req->dst); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1309 | } else { |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 1310 | dst_dma = edesc->sec4_sg_dma + sec4_sg_index * |
| 1311 | sizeof(struct sec4_sg_entry); |
| 1312 | out_options = LDST_SGF; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1313 | } |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 1314 | |
Horia Geantă | 334d37c | 2019-06-10 16:30:59 +0300 | [diff] [blame] | 1315 | append_seq_out_ptr(desc, dst_dma, req->cryptlen + ivsize, out_options); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | /* |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1319 | * allocate and map the aead extended descriptor |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1320 | */ |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1321 | static struct aead_edesc *aead_edesc_alloc(struct aead_request *req, |
| 1322 | int desc_bytes, bool *all_contig_ptr, |
| 1323 | bool encrypt) |
| 1324 | { |
| 1325 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
| 1326 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 1327 | struct device *jrdev = ctx->jrdev; |
Horia Geantă | 019d62d | 2017-06-19 11:44:46 +0300 | [diff] [blame] | 1328 | gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? |
| 1329 | GFP_KERNEL : GFP_ATOMIC; |
Horia Geantă | 838e0a8 | 2017-02-10 14:07:20 +0200 | [diff] [blame] | 1330 | int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0; |
Horia Geantă | 059d73e | 2019-06-10 16:30:58 +0300 | [diff] [blame] | 1331 | int src_len, dst_len = 0; |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1332 | struct aead_edesc *edesc; |
Horia Geantă | fa0c92d | 2017-02-10 14:07:19 +0200 | [diff] [blame] | 1333 | int sec4_sg_index, sec4_sg_len, sec4_sg_bytes; |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1334 | unsigned int authsize = ctx->authsize; |
| 1335 | |
| 1336 | if (unlikely(req->dst != req->src)) { |
Horia Geantă | 059d73e | 2019-06-10 16:30:58 +0300 | [diff] [blame] | 1337 | src_len = req->assoclen + req->cryptlen; |
| 1338 | dst_len = src_len + (encrypt ? authsize : (-authsize)); |
| 1339 | |
| 1340 | src_nents = sg_nents_for_len(req->src, src_len); |
Horia Geantă | fd144d8 | 2017-02-10 14:07:18 +0200 | [diff] [blame] | 1341 | if (unlikely(src_nents < 0)) { |
| 1342 | dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n", |
Horia Geantă | 059d73e | 2019-06-10 16:30:58 +0300 | [diff] [blame] | 1343 | src_len); |
Horia Geantă | fd144d8 | 2017-02-10 14:07:18 +0200 | [diff] [blame] | 1344 | return ERR_PTR(src_nents); |
| 1345 | } |
| 1346 | |
Horia Geantă | 059d73e | 2019-06-10 16:30:58 +0300 | [diff] [blame] | 1347 | dst_nents = sg_nents_for_len(req->dst, dst_len); |
Horia Geantă | fd144d8 | 2017-02-10 14:07:18 +0200 | [diff] [blame] | 1348 | if (unlikely(dst_nents < 0)) { |
| 1349 | dev_err(jrdev, "Insufficient bytes (%d) in dst S/G\n", |
Horia Geantă | 059d73e | 2019-06-10 16:30:58 +0300 | [diff] [blame] | 1350 | dst_len); |
Horia Geantă | fd144d8 | 2017-02-10 14:07:18 +0200 | [diff] [blame] | 1351 | return ERR_PTR(dst_nents); |
| 1352 | } |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1353 | } else { |
Horia Geantă | 059d73e | 2019-06-10 16:30:58 +0300 | [diff] [blame] | 1354 | src_len = req->assoclen + req->cryptlen + |
| 1355 | (encrypt ? authsize : 0); |
| 1356 | |
| 1357 | src_nents = sg_nents_for_len(req->src, src_len); |
Horia Geantă | fd144d8 | 2017-02-10 14:07:18 +0200 | [diff] [blame] | 1358 | if (unlikely(src_nents < 0)) { |
| 1359 | dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n", |
Horia Geantă | 059d73e | 2019-06-10 16:30:58 +0300 | [diff] [blame] | 1360 | src_len); |
Horia Geantă | fd144d8 | 2017-02-10 14:07:18 +0200 | [diff] [blame] | 1361 | return ERR_PTR(src_nents); |
| 1362 | } |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1363 | } |
| 1364 | |
Horia Geantă | 838e0a8 | 2017-02-10 14:07:20 +0200 | [diff] [blame] | 1365 | if (likely(req->src == req->dst)) { |
| 1366 | mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents, |
| 1367 | DMA_BIDIRECTIONAL); |
| 1368 | if (unlikely(!mapped_src_nents)) { |
| 1369 | dev_err(jrdev, "unable to map source\n"); |
| 1370 | return ERR_PTR(-ENOMEM); |
| 1371 | } |
| 1372 | } else { |
| 1373 | /* Cover also the case of null (zero length) input data */ |
| 1374 | if (src_nents) { |
| 1375 | mapped_src_nents = dma_map_sg(jrdev, req->src, |
| 1376 | src_nents, DMA_TO_DEVICE); |
| 1377 | if (unlikely(!mapped_src_nents)) { |
| 1378 | dev_err(jrdev, "unable to map source\n"); |
| 1379 | return ERR_PTR(-ENOMEM); |
| 1380 | } |
| 1381 | } else { |
| 1382 | mapped_src_nents = 0; |
| 1383 | } |
| 1384 | |
Horia Geantă | 763069b | 2019-01-22 16:47:01 +0200 | [diff] [blame] | 1385 | /* Cover also the case of null (zero length) output data */ |
| 1386 | if (dst_nents) { |
| 1387 | mapped_dst_nents = dma_map_sg(jrdev, req->dst, |
| 1388 | dst_nents, |
| 1389 | DMA_FROM_DEVICE); |
| 1390 | if (unlikely(!mapped_dst_nents)) { |
| 1391 | dev_err(jrdev, "unable to map destination\n"); |
| 1392 | dma_unmap_sg(jrdev, req->src, src_nents, |
| 1393 | DMA_TO_DEVICE); |
| 1394 | return ERR_PTR(-ENOMEM); |
| 1395 | } |
| 1396 | } else { |
| 1397 | mapped_dst_nents = 0; |
Horia Geantă | 838e0a8 | 2017-02-10 14:07:20 +0200 | [diff] [blame] | 1398 | } |
| 1399 | } |
| 1400 | |
Horia Geantă | a5e5c13 | 2019-05-03 17:17:38 +0300 | [diff] [blame] | 1401 | /* |
| 1402 | * HW reads 4 S/G entries at a time; make sure the reads don't go beyond |
| 1403 | * the end of the table by allocating more S/G entries. |
| 1404 | */ |
Horia Geantă | 838e0a8 | 2017-02-10 14:07:20 +0200 | [diff] [blame] | 1405 | sec4_sg_len = mapped_src_nents > 1 ? mapped_src_nents : 0; |
Horia Geantă | a5e5c13 | 2019-05-03 17:17:38 +0300 | [diff] [blame] | 1406 | if (mapped_dst_nents > 1) |
| 1407 | sec4_sg_len += pad_sg_nents(mapped_dst_nents); |
| 1408 | else |
| 1409 | sec4_sg_len = pad_sg_nents(sec4_sg_len); |
| 1410 | |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1411 | sec4_sg_bytes = sec4_sg_len * sizeof(struct sec4_sg_entry); |
| 1412 | |
| 1413 | /* allocate space for base edesc and hw desc commands, link tables */ |
Victoria Milhoan | dde20ae | 2015-08-05 11:28:39 -0700 | [diff] [blame] | 1414 | edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes, |
| 1415 | GFP_DMA | flags); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1416 | if (!edesc) { |
Horia Geantă | 838e0a8 | 2017-02-10 14:07:20 +0200 | [diff] [blame] | 1417 | caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0, |
Horia Geantă | cf5448b | 2018-08-06 15:43:57 +0300 | [diff] [blame] | 1418 | 0, 0, 0); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1419 | return ERR_PTR(-ENOMEM); |
| 1420 | } |
| 1421 | |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1422 | edesc->src_nents = src_nents; |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1423 | edesc->dst_nents = dst_nents; |
Iuliana Prodan | ba4cf71 | 2019-02-08 15:50:07 +0200 | [diff] [blame] | 1424 | edesc->mapped_src_nents = mapped_src_nents; |
| 1425 | edesc->mapped_dst_nents = mapped_dst_nents; |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1426 | edesc->sec4_sg = (void *)edesc + sizeof(struct aead_edesc) + |
| 1427 | desc_bytes; |
Horia Geantă | 838e0a8 | 2017-02-10 14:07:20 +0200 | [diff] [blame] | 1428 | *all_contig_ptr = !(mapped_src_nents > 1); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1429 | |
| 1430 | sec4_sg_index = 0; |
Horia Geantă | 838e0a8 | 2017-02-10 14:07:20 +0200 | [diff] [blame] | 1431 | if (mapped_src_nents > 1) { |
Horia Geantă | 059d73e | 2019-06-10 16:30:58 +0300 | [diff] [blame] | 1432 | sg_to_sec4_sg_last(req->src, src_len, |
Horia Geantă | 838e0a8 | 2017-02-10 14:07:20 +0200 | [diff] [blame] | 1433 | edesc->sec4_sg + sec4_sg_index, 0); |
| 1434 | sec4_sg_index += mapped_src_nents; |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1435 | } |
Horia Geantă | 838e0a8 | 2017-02-10 14:07:20 +0200 | [diff] [blame] | 1436 | if (mapped_dst_nents > 1) { |
Horia Geantă | 059d73e | 2019-06-10 16:30:58 +0300 | [diff] [blame] | 1437 | sg_to_sec4_sg_last(req->dst, dst_len, |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1438 | edesc->sec4_sg + sec4_sg_index, 0); |
| 1439 | } |
| 1440 | |
| 1441 | if (!sec4_sg_bytes) |
| 1442 | return edesc; |
| 1443 | |
| 1444 | edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg, |
| 1445 | sec4_sg_bytes, DMA_TO_DEVICE); |
| 1446 | if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) { |
| 1447 | dev_err(jrdev, "unable to map S/G table\n"); |
| 1448 | aead_unmap(jrdev, edesc, req); |
| 1449 | kfree(edesc); |
| 1450 | return ERR_PTR(-ENOMEM); |
| 1451 | } |
| 1452 | |
| 1453 | edesc->sec4_sg_bytes = sec4_sg_bytes; |
| 1454 | |
| 1455 | return edesc; |
| 1456 | } |
| 1457 | |
| 1458 | static int gcm_encrypt(struct aead_request *req) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1459 | { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1460 | struct aead_edesc *edesc; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1461 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1462 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 1463 | struct device *jrdev = ctx->jrdev; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1464 | bool all_contig; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1465 | u32 *desc; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1466 | int ret = 0; |
| 1467 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1468 | /* allocate extended descriptor */ |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1469 | edesc = aead_edesc_alloc(req, GCM_DESC_JOB_IO_LEN, &all_contig, true); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1470 | if (IS_ERR(edesc)) |
| 1471 | return PTR_ERR(edesc); |
| 1472 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1473 | /* Create and submit job descriptor */ |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1474 | init_gcm_job(req, edesc, all_contig, true); |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 1475 | |
| 1476 | print_hex_dump_debug("aead jobdesc@"__stringify(__LINE__)": ", |
| 1477 | DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc, |
| 1478 | desc_bytes(edesc->hw_desc), 1); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1479 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1480 | desc = edesc->hw_desc; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1481 | ret = caam_jr_enqueue(jrdev, desc, aead_encrypt_done, req); |
| 1482 | if (!ret) { |
| 1483 | ret = -EINPROGRESS; |
| 1484 | } else { |
| 1485 | aead_unmap(jrdev, edesc, req); |
| 1486 | kfree(edesc); |
| 1487 | } |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1488 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1489 | return ret; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1490 | } |
| 1491 | |
Horia Geantă | d6bbd4e | 2018-11-08 15:36:30 +0200 | [diff] [blame] | 1492 | static int chachapoly_encrypt(struct aead_request *req) |
| 1493 | { |
| 1494 | struct aead_edesc *edesc; |
| 1495 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
| 1496 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 1497 | struct device *jrdev = ctx->jrdev; |
| 1498 | bool all_contig; |
| 1499 | u32 *desc; |
| 1500 | int ret; |
| 1501 | |
| 1502 | edesc = aead_edesc_alloc(req, CHACHAPOLY_DESC_JOB_IO_LEN, &all_contig, |
| 1503 | true); |
| 1504 | if (IS_ERR(edesc)) |
| 1505 | return PTR_ERR(edesc); |
| 1506 | |
| 1507 | desc = edesc->hw_desc; |
| 1508 | |
| 1509 | init_chachapoly_job(req, edesc, all_contig, true); |
| 1510 | print_hex_dump_debug("chachapoly jobdesc@" __stringify(__LINE__)": ", |
| 1511 | DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), |
| 1512 | 1); |
| 1513 | |
| 1514 | ret = caam_jr_enqueue(jrdev, desc, aead_encrypt_done, req); |
| 1515 | if (!ret) { |
| 1516 | ret = -EINPROGRESS; |
| 1517 | } else { |
| 1518 | aead_unmap(jrdev, edesc, req); |
| 1519 | kfree(edesc); |
| 1520 | } |
| 1521 | |
| 1522 | return ret; |
| 1523 | } |
| 1524 | |
| 1525 | static int chachapoly_decrypt(struct aead_request *req) |
| 1526 | { |
| 1527 | struct aead_edesc *edesc; |
| 1528 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
| 1529 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 1530 | struct device *jrdev = ctx->jrdev; |
| 1531 | bool all_contig; |
| 1532 | u32 *desc; |
| 1533 | int ret; |
| 1534 | |
| 1535 | edesc = aead_edesc_alloc(req, CHACHAPOLY_DESC_JOB_IO_LEN, &all_contig, |
| 1536 | false); |
| 1537 | if (IS_ERR(edesc)) |
| 1538 | return PTR_ERR(edesc); |
| 1539 | |
| 1540 | desc = edesc->hw_desc; |
| 1541 | |
| 1542 | init_chachapoly_job(req, edesc, all_contig, false); |
| 1543 | print_hex_dump_debug("chachapoly jobdesc@" __stringify(__LINE__)": ", |
| 1544 | DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), |
| 1545 | 1); |
| 1546 | |
| 1547 | ret = caam_jr_enqueue(jrdev, desc, aead_decrypt_done, req); |
| 1548 | if (!ret) { |
| 1549 | ret = -EINPROGRESS; |
| 1550 | } else { |
| 1551 | aead_unmap(jrdev, edesc, req); |
| 1552 | kfree(edesc); |
| 1553 | } |
| 1554 | |
| 1555 | return ret; |
| 1556 | } |
| 1557 | |
Herbert Xu | 4621875 | 2015-07-09 07:17:33 +0800 | [diff] [blame] | 1558 | static int ipsec_gcm_encrypt(struct aead_request *req) |
| 1559 | { |
Iuliana Prodan | fcd23ed | 2019-07-31 16:08:07 +0300 | [diff] [blame] | 1560 | return crypto_ipsec_check_assoclen(req->assoclen) ? : gcm_encrypt(req); |
Herbert Xu | 4621875 | 2015-07-09 07:17:33 +0800 | [diff] [blame] | 1561 | } |
| 1562 | |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1563 | static int aead_encrypt(struct aead_request *req) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1564 | { |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1565 | struct aead_edesc *edesc; |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1566 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1567 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 1568 | struct device *jrdev = ctx->jrdev; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1569 | bool all_contig; |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1570 | u32 *desc; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1571 | int ret = 0; |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1572 | |
| 1573 | /* allocate extended descriptor */ |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1574 | edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN, |
| 1575 | &all_contig, true); |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1576 | if (IS_ERR(edesc)) |
| 1577 | return PTR_ERR(edesc); |
| 1578 | |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1579 | /* Create and submit job descriptor */ |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1580 | init_authenc_job(req, edesc, all_contig, true); |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 1581 | |
| 1582 | print_hex_dump_debug("aead jobdesc@"__stringify(__LINE__)": ", |
| 1583 | DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc, |
| 1584 | desc_bytes(edesc->hw_desc), 1); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1585 | |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1586 | desc = edesc->hw_desc; |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1587 | ret = caam_jr_enqueue(jrdev, desc, aead_encrypt_done, req); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1588 | if (!ret) { |
| 1589 | ret = -EINPROGRESS; |
| 1590 | } else { |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1591 | aead_unmap(jrdev, edesc, req); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1592 | kfree(edesc); |
| 1593 | } |
| 1594 | |
| 1595 | return ret; |
| 1596 | } |
| 1597 | |
| 1598 | static int gcm_decrypt(struct aead_request *req) |
| 1599 | { |
| 1600 | struct aead_edesc *edesc; |
| 1601 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
| 1602 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 1603 | struct device *jrdev = ctx->jrdev; |
| 1604 | bool all_contig; |
| 1605 | u32 *desc; |
| 1606 | int ret = 0; |
| 1607 | |
| 1608 | /* allocate extended descriptor */ |
| 1609 | edesc = aead_edesc_alloc(req, GCM_DESC_JOB_IO_LEN, &all_contig, false); |
| 1610 | if (IS_ERR(edesc)) |
| 1611 | return PTR_ERR(edesc); |
| 1612 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1613 | /* Create and submit job descriptor*/ |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1614 | init_gcm_job(req, edesc, all_contig, false); |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 1615 | |
| 1616 | print_hex_dump_debug("aead jobdesc@"__stringify(__LINE__)": ", |
| 1617 | DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc, |
| 1618 | desc_bytes(edesc->hw_desc), 1); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1619 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1620 | desc = edesc->hw_desc; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1621 | ret = caam_jr_enqueue(jrdev, desc, aead_decrypt_done, req); |
| 1622 | if (!ret) { |
| 1623 | ret = -EINPROGRESS; |
| 1624 | } else { |
| 1625 | aead_unmap(jrdev, edesc, req); |
| 1626 | kfree(edesc); |
| 1627 | } |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1628 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1629 | return ret; |
| 1630 | } |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1631 | |
Herbert Xu | 4621875 | 2015-07-09 07:17:33 +0800 | [diff] [blame] | 1632 | static int ipsec_gcm_decrypt(struct aead_request *req) |
| 1633 | { |
Iuliana Prodan | fcd23ed | 2019-07-31 16:08:07 +0300 | [diff] [blame] | 1634 | return crypto_ipsec_check_assoclen(req->assoclen) ? : gcm_decrypt(req); |
Herbert Xu | 4621875 | 2015-07-09 07:17:33 +0800 | [diff] [blame] | 1635 | } |
| 1636 | |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1637 | static int aead_decrypt(struct aead_request *req) |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1638 | { |
| 1639 | struct aead_edesc *edesc; |
| 1640 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
| 1641 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 1642 | struct device *jrdev = ctx->jrdev; |
| 1643 | bool all_contig; |
| 1644 | u32 *desc; |
| 1645 | int ret = 0; |
| 1646 | |
Sascha Hauer | 8a82451 | 2019-05-23 10:50:30 +0200 | [diff] [blame] | 1647 | caam_dump_sg("dec src@" __stringify(__LINE__)": ", |
Horia Geantă | 972b812 | 2017-07-10 08:40:28 +0300 | [diff] [blame] | 1648 | DUMP_PREFIX_ADDRESS, 16, 4, req->src, |
| 1649 | req->assoclen + req->cryptlen, 1); |
Catalin Vasile | 5ecf8ef | 2016-09-22 11:57:58 +0300 | [diff] [blame] | 1650 | |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1651 | /* allocate extended descriptor */ |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1652 | edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN, |
| 1653 | &all_contig, false); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1654 | if (IS_ERR(edesc)) |
| 1655 | return PTR_ERR(edesc); |
| 1656 | |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1657 | /* Create and submit job descriptor*/ |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1658 | init_authenc_job(req, edesc, all_contig, false); |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 1659 | |
| 1660 | print_hex_dump_debug("aead jobdesc@"__stringify(__LINE__)": ", |
| 1661 | DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc, |
| 1662 | desc_bytes(edesc->hw_desc), 1); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1663 | |
| 1664 | desc = edesc->hw_desc; |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1665 | ret = caam_jr_enqueue(jrdev, desc, aead_decrypt_done, req); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1666 | if (!ret) { |
| 1667 | ret = -EINPROGRESS; |
| 1668 | } else { |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 1669 | aead_unmap(jrdev, edesc, req); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 1670 | kfree(edesc); |
| 1671 | } |
| 1672 | |
| 1673 | return ret; |
| 1674 | } |
| 1675 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1676 | /* |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1677 | * allocate and map the skcipher extended descriptor for skcipher |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1678 | */ |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1679 | static struct skcipher_edesc *skcipher_edesc_alloc(struct skcipher_request *req, |
| 1680 | int desc_bytes) |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1681 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1682 | struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); |
| 1683 | struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1684 | struct device *jrdev = ctx->jrdev; |
Horia Geantă | 42cfcaf | 2017-06-19 11:44:45 +0300 | [diff] [blame] | 1685 | gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1686 | GFP_KERNEL : GFP_ATOMIC; |
Horia Geantă | 838e0a8 | 2017-02-10 14:07:20 +0200 | [diff] [blame] | 1687 | int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0; |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1688 | struct skcipher_edesc *edesc; |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 1689 | dma_addr_t iv_dma = 0; |
Horia Geantă | 115957b | 2018-03-28 15:39:18 +0300 | [diff] [blame] | 1690 | u8 *iv; |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1691 | int ivsize = crypto_skcipher_ivsize(skcipher); |
Horia Geantă | 838e0a8 | 2017-02-10 14:07:20 +0200 | [diff] [blame] | 1692 | int dst_sg_idx, sec4_sg_ents, sec4_sg_bytes; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1693 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1694 | src_nents = sg_nents_for_len(req->src, req->cryptlen); |
Horia Geantă | fd144d8 | 2017-02-10 14:07:18 +0200 | [diff] [blame] | 1695 | if (unlikely(src_nents < 0)) { |
| 1696 | dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n", |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1697 | req->cryptlen); |
Horia Geantă | fd144d8 | 2017-02-10 14:07:18 +0200 | [diff] [blame] | 1698 | return ERR_PTR(src_nents); |
| 1699 | } |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1700 | |
Horia Geantă | fd144d8 | 2017-02-10 14:07:18 +0200 | [diff] [blame] | 1701 | if (req->dst != req->src) { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1702 | dst_nents = sg_nents_for_len(req->dst, req->cryptlen); |
Horia Geantă | fd144d8 | 2017-02-10 14:07:18 +0200 | [diff] [blame] | 1703 | if (unlikely(dst_nents < 0)) { |
| 1704 | dev_err(jrdev, "Insufficient bytes (%d) in dst S/G\n", |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1705 | req->cryptlen); |
Horia Geantă | fd144d8 | 2017-02-10 14:07:18 +0200 | [diff] [blame] | 1706 | return ERR_PTR(dst_nents); |
| 1707 | } |
| 1708 | } |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1709 | |
| 1710 | if (likely(req->src == req->dst)) { |
Horia Geantă | 838e0a8 | 2017-02-10 14:07:20 +0200 | [diff] [blame] | 1711 | mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents, |
| 1712 | DMA_BIDIRECTIONAL); |
| 1713 | if (unlikely(!mapped_src_nents)) { |
Horia Geantă | c73e36e | 2016-11-09 10:46:20 +0200 | [diff] [blame] | 1714 | dev_err(jrdev, "unable to map source\n"); |
| 1715 | return ERR_PTR(-ENOMEM); |
| 1716 | } |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1717 | } else { |
Horia Geantă | 838e0a8 | 2017-02-10 14:07:20 +0200 | [diff] [blame] | 1718 | mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents, |
| 1719 | DMA_TO_DEVICE); |
| 1720 | if (unlikely(!mapped_src_nents)) { |
Horia Geantă | c73e36e | 2016-11-09 10:46:20 +0200 | [diff] [blame] | 1721 | dev_err(jrdev, "unable to map source\n"); |
| 1722 | return ERR_PTR(-ENOMEM); |
| 1723 | } |
Horia Geantă | 838e0a8 | 2017-02-10 14:07:20 +0200 | [diff] [blame] | 1724 | mapped_dst_nents = dma_map_sg(jrdev, req->dst, dst_nents, |
| 1725 | DMA_FROM_DEVICE); |
| 1726 | if (unlikely(!mapped_dst_nents)) { |
Horia Geantă | c73e36e | 2016-11-09 10:46:20 +0200 | [diff] [blame] | 1727 | dev_err(jrdev, "unable to map destination\n"); |
Horia Geantă | fa0c92d | 2017-02-10 14:07:19 +0200 | [diff] [blame] | 1728 | dma_unmap_sg(jrdev, req->src, src_nents, DMA_TO_DEVICE); |
Horia Geantă | c73e36e | 2016-11-09 10:46:20 +0200 | [diff] [blame] | 1729 | return ERR_PTR(-ENOMEM); |
| 1730 | } |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1731 | } |
| 1732 | |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 1733 | if (!ivsize && mapped_src_nents == 1) |
| 1734 | sec4_sg_ents = 0; // no need for an input hw s/g table |
| 1735 | else |
| 1736 | sec4_sg_ents = mapped_src_nents + !!ivsize; |
Horia Geantă | fa0c92d | 2017-02-10 14:07:19 +0200 | [diff] [blame] | 1737 | dst_sg_idx = sec4_sg_ents; |
Horia Geantă | a5e5c13 | 2019-05-03 17:17:38 +0300 | [diff] [blame] | 1738 | |
| 1739 | /* |
Horia Geantă | 334d37c | 2019-06-10 16:30:59 +0300 | [diff] [blame] | 1740 | * Input, output HW S/G tables: [IV, src][dst, IV] |
| 1741 | * IV entries point to the same buffer |
| 1742 | * If src == dst, S/G entries are reused (S/G tables overlap) |
| 1743 | * |
Horia Geantă | a5e5c13 | 2019-05-03 17:17:38 +0300 | [diff] [blame] | 1744 | * HW reads 4 S/G entries at a time; make sure the reads don't go beyond |
| 1745 | * the end of the table by allocating more S/G entries. Logic: |
Horia Geantă | 334d37c | 2019-06-10 16:30:59 +0300 | [diff] [blame] | 1746 | * if (output S/G) |
Horia Geantă | a5e5c13 | 2019-05-03 17:17:38 +0300 | [diff] [blame] | 1747 | * pad output S/G, if needed |
Horia Geantă | a5e5c13 | 2019-05-03 17:17:38 +0300 | [diff] [blame] | 1748 | * else if (input S/G) ... |
| 1749 | * pad input S/G, if needed |
| 1750 | */ |
Horia Geantă | 334d37c | 2019-06-10 16:30:59 +0300 | [diff] [blame] | 1751 | if (ivsize || mapped_dst_nents > 1) { |
| 1752 | if (req->src == req->dst) |
| 1753 | sec4_sg_ents = !!ivsize + pad_sg_nents(sec4_sg_ents); |
| 1754 | else |
| 1755 | sec4_sg_ents += pad_sg_nents(mapped_dst_nents + |
| 1756 | !!ivsize); |
| 1757 | } else { |
Horia Geantă | a5e5c13 | 2019-05-03 17:17:38 +0300 | [diff] [blame] | 1758 | sec4_sg_ents = pad_sg_nents(sec4_sg_ents); |
Horia Geantă | 334d37c | 2019-06-10 16:30:59 +0300 | [diff] [blame] | 1759 | } |
Horia Geantă | a5e5c13 | 2019-05-03 17:17:38 +0300 | [diff] [blame] | 1760 | |
Horia Geantă | fa0c92d | 2017-02-10 14:07:19 +0200 | [diff] [blame] | 1761 | sec4_sg_bytes = sec4_sg_ents * sizeof(struct sec4_sg_entry); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1762 | |
Horia Geantă | 115957b | 2018-03-28 15:39:18 +0300 | [diff] [blame] | 1763 | /* |
| 1764 | * allocate space for base edesc and hw desc commands, link tables, IV |
| 1765 | */ |
| 1766 | edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes + ivsize, |
Victoria Milhoan | dde20ae | 2015-08-05 11:28:39 -0700 | [diff] [blame] | 1767 | GFP_DMA | flags); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1768 | if (!edesc) { |
| 1769 | dev_err(jrdev, "could not allocate extended descriptor\n"); |
Horia Geantă | 115957b | 2018-03-28 15:39:18 +0300 | [diff] [blame] | 1770 | caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0, |
Horia Geantă | cf5448b | 2018-08-06 15:43:57 +0300 | [diff] [blame] | 1771 | 0, 0, 0); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1772 | return ERR_PTR(-ENOMEM); |
| 1773 | } |
| 1774 | |
| 1775 | edesc->src_nents = src_nents; |
| 1776 | edesc->dst_nents = dst_nents; |
Iuliana Prodan | ba4cf71 | 2019-02-08 15:50:07 +0200 | [diff] [blame] | 1777 | edesc->mapped_src_nents = mapped_src_nents; |
| 1778 | edesc->mapped_dst_nents = mapped_dst_nents; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1779 | edesc->sec4_sg_bytes = sec4_sg_bytes; |
Horia Geantă | 13cc6f4 | 2018-09-14 18:34:28 +0300 | [diff] [blame] | 1780 | edesc->sec4_sg = (struct sec4_sg_entry *)((u8 *)edesc->hw_desc + |
| 1781 | desc_bytes); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1782 | |
Horia Geantă | 115957b | 2018-03-28 15:39:18 +0300 | [diff] [blame] | 1783 | /* Make sure IV is located in a DMAable area */ |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 1784 | if (ivsize) { |
Horia Geantă | 334d37c | 2019-06-10 16:30:59 +0300 | [diff] [blame] | 1785 | iv = (u8 *)edesc->sec4_sg + sec4_sg_bytes; |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 1786 | memcpy(iv, req->iv, ivsize); |
Horia Geantă | 115957b | 2018-03-28 15:39:18 +0300 | [diff] [blame] | 1787 | |
Horia Geantă | 334d37c | 2019-06-10 16:30:59 +0300 | [diff] [blame] | 1788 | iv_dma = dma_map_single(jrdev, iv, ivsize, DMA_BIDIRECTIONAL); |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 1789 | if (dma_mapping_error(jrdev, iv_dma)) { |
| 1790 | dev_err(jrdev, "unable to map IV\n"); |
| 1791 | caam_unmap(jrdev, req->src, req->dst, src_nents, |
| 1792 | dst_nents, 0, 0, 0, 0); |
| 1793 | kfree(edesc); |
| 1794 | return ERR_PTR(-ENOMEM); |
| 1795 | } |
| 1796 | |
| 1797 | dma_to_sec4_sg_one(edesc->sec4_sg, iv_dma, ivsize, 0); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1798 | } |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 1799 | if (dst_sg_idx) |
Horia Geantă | 334d37c | 2019-06-10 16:30:59 +0300 | [diff] [blame] | 1800 | sg_to_sec4_sg(req->src, req->cryptlen, edesc->sec4_sg + |
| 1801 | !!ivsize, 0); |
Horia Geantă | 115957b | 2018-03-28 15:39:18 +0300 | [diff] [blame] | 1802 | |
Horia Geantă | 334d37c | 2019-06-10 16:30:59 +0300 | [diff] [blame] | 1803 | if (req->src != req->dst && (ivsize || mapped_dst_nents > 1)) |
| 1804 | sg_to_sec4_sg(req->dst, req->cryptlen, edesc->sec4_sg + |
| 1805 | dst_sg_idx, 0); |
| 1806 | |
| 1807 | if (ivsize) |
| 1808 | dma_to_sec4_sg_one(edesc->sec4_sg + dst_sg_idx + |
| 1809 | mapped_dst_nents, iv_dma, ivsize, 0); |
| 1810 | |
| 1811 | if (ivsize || mapped_dst_nents > 1) |
| 1812 | sg_to_sec4_set_last(edesc->sec4_sg + dst_sg_idx + |
| 1813 | mapped_dst_nents); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1814 | |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 1815 | if (sec4_sg_bytes) { |
| 1816 | edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg, |
| 1817 | sec4_sg_bytes, |
| 1818 | DMA_TO_DEVICE); |
| 1819 | if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) { |
| 1820 | dev_err(jrdev, "unable to map S/G table\n"); |
| 1821 | caam_unmap(jrdev, req->src, req->dst, src_nents, |
| 1822 | dst_nents, iv_dma, ivsize, 0, 0); |
| 1823 | kfree(edesc); |
| 1824 | return ERR_PTR(-ENOMEM); |
| 1825 | } |
Horia Geanta | ce57208 | 2014-07-11 15:34:49 +0300 | [diff] [blame] | 1826 | } |
| 1827 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1828 | edesc->iv_dma = iv_dma; |
| 1829 | |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 1830 | print_hex_dump_debug("skcipher sec4_sg@" __stringify(__LINE__)": ", |
| 1831 | DUMP_PREFIX_ADDRESS, 16, 4, edesc->sec4_sg, |
| 1832 | sec4_sg_bytes, 1); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1833 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1834 | return edesc; |
| 1835 | } |
| 1836 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1837 | static int skcipher_encrypt(struct skcipher_request *req) |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1838 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1839 | struct skcipher_edesc *edesc; |
| 1840 | struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); |
| 1841 | struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1842 | struct device *jrdev = ctx->jrdev; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1843 | u32 *desc; |
| 1844 | int ret = 0; |
| 1845 | |
Iuliana Prodan | 31bb2f0 | 2019-07-31 16:08:08 +0300 | [diff] [blame] | 1846 | if (!req->cryptlen) |
| 1847 | return 0; |
| 1848 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1849 | /* allocate extended descriptor */ |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1850 | edesc = skcipher_edesc_alloc(req, DESC_JOB_IO_LEN * CAAM_CMD_SZ); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1851 | if (IS_ERR(edesc)) |
| 1852 | return PTR_ERR(edesc); |
| 1853 | |
| 1854 | /* Create and submit job descriptor*/ |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1855 | init_skcipher_job(req, edesc, true); |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 1856 | |
| 1857 | print_hex_dump_debug("skcipher jobdesc@" __stringify(__LINE__)": ", |
| 1858 | DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc, |
| 1859 | desc_bytes(edesc->hw_desc), 1); |
| 1860 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1861 | desc = edesc->hw_desc; |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1862 | ret = caam_jr_enqueue(jrdev, desc, skcipher_encrypt_done, req); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1863 | |
| 1864 | if (!ret) { |
| 1865 | ret = -EINPROGRESS; |
| 1866 | } else { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1867 | skcipher_unmap(jrdev, edesc, req); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1868 | kfree(edesc); |
| 1869 | } |
| 1870 | |
| 1871 | return ret; |
| 1872 | } |
| 1873 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1874 | static int skcipher_decrypt(struct skcipher_request *req) |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1875 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1876 | struct skcipher_edesc *edesc; |
| 1877 | struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); |
| 1878 | struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1879 | struct device *jrdev = ctx->jrdev; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1880 | u32 *desc; |
| 1881 | int ret = 0; |
| 1882 | |
Iuliana Prodan | 31bb2f0 | 2019-07-31 16:08:08 +0300 | [diff] [blame] | 1883 | if (!req->cryptlen) |
| 1884 | return 0; |
| 1885 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1886 | /* allocate extended descriptor */ |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1887 | edesc = skcipher_edesc_alloc(req, DESC_JOB_IO_LEN * CAAM_CMD_SZ); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1888 | if (IS_ERR(edesc)) |
| 1889 | return PTR_ERR(edesc); |
| 1890 | |
| 1891 | /* Create and submit job descriptor*/ |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1892 | init_skcipher_job(req, edesc, false); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1893 | desc = edesc->hw_desc; |
Sascha Hauer | 6e00550 | 2019-05-23 10:50:29 +0200 | [diff] [blame] | 1894 | |
| 1895 | print_hex_dump_debug("skcipher jobdesc@" __stringify(__LINE__)": ", |
| 1896 | DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc, |
| 1897 | desc_bytes(edesc->hw_desc), 1); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1898 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1899 | ret = caam_jr_enqueue(jrdev, desc, skcipher_decrypt_done, req); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1900 | if (!ret) { |
| 1901 | ret = -EINPROGRESS; |
| 1902 | } else { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1903 | skcipher_unmap(jrdev, edesc, req); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1904 | kfree(edesc); |
| 1905 | } |
| 1906 | |
| 1907 | return ret; |
| 1908 | } |
| 1909 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1910 | static struct caam_skcipher_alg driver_algs[] = { |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1911 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1912 | .skcipher = { |
| 1913 | .base = { |
| 1914 | .cra_name = "cbc(aes)", |
| 1915 | .cra_driver_name = "cbc-aes-caam", |
| 1916 | .cra_blocksize = AES_BLOCK_SIZE, |
| 1917 | }, |
Iuliana Prodan | 836d8f4 | 2019-07-31 16:08:05 +0300 | [diff] [blame] | 1918 | .setkey = aes_skcipher_setkey, |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1919 | .encrypt = skcipher_encrypt, |
| 1920 | .decrypt = skcipher_decrypt, |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1921 | .min_keysize = AES_MIN_KEY_SIZE, |
| 1922 | .max_keysize = AES_MAX_KEY_SIZE, |
| 1923 | .ivsize = AES_BLOCK_SIZE, |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1924 | }, |
| 1925 | .caam.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1926 | }, |
| 1927 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1928 | .skcipher = { |
| 1929 | .base = { |
| 1930 | .cra_name = "cbc(des3_ede)", |
| 1931 | .cra_driver_name = "cbc-3des-caam", |
| 1932 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 1933 | }, |
Ard Biesheuvel | a628c5a | 2019-08-15 12:00:48 +0300 | [diff] [blame] | 1934 | .setkey = des3_skcipher_setkey, |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1935 | .encrypt = skcipher_encrypt, |
| 1936 | .decrypt = skcipher_decrypt, |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1937 | .min_keysize = DES3_EDE_KEY_SIZE, |
| 1938 | .max_keysize = DES3_EDE_KEY_SIZE, |
| 1939 | .ivsize = DES3_EDE_BLOCK_SIZE, |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1940 | }, |
| 1941 | .caam.class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1942 | }, |
| 1943 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1944 | .skcipher = { |
| 1945 | .base = { |
| 1946 | .cra_name = "cbc(des)", |
| 1947 | .cra_driver_name = "cbc-des-caam", |
| 1948 | .cra_blocksize = DES_BLOCK_SIZE, |
| 1949 | }, |
Iuliana Prodan | cf64e49 | 2019-02-08 15:50:10 +0200 | [diff] [blame] | 1950 | .setkey = des_skcipher_setkey, |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1951 | .encrypt = skcipher_encrypt, |
| 1952 | .decrypt = skcipher_decrypt, |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1953 | .min_keysize = DES_KEY_SIZE, |
| 1954 | .max_keysize = DES_KEY_SIZE, |
| 1955 | .ivsize = DES_BLOCK_SIZE, |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1956 | }, |
| 1957 | .caam.class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
Catalin Vasile | 2b22f6c | 2014-10-31 12:45:35 +0200 | [diff] [blame] | 1958 | }, |
| 1959 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1960 | .skcipher = { |
| 1961 | .base = { |
| 1962 | .cra_name = "ctr(aes)", |
| 1963 | .cra_driver_name = "ctr-aes-caam", |
| 1964 | .cra_blocksize = 1, |
| 1965 | }, |
Iuliana Prodan | 836d8f4 | 2019-07-31 16:08:05 +0300 | [diff] [blame] | 1966 | .setkey = ctr_skcipher_setkey, |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1967 | .encrypt = skcipher_encrypt, |
| 1968 | .decrypt = skcipher_decrypt, |
Catalin Vasile | 2b22f6c | 2014-10-31 12:45:35 +0200 | [diff] [blame] | 1969 | .min_keysize = AES_MIN_KEY_SIZE, |
| 1970 | .max_keysize = AES_MAX_KEY_SIZE, |
| 1971 | .ivsize = AES_BLOCK_SIZE, |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1972 | .chunksize = AES_BLOCK_SIZE, |
| 1973 | }, |
| 1974 | .caam.class1_alg_type = OP_ALG_ALGSEL_AES | |
| 1975 | OP_ALG_AAI_CTR_MOD128, |
Catalin Vasile | a5f57cf | 2014-10-31 12:45:36 +0200 | [diff] [blame] | 1976 | }, |
| 1977 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1978 | .skcipher = { |
| 1979 | .base = { |
| 1980 | .cra_name = "rfc3686(ctr(aes))", |
| 1981 | .cra_driver_name = "rfc3686-ctr-aes-caam", |
| 1982 | .cra_blocksize = 1, |
| 1983 | }, |
Iuliana Prodan | 836d8f4 | 2019-07-31 16:08:05 +0300 | [diff] [blame] | 1984 | .setkey = rfc3686_skcipher_setkey, |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1985 | .encrypt = skcipher_encrypt, |
| 1986 | .decrypt = skcipher_decrypt, |
Catalin Vasile | a5f57cf | 2014-10-31 12:45:36 +0200 | [diff] [blame] | 1987 | .min_keysize = AES_MIN_KEY_SIZE + |
| 1988 | CTR_RFC3686_NONCE_SIZE, |
| 1989 | .max_keysize = AES_MAX_KEY_SIZE + |
| 1990 | CTR_RFC3686_NONCE_SIZE, |
| 1991 | .ivsize = CTR_RFC3686_IV_SIZE, |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 1992 | .chunksize = AES_BLOCK_SIZE, |
| 1993 | }, |
| 1994 | .caam = { |
| 1995 | .class1_alg_type = OP_ALG_ALGSEL_AES | |
| 1996 | OP_ALG_AAI_CTR_MOD128, |
| 1997 | .rfc3686 = true, |
| 1998 | }, |
Catalin Vasile | c6415a6 | 2015-10-02 13:13:18 +0300 | [diff] [blame] | 1999 | }, |
| 2000 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 2001 | .skcipher = { |
| 2002 | .base = { |
| 2003 | .cra_name = "xts(aes)", |
| 2004 | .cra_driver_name = "xts-aes-caam", |
| 2005 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2006 | }, |
| 2007 | .setkey = xts_skcipher_setkey, |
| 2008 | .encrypt = skcipher_encrypt, |
| 2009 | .decrypt = skcipher_decrypt, |
Catalin Vasile | c6415a6 | 2015-10-02 13:13:18 +0300 | [diff] [blame] | 2010 | .min_keysize = 2 * AES_MIN_KEY_SIZE, |
| 2011 | .max_keysize = 2 * AES_MAX_KEY_SIZE, |
| 2012 | .ivsize = AES_BLOCK_SIZE, |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 2013 | }, |
| 2014 | .caam.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_XTS, |
Catalin Vasile | c6415a6 | 2015-10-02 13:13:18 +0300 | [diff] [blame] | 2015 | }, |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 2016 | { |
| 2017 | .skcipher = { |
| 2018 | .base = { |
| 2019 | .cra_name = "ecb(des)", |
| 2020 | .cra_driver_name = "ecb-des-caam", |
| 2021 | .cra_blocksize = DES_BLOCK_SIZE, |
| 2022 | }, |
| 2023 | .setkey = des_skcipher_setkey, |
| 2024 | .encrypt = skcipher_encrypt, |
| 2025 | .decrypt = skcipher_decrypt, |
| 2026 | .min_keysize = DES_KEY_SIZE, |
| 2027 | .max_keysize = DES_KEY_SIZE, |
| 2028 | }, |
| 2029 | .caam.class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_ECB, |
| 2030 | }, |
| 2031 | { |
| 2032 | .skcipher = { |
| 2033 | .base = { |
| 2034 | .cra_name = "ecb(aes)", |
| 2035 | .cra_driver_name = "ecb-aes-caam", |
| 2036 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2037 | }, |
Iuliana Prodan | 836d8f4 | 2019-07-31 16:08:05 +0300 | [diff] [blame] | 2038 | .setkey = aes_skcipher_setkey, |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 2039 | .encrypt = skcipher_encrypt, |
| 2040 | .decrypt = skcipher_decrypt, |
| 2041 | .min_keysize = AES_MIN_KEY_SIZE, |
| 2042 | .max_keysize = AES_MAX_KEY_SIZE, |
| 2043 | }, |
| 2044 | .caam.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_ECB, |
| 2045 | }, |
| 2046 | { |
| 2047 | .skcipher = { |
| 2048 | .base = { |
| 2049 | .cra_name = "ecb(des3_ede)", |
| 2050 | .cra_driver_name = "ecb-des3-caam", |
| 2051 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2052 | }, |
Ard Biesheuvel | a628c5a | 2019-08-15 12:00:48 +0300 | [diff] [blame] | 2053 | .setkey = des3_skcipher_setkey, |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 2054 | .encrypt = skcipher_encrypt, |
| 2055 | .decrypt = skcipher_decrypt, |
| 2056 | .min_keysize = DES3_EDE_KEY_SIZE, |
| 2057 | .max_keysize = DES3_EDE_KEY_SIZE, |
| 2058 | }, |
| 2059 | .caam.class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_ECB, |
| 2060 | }, |
| 2061 | { |
| 2062 | .skcipher = { |
| 2063 | .base = { |
| 2064 | .cra_name = "ecb(arc4)", |
| 2065 | .cra_driver_name = "ecb-arc4-caam", |
| 2066 | .cra_blocksize = ARC4_BLOCK_SIZE, |
| 2067 | }, |
Iuliana Prodan | 836d8f4 | 2019-07-31 16:08:05 +0300 | [diff] [blame] | 2068 | .setkey = arc4_skcipher_setkey, |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 2069 | .encrypt = skcipher_encrypt, |
| 2070 | .decrypt = skcipher_decrypt, |
| 2071 | .min_keysize = ARC4_MIN_KEY_SIZE, |
| 2072 | .max_keysize = ARC4_MAX_KEY_SIZE, |
| 2073 | }, |
| 2074 | .caam.class1_alg_type = OP_ALG_ALGSEL_ARC4 | OP_ALG_AAI_ECB, |
| 2075 | }, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2076 | }; |
| 2077 | |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 2078 | static struct caam_aead_alg driver_aeads[] = { |
| 2079 | { |
| 2080 | .aead = { |
| 2081 | .base = { |
| 2082 | .cra_name = "rfc4106(gcm(aes))", |
| 2083 | .cra_driver_name = "rfc4106-gcm-aes-caam", |
| 2084 | .cra_blocksize = 1, |
| 2085 | }, |
| 2086 | .setkey = rfc4106_setkey, |
| 2087 | .setauthsize = rfc4106_setauthsize, |
Herbert Xu | 4621875 | 2015-07-09 07:17:33 +0800 | [diff] [blame] | 2088 | .encrypt = ipsec_gcm_encrypt, |
| 2089 | .decrypt = ipsec_gcm_decrypt, |
Corentin LABBE | 7545e16 | 2017-08-22 10:08:09 +0200 | [diff] [blame] | 2090 | .ivsize = GCM_RFC4106_IV_SIZE, |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 2091 | .maxauthsize = AES_BLOCK_SIZE, |
| 2092 | }, |
| 2093 | .caam = { |
| 2094 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM, |
Herbert Xu | 24586b5 | 2019-05-06 14:39:44 +0800 | [diff] [blame] | 2095 | .nodkp = true, |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 2096 | }, |
| 2097 | }, |
| 2098 | { |
| 2099 | .aead = { |
| 2100 | .base = { |
| 2101 | .cra_name = "rfc4543(gcm(aes))", |
| 2102 | .cra_driver_name = "rfc4543-gcm-aes-caam", |
| 2103 | .cra_blocksize = 1, |
| 2104 | }, |
| 2105 | .setkey = rfc4543_setkey, |
| 2106 | .setauthsize = rfc4543_setauthsize, |
Herbert Xu | 4621875 | 2015-07-09 07:17:33 +0800 | [diff] [blame] | 2107 | .encrypt = ipsec_gcm_encrypt, |
| 2108 | .decrypt = ipsec_gcm_decrypt, |
Corentin LABBE | 7545e16 | 2017-08-22 10:08:09 +0200 | [diff] [blame] | 2109 | .ivsize = GCM_RFC4543_IV_SIZE, |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 2110 | .maxauthsize = AES_BLOCK_SIZE, |
| 2111 | }, |
| 2112 | .caam = { |
| 2113 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM, |
Herbert Xu | 24586b5 | 2019-05-06 14:39:44 +0800 | [diff] [blame] | 2114 | .nodkp = true, |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 2115 | }, |
| 2116 | }, |
| 2117 | /* Galois Counter Mode */ |
| 2118 | { |
| 2119 | .aead = { |
| 2120 | .base = { |
| 2121 | .cra_name = "gcm(aes)", |
| 2122 | .cra_driver_name = "gcm-aes-caam", |
| 2123 | .cra_blocksize = 1, |
| 2124 | }, |
| 2125 | .setkey = gcm_setkey, |
| 2126 | .setauthsize = gcm_setauthsize, |
| 2127 | .encrypt = gcm_encrypt, |
| 2128 | .decrypt = gcm_decrypt, |
Corentin LABBE | 7545e16 | 2017-08-22 10:08:09 +0200 | [diff] [blame] | 2129 | .ivsize = GCM_AES_IV_SIZE, |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 2130 | .maxauthsize = AES_BLOCK_SIZE, |
| 2131 | }, |
| 2132 | .caam = { |
| 2133 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM, |
Herbert Xu | 24586b5 | 2019-05-06 14:39:44 +0800 | [diff] [blame] | 2134 | .nodkp = true, |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 2135 | }, |
| 2136 | }, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2137 | /* single-pass ipsec_esp descriptor */ |
| 2138 | { |
| 2139 | .aead = { |
| 2140 | .base = { |
| 2141 | .cra_name = "authenc(hmac(md5)," |
| 2142 | "ecb(cipher_null))", |
| 2143 | .cra_driver_name = "authenc-hmac-md5-" |
| 2144 | "ecb-cipher_null-caam", |
| 2145 | .cra_blocksize = NULL_BLOCK_SIZE, |
| 2146 | }, |
| 2147 | .setkey = aead_setkey, |
| 2148 | .setauthsize = aead_setauthsize, |
| 2149 | .encrypt = aead_encrypt, |
| 2150 | .decrypt = aead_decrypt, |
| 2151 | .ivsize = NULL_IV_SIZE, |
| 2152 | .maxauthsize = MD5_DIGEST_SIZE, |
| 2153 | }, |
| 2154 | .caam = { |
| 2155 | .class2_alg_type = OP_ALG_ALGSEL_MD5 | |
| 2156 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2157 | }, |
| 2158 | }, |
| 2159 | { |
| 2160 | .aead = { |
| 2161 | .base = { |
| 2162 | .cra_name = "authenc(hmac(sha1)," |
| 2163 | "ecb(cipher_null))", |
| 2164 | .cra_driver_name = "authenc-hmac-sha1-" |
| 2165 | "ecb-cipher_null-caam", |
| 2166 | .cra_blocksize = NULL_BLOCK_SIZE, |
| 2167 | }, |
| 2168 | .setkey = aead_setkey, |
| 2169 | .setauthsize = aead_setauthsize, |
| 2170 | .encrypt = aead_encrypt, |
| 2171 | .decrypt = aead_decrypt, |
| 2172 | .ivsize = NULL_IV_SIZE, |
| 2173 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 2174 | }, |
| 2175 | .caam = { |
| 2176 | .class2_alg_type = OP_ALG_ALGSEL_SHA1 | |
| 2177 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2178 | }, |
| 2179 | }, |
| 2180 | { |
| 2181 | .aead = { |
| 2182 | .base = { |
| 2183 | .cra_name = "authenc(hmac(sha224)," |
| 2184 | "ecb(cipher_null))", |
| 2185 | .cra_driver_name = "authenc-hmac-sha224-" |
| 2186 | "ecb-cipher_null-caam", |
| 2187 | .cra_blocksize = NULL_BLOCK_SIZE, |
| 2188 | }, |
| 2189 | .setkey = aead_setkey, |
| 2190 | .setauthsize = aead_setauthsize, |
| 2191 | .encrypt = aead_encrypt, |
| 2192 | .decrypt = aead_decrypt, |
| 2193 | .ivsize = NULL_IV_SIZE, |
| 2194 | .maxauthsize = SHA224_DIGEST_SIZE, |
| 2195 | }, |
| 2196 | .caam = { |
| 2197 | .class2_alg_type = OP_ALG_ALGSEL_SHA224 | |
| 2198 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2199 | }, |
| 2200 | }, |
| 2201 | { |
| 2202 | .aead = { |
| 2203 | .base = { |
| 2204 | .cra_name = "authenc(hmac(sha256)," |
| 2205 | "ecb(cipher_null))", |
| 2206 | .cra_driver_name = "authenc-hmac-sha256-" |
| 2207 | "ecb-cipher_null-caam", |
| 2208 | .cra_blocksize = NULL_BLOCK_SIZE, |
| 2209 | }, |
| 2210 | .setkey = aead_setkey, |
| 2211 | .setauthsize = aead_setauthsize, |
| 2212 | .encrypt = aead_encrypt, |
| 2213 | .decrypt = aead_decrypt, |
| 2214 | .ivsize = NULL_IV_SIZE, |
| 2215 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 2216 | }, |
| 2217 | .caam = { |
| 2218 | .class2_alg_type = OP_ALG_ALGSEL_SHA256 | |
| 2219 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2220 | }, |
| 2221 | }, |
| 2222 | { |
| 2223 | .aead = { |
| 2224 | .base = { |
| 2225 | .cra_name = "authenc(hmac(sha384)," |
| 2226 | "ecb(cipher_null))", |
| 2227 | .cra_driver_name = "authenc-hmac-sha384-" |
| 2228 | "ecb-cipher_null-caam", |
| 2229 | .cra_blocksize = NULL_BLOCK_SIZE, |
| 2230 | }, |
| 2231 | .setkey = aead_setkey, |
| 2232 | .setauthsize = aead_setauthsize, |
| 2233 | .encrypt = aead_encrypt, |
| 2234 | .decrypt = aead_decrypt, |
| 2235 | .ivsize = NULL_IV_SIZE, |
| 2236 | .maxauthsize = SHA384_DIGEST_SIZE, |
| 2237 | }, |
| 2238 | .caam = { |
| 2239 | .class2_alg_type = OP_ALG_ALGSEL_SHA384 | |
| 2240 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2241 | }, |
| 2242 | }, |
| 2243 | { |
| 2244 | .aead = { |
| 2245 | .base = { |
| 2246 | .cra_name = "authenc(hmac(sha512)," |
| 2247 | "ecb(cipher_null))", |
| 2248 | .cra_driver_name = "authenc-hmac-sha512-" |
| 2249 | "ecb-cipher_null-caam", |
| 2250 | .cra_blocksize = NULL_BLOCK_SIZE, |
| 2251 | }, |
| 2252 | .setkey = aead_setkey, |
| 2253 | .setauthsize = aead_setauthsize, |
| 2254 | .encrypt = aead_encrypt, |
| 2255 | .decrypt = aead_decrypt, |
| 2256 | .ivsize = NULL_IV_SIZE, |
| 2257 | .maxauthsize = SHA512_DIGEST_SIZE, |
| 2258 | }, |
| 2259 | .caam = { |
| 2260 | .class2_alg_type = OP_ALG_ALGSEL_SHA512 | |
| 2261 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2262 | }, |
| 2263 | }, |
| 2264 | { |
| 2265 | .aead = { |
| 2266 | .base = { |
| 2267 | .cra_name = "authenc(hmac(md5),cbc(aes))", |
| 2268 | .cra_driver_name = "authenc-hmac-md5-" |
| 2269 | "cbc-aes-caam", |
| 2270 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2271 | }, |
| 2272 | .setkey = aead_setkey, |
| 2273 | .setauthsize = aead_setauthsize, |
| 2274 | .encrypt = aead_encrypt, |
| 2275 | .decrypt = aead_decrypt, |
| 2276 | .ivsize = AES_BLOCK_SIZE, |
| 2277 | .maxauthsize = MD5_DIGEST_SIZE, |
| 2278 | }, |
| 2279 | .caam = { |
| 2280 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2281 | .class2_alg_type = OP_ALG_ALGSEL_MD5 | |
| 2282 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2283 | }, |
| 2284 | }, |
| 2285 | { |
| 2286 | .aead = { |
| 2287 | .base = { |
| 2288 | .cra_name = "echainiv(authenc(hmac(md5)," |
| 2289 | "cbc(aes)))", |
| 2290 | .cra_driver_name = "echainiv-authenc-hmac-md5-" |
| 2291 | "cbc-aes-caam", |
| 2292 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2293 | }, |
| 2294 | .setkey = aead_setkey, |
| 2295 | .setauthsize = aead_setauthsize, |
| 2296 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 2297 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2298 | .ivsize = AES_BLOCK_SIZE, |
| 2299 | .maxauthsize = MD5_DIGEST_SIZE, |
| 2300 | }, |
| 2301 | .caam = { |
| 2302 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2303 | .class2_alg_type = OP_ALG_ALGSEL_MD5 | |
| 2304 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2305 | .geniv = true, |
| 2306 | }, |
| 2307 | }, |
| 2308 | { |
| 2309 | .aead = { |
| 2310 | .base = { |
| 2311 | .cra_name = "authenc(hmac(sha1),cbc(aes))", |
| 2312 | .cra_driver_name = "authenc-hmac-sha1-" |
| 2313 | "cbc-aes-caam", |
| 2314 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2315 | }, |
| 2316 | .setkey = aead_setkey, |
| 2317 | .setauthsize = aead_setauthsize, |
| 2318 | .encrypt = aead_encrypt, |
| 2319 | .decrypt = aead_decrypt, |
| 2320 | .ivsize = AES_BLOCK_SIZE, |
| 2321 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 2322 | }, |
| 2323 | .caam = { |
| 2324 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2325 | .class2_alg_type = OP_ALG_ALGSEL_SHA1 | |
| 2326 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2327 | }, |
| 2328 | }, |
| 2329 | { |
| 2330 | .aead = { |
| 2331 | .base = { |
| 2332 | .cra_name = "echainiv(authenc(hmac(sha1)," |
| 2333 | "cbc(aes)))", |
| 2334 | .cra_driver_name = "echainiv-authenc-" |
| 2335 | "hmac-sha1-cbc-aes-caam", |
| 2336 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2337 | }, |
| 2338 | .setkey = aead_setkey, |
| 2339 | .setauthsize = aead_setauthsize, |
| 2340 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 2341 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2342 | .ivsize = AES_BLOCK_SIZE, |
| 2343 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 2344 | }, |
| 2345 | .caam = { |
| 2346 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2347 | .class2_alg_type = OP_ALG_ALGSEL_SHA1 | |
| 2348 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2349 | .geniv = true, |
| 2350 | }, |
| 2351 | }, |
| 2352 | { |
| 2353 | .aead = { |
| 2354 | .base = { |
| 2355 | .cra_name = "authenc(hmac(sha224),cbc(aes))", |
| 2356 | .cra_driver_name = "authenc-hmac-sha224-" |
| 2357 | "cbc-aes-caam", |
| 2358 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2359 | }, |
| 2360 | .setkey = aead_setkey, |
| 2361 | .setauthsize = aead_setauthsize, |
| 2362 | .encrypt = aead_encrypt, |
| 2363 | .decrypt = aead_decrypt, |
| 2364 | .ivsize = AES_BLOCK_SIZE, |
| 2365 | .maxauthsize = SHA224_DIGEST_SIZE, |
| 2366 | }, |
| 2367 | .caam = { |
| 2368 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2369 | .class2_alg_type = OP_ALG_ALGSEL_SHA224 | |
| 2370 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2371 | }, |
| 2372 | }, |
| 2373 | { |
| 2374 | .aead = { |
| 2375 | .base = { |
| 2376 | .cra_name = "echainiv(authenc(hmac(sha224)," |
| 2377 | "cbc(aes)))", |
| 2378 | .cra_driver_name = "echainiv-authenc-" |
| 2379 | "hmac-sha224-cbc-aes-caam", |
| 2380 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2381 | }, |
| 2382 | .setkey = aead_setkey, |
| 2383 | .setauthsize = aead_setauthsize, |
| 2384 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 2385 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2386 | .ivsize = AES_BLOCK_SIZE, |
| 2387 | .maxauthsize = SHA224_DIGEST_SIZE, |
| 2388 | }, |
| 2389 | .caam = { |
| 2390 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2391 | .class2_alg_type = OP_ALG_ALGSEL_SHA224 | |
| 2392 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2393 | .geniv = true, |
| 2394 | }, |
| 2395 | }, |
| 2396 | { |
| 2397 | .aead = { |
| 2398 | .base = { |
| 2399 | .cra_name = "authenc(hmac(sha256),cbc(aes))", |
| 2400 | .cra_driver_name = "authenc-hmac-sha256-" |
| 2401 | "cbc-aes-caam", |
| 2402 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2403 | }, |
| 2404 | .setkey = aead_setkey, |
| 2405 | .setauthsize = aead_setauthsize, |
| 2406 | .encrypt = aead_encrypt, |
| 2407 | .decrypt = aead_decrypt, |
| 2408 | .ivsize = AES_BLOCK_SIZE, |
| 2409 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 2410 | }, |
| 2411 | .caam = { |
| 2412 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2413 | .class2_alg_type = OP_ALG_ALGSEL_SHA256 | |
| 2414 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2415 | }, |
| 2416 | }, |
| 2417 | { |
| 2418 | .aead = { |
| 2419 | .base = { |
| 2420 | .cra_name = "echainiv(authenc(hmac(sha256)," |
| 2421 | "cbc(aes)))", |
| 2422 | .cra_driver_name = "echainiv-authenc-" |
| 2423 | "hmac-sha256-cbc-aes-caam", |
| 2424 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2425 | }, |
| 2426 | .setkey = aead_setkey, |
| 2427 | .setauthsize = aead_setauthsize, |
| 2428 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 2429 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2430 | .ivsize = AES_BLOCK_SIZE, |
| 2431 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 2432 | }, |
| 2433 | .caam = { |
| 2434 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2435 | .class2_alg_type = OP_ALG_ALGSEL_SHA256 | |
| 2436 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2437 | .geniv = true, |
| 2438 | }, |
| 2439 | }, |
| 2440 | { |
| 2441 | .aead = { |
| 2442 | .base = { |
| 2443 | .cra_name = "authenc(hmac(sha384),cbc(aes))", |
| 2444 | .cra_driver_name = "authenc-hmac-sha384-" |
| 2445 | "cbc-aes-caam", |
| 2446 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2447 | }, |
| 2448 | .setkey = aead_setkey, |
| 2449 | .setauthsize = aead_setauthsize, |
| 2450 | .encrypt = aead_encrypt, |
| 2451 | .decrypt = aead_decrypt, |
| 2452 | .ivsize = AES_BLOCK_SIZE, |
| 2453 | .maxauthsize = SHA384_DIGEST_SIZE, |
| 2454 | }, |
| 2455 | .caam = { |
| 2456 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2457 | .class2_alg_type = OP_ALG_ALGSEL_SHA384 | |
| 2458 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2459 | }, |
| 2460 | }, |
| 2461 | { |
| 2462 | .aead = { |
| 2463 | .base = { |
| 2464 | .cra_name = "echainiv(authenc(hmac(sha384)," |
| 2465 | "cbc(aes)))", |
| 2466 | .cra_driver_name = "echainiv-authenc-" |
| 2467 | "hmac-sha384-cbc-aes-caam", |
| 2468 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2469 | }, |
| 2470 | .setkey = aead_setkey, |
| 2471 | .setauthsize = aead_setauthsize, |
| 2472 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 2473 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2474 | .ivsize = AES_BLOCK_SIZE, |
| 2475 | .maxauthsize = SHA384_DIGEST_SIZE, |
| 2476 | }, |
| 2477 | .caam = { |
| 2478 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2479 | .class2_alg_type = OP_ALG_ALGSEL_SHA384 | |
| 2480 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2481 | .geniv = true, |
| 2482 | }, |
| 2483 | }, |
| 2484 | { |
| 2485 | .aead = { |
| 2486 | .base = { |
| 2487 | .cra_name = "authenc(hmac(sha512),cbc(aes))", |
| 2488 | .cra_driver_name = "authenc-hmac-sha512-" |
| 2489 | "cbc-aes-caam", |
| 2490 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2491 | }, |
| 2492 | .setkey = aead_setkey, |
| 2493 | .setauthsize = aead_setauthsize, |
| 2494 | .encrypt = aead_encrypt, |
| 2495 | .decrypt = aead_decrypt, |
| 2496 | .ivsize = AES_BLOCK_SIZE, |
| 2497 | .maxauthsize = SHA512_DIGEST_SIZE, |
| 2498 | }, |
| 2499 | .caam = { |
| 2500 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2501 | .class2_alg_type = OP_ALG_ALGSEL_SHA512 | |
| 2502 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2503 | }, |
| 2504 | }, |
| 2505 | { |
| 2506 | .aead = { |
| 2507 | .base = { |
| 2508 | .cra_name = "echainiv(authenc(hmac(sha512)," |
| 2509 | "cbc(aes)))", |
| 2510 | .cra_driver_name = "echainiv-authenc-" |
| 2511 | "hmac-sha512-cbc-aes-caam", |
| 2512 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2513 | }, |
| 2514 | .setkey = aead_setkey, |
| 2515 | .setauthsize = aead_setauthsize, |
| 2516 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 2517 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2518 | .ivsize = AES_BLOCK_SIZE, |
| 2519 | .maxauthsize = SHA512_DIGEST_SIZE, |
| 2520 | }, |
| 2521 | .caam = { |
| 2522 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2523 | .class2_alg_type = OP_ALG_ALGSEL_SHA512 | |
| 2524 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2525 | .geniv = true, |
| 2526 | }, |
| 2527 | }, |
| 2528 | { |
| 2529 | .aead = { |
| 2530 | .base = { |
| 2531 | .cra_name = "authenc(hmac(md5),cbc(des3_ede))", |
| 2532 | .cra_driver_name = "authenc-hmac-md5-" |
| 2533 | "cbc-des3_ede-caam", |
| 2534 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2535 | }, |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 2536 | .setkey = des3_aead_setkey, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2537 | .setauthsize = aead_setauthsize, |
| 2538 | .encrypt = aead_encrypt, |
| 2539 | .decrypt = aead_decrypt, |
| 2540 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2541 | .maxauthsize = MD5_DIGEST_SIZE, |
| 2542 | }, |
| 2543 | .caam = { |
| 2544 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2545 | .class2_alg_type = OP_ALG_ALGSEL_MD5 | |
| 2546 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2547 | } |
| 2548 | }, |
| 2549 | { |
| 2550 | .aead = { |
| 2551 | .base = { |
| 2552 | .cra_name = "echainiv(authenc(hmac(md5)," |
| 2553 | "cbc(des3_ede)))", |
| 2554 | .cra_driver_name = "echainiv-authenc-hmac-md5-" |
| 2555 | "cbc-des3_ede-caam", |
| 2556 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2557 | }, |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 2558 | .setkey = des3_aead_setkey, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2559 | .setauthsize = aead_setauthsize, |
| 2560 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 2561 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2562 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2563 | .maxauthsize = MD5_DIGEST_SIZE, |
| 2564 | }, |
| 2565 | .caam = { |
| 2566 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2567 | .class2_alg_type = OP_ALG_ALGSEL_MD5 | |
| 2568 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2569 | .geniv = true, |
| 2570 | } |
| 2571 | }, |
| 2572 | { |
| 2573 | .aead = { |
| 2574 | .base = { |
| 2575 | .cra_name = "authenc(hmac(sha1)," |
| 2576 | "cbc(des3_ede))", |
| 2577 | .cra_driver_name = "authenc-hmac-sha1-" |
| 2578 | "cbc-des3_ede-caam", |
| 2579 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2580 | }, |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 2581 | .setkey = des3_aead_setkey, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2582 | .setauthsize = aead_setauthsize, |
| 2583 | .encrypt = aead_encrypt, |
| 2584 | .decrypt = aead_decrypt, |
| 2585 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2586 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 2587 | }, |
| 2588 | .caam = { |
| 2589 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2590 | .class2_alg_type = OP_ALG_ALGSEL_SHA1 | |
| 2591 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2592 | }, |
| 2593 | }, |
| 2594 | { |
| 2595 | .aead = { |
| 2596 | .base = { |
| 2597 | .cra_name = "echainiv(authenc(hmac(sha1)," |
| 2598 | "cbc(des3_ede)))", |
| 2599 | .cra_driver_name = "echainiv-authenc-" |
| 2600 | "hmac-sha1-" |
| 2601 | "cbc-des3_ede-caam", |
| 2602 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2603 | }, |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 2604 | .setkey = des3_aead_setkey, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2605 | .setauthsize = aead_setauthsize, |
| 2606 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 2607 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2608 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2609 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 2610 | }, |
| 2611 | .caam = { |
| 2612 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2613 | .class2_alg_type = OP_ALG_ALGSEL_SHA1 | |
| 2614 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2615 | .geniv = true, |
| 2616 | }, |
| 2617 | }, |
| 2618 | { |
| 2619 | .aead = { |
| 2620 | .base = { |
| 2621 | .cra_name = "authenc(hmac(sha224)," |
| 2622 | "cbc(des3_ede))", |
| 2623 | .cra_driver_name = "authenc-hmac-sha224-" |
| 2624 | "cbc-des3_ede-caam", |
| 2625 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2626 | }, |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 2627 | .setkey = des3_aead_setkey, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2628 | .setauthsize = aead_setauthsize, |
| 2629 | .encrypt = aead_encrypt, |
| 2630 | .decrypt = aead_decrypt, |
| 2631 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2632 | .maxauthsize = SHA224_DIGEST_SIZE, |
| 2633 | }, |
| 2634 | .caam = { |
| 2635 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2636 | .class2_alg_type = OP_ALG_ALGSEL_SHA224 | |
| 2637 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2638 | }, |
| 2639 | }, |
| 2640 | { |
| 2641 | .aead = { |
| 2642 | .base = { |
| 2643 | .cra_name = "echainiv(authenc(hmac(sha224)," |
| 2644 | "cbc(des3_ede)))", |
| 2645 | .cra_driver_name = "echainiv-authenc-" |
| 2646 | "hmac-sha224-" |
| 2647 | "cbc-des3_ede-caam", |
| 2648 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2649 | }, |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 2650 | .setkey = des3_aead_setkey, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2651 | .setauthsize = aead_setauthsize, |
| 2652 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 2653 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2654 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2655 | .maxauthsize = SHA224_DIGEST_SIZE, |
| 2656 | }, |
| 2657 | .caam = { |
| 2658 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2659 | .class2_alg_type = OP_ALG_ALGSEL_SHA224 | |
| 2660 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2661 | .geniv = true, |
| 2662 | }, |
| 2663 | }, |
| 2664 | { |
| 2665 | .aead = { |
| 2666 | .base = { |
| 2667 | .cra_name = "authenc(hmac(sha256)," |
| 2668 | "cbc(des3_ede))", |
| 2669 | .cra_driver_name = "authenc-hmac-sha256-" |
| 2670 | "cbc-des3_ede-caam", |
| 2671 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2672 | }, |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 2673 | .setkey = des3_aead_setkey, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2674 | .setauthsize = aead_setauthsize, |
| 2675 | .encrypt = aead_encrypt, |
| 2676 | .decrypt = aead_decrypt, |
| 2677 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2678 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 2679 | }, |
| 2680 | .caam = { |
| 2681 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2682 | .class2_alg_type = OP_ALG_ALGSEL_SHA256 | |
| 2683 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2684 | }, |
| 2685 | }, |
| 2686 | { |
| 2687 | .aead = { |
| 2688 | .base = { |
| 2689 | .cra_name = "echainiv(authenc(hmac(sha256)," |
| 2690 | "cbc(des3_ede)))", |
| 2691 | .cra_driver_name = "echainiv-authenc-" |
| 2692 | "hmac-sha256-" |
| 2693 | "cbc-des3_ede-caam", |
| 2694 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2695 | }, |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 2696 | .setkey = des3_aead_setkey, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2697 | .setauthsize = aead_setauthsize, |
| 2698 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 2699 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2700 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2701 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 2702 | }, |
| 2703 | .caam = { |
| 2704 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2705 | .class2_alg_type = OP_ALG_ALGSEL_SHA256 | |
| 2706 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2707 | .geniv = true, |
| 2708 | }, |
| 2709 | }, |
| 2710 | { |
| 2711 | .aead = { |
| 2712 | .base = { |
| 2713 | .cra_name = "authenc(hmac(sha384)," |
| 2714 | "cbc(des3_ede))", |
| 2715 | .cra_driver_name = "authenc-hmac-sha384-" |
| 2716 | "cbc-des3_ede-caam", |
| 2717 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2718 | }, |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 2719 | .setkey = des3_aead_setkey, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2720 | .setauthsize = aead_setauthsize, |
| 2721 | .encrypt = aead_encrypt, |
| 2722 | .decrypt = aead_decrypt, |
| 2723 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2724 | .maxauthsize = SHA384_DIGEST_SIZE, |
| 2725 | }, |
| 2726 | .caam = { |
| 2727 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2728 | .class2_alg_type = OP_ALG_ALGSEL_SHA384 | |
| 2729 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2730 | }, |
| 2731 | }, |
| 2732 | { |
| 2733 | .aead = { |
| 2734 | .base = { |
| 2735 | .cra_name = "echainiv(authenc(hmac(sha384)," |
| 2736 | "cbc(des3_ede)))", |
| 2737 | .cra_driver_name = "echainiv-authenc-" |
| 2738 | "hmac-sha384-" |
| 2739 | "cbc-des3_ede-caam", |
| 2740 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2741 | }, |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 2742 | .setkey = des3_aead_setkey, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2743 | .setauthsize = aead_setauthsize, |
| 2744 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 2745 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2746 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2747 | .maxauthsize = SHA384_DIGEST_SIZE, |
| 2748 | }, |
| 2749 | .caam = { |
| 2750 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2751 | .class2_alg_type = OP_ALG_ALGSEL_SHA384 | |
| 2752 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2753 | .geniv = true, |
| 2754 | }, |
| 2755 | }, |
| 2756 | { |
| 2757 | .aead = { |
| 2758 | .base = { |
| 2759 | .cra_name = "authenc(hmac(sha512)," |
| 2760 | "cbc(des3_ede))", |
| 2761 | .cra_driver_name = "authenc-hmac-sha512-" |
| 2762 | "cbc-des3_ede-caam", |
| 2763 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2764 | }, |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 2765 | .setkey = des3_aead_setkey, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2766 | .setauthsize = aead_setauthsize, |
| 2767 | .encrypt = aead_encrypt, |
| 2768 | .decrypt = aead_decrypt, |
| 2769 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2770 | .maxauthsize = SHA512_DIGEST_SIZE, |
| 2771 | }, |
| 2772 | .caam = { |
| 2773 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2774 | .class2_alg_type = OP_ALG_ALGSEL_SHA512 | |
| 2775 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2776 | }, |
| 2777 | }, |
| 2778 | { |
| 2779 | .aead = { |
| 2780 | .base = { |
| 2781 | .cra_name = "echainiv(authenc(hmac(sha512)," |
| 2782 | "cbc(des3_ede)))", |
| 2783 | .cra_driver_name = "echainiv-authenc-" |
| 2784 | "hmac-sha512-" |
| 2785 | "cbc-des3_ede-caam", |
| 2786 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2787 | }, |
Herbert Xu | 1b52c40 | 2019-04-11 16:51:02 +0800 | [diff] [blame] | 2788 | .setkey = des3_aead_setkey, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2789 | .setauthsize = aead_setauthsize, |
| 2790 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 2791 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2792 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2793 | .maxauthsize = SHA512_DIGEST_SIZE, |
| 2794 | }, |
| 2795 | .caam = { |
| 2796 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2797 | .class2_alg_type = OP_ALG_ALGSEL_SHA512 | |
| 2798 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2799 | .geniv = true, |
| 2800 | }, |
| 2801 | }, |
| 2802 | { |
| 2803 | .aead = { |
| 2804 | .base = { |
| 2805 | .cra_name = "authenc(hmac(md5),cbc(des))", |
| 2806 | .cra_driver_name = "authenc-hmac-md5-" |
| 2807 | "cbc-des-caam", |
| 2808 | .cra_blocksize = DES_BLOCK_SIZE, |
| 2809 | }, |
| 2810 | .setkey = aead_setkey, |
| 2811 | .setauthsize = aead_setauthsize, |
| 2812 | .encrypt = aead_encrypt, |
| 2813 | .decrypt = aead_decrypt, |
| 2814 | .ivsize = DES_BLOCK_SIZE, |
| 2815 | .maxauthsize = MD5_DIGEST_SIZE, |
| 2816 | }, |
| 2817 | .caam = { |
| 2818 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 2819 | .class2_alg_type = OP_ALG_ALGSEL_MD5 | |
| 2820 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2821 | }, |
| 2822 | }, |
| 2823 | { |
| 2824 | .aead = { |
| 2825 | .base = { |
| 2826 | .cra_name = "echainiv(authenc(hmac(md5)," |
| 2827 | "cbc(des)))", |
| 2828 | .cra_driver_name = "echainiv-authenc-hmac-md5-" |
| 2829 | "cbc-des-caam", |
| 2830 | .cra_blocksize = DES_BLOCK_SIZE, |
| 2831 | }, |
| 2832 | .setkey = aead_setkey, |
| 2833 | .setauthsize = aead_setauthsize, |
| 2834 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 2835 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2836 | .ivsize = DES_BLOCK_SIZE, |
| 2837 | .maxauthsize = MD5_DIGEST_SIZE, |
| 2838 | }, |
| 2839 | .caam = { |
| 2840 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 2841 | .class2_alg_type = OP_ALG_ALGSEL_MD5 | |
| 2842 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2843 | .geniv = true, |
| 2844 | }, |
| 2845 | }, |
| 2846 | { |
| 2847 | .aead = { |
| 2848 | .base = { |
| 2849 | .cra_name = "authenc(hmac(sha1),cbc(des))", |
| 2850 | .cra_driver_name = "authenc-hmac-sha1-" |
| 2851 | "cbc-des-caam", |
| 2852 | .cra_blocksize = DES_BLOCK_SIZE, |
| 2853 | }, |
| 2854 | .setkey = aead_setkey, |
| 2855 | .setauthsize = aead_setauthsize, |
| 2856 | .encrypt = aead_encrypt, |
| 2857 | .decrypt = aead_decrypt, |
| 2858 | .ivsize = DES_BLOCK_SIZE, |
| 2859 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 2860 | }, |
| 2861 | .caam = { |
| 2862 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 2863 | .class2_alg_type = OP_ALG_ALGSEL_SHA1 | |
| 2864 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2865 | }, |
| 2866 | }, |
| 2867 | { |
| 2868 | .aead = { |
| 2869 | .base = { |
| 2870 | .cra_name = "echainiv(authenc(hmac(sha1)," |
| 2871 | "cbc(des)))", |
| 2872 | .cra_driver_name = "echainiv-authenc-" |
| 2873 | "hmac-sha1-cbc-des-caam", |
| 2874 | .cra_blocksize = DES_BLOCK_SIZE, |
| 2875 | }, |
| 2876 | .setkey = aead_setkey, |
| 2877 | .setauthsize = aead_setauthsize, |
| 2878 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 2879 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2880 | .ivsize = DES_BLOCK_SIZE, |
| 2881 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 2882 | }, |
| 2883 | .caam = { |
| 2884 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 2885 | .class2_alg_type = OP_ALG_ALGSEL_SHA1 | |
| 2886 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2887 | .geniv = true, |
| 2888 | }, |
| 2889 | }, |
| 2890 | { |
| 2891 | .aead = { |
| 2892 | .base = { |
| 2893 | .cra_name = "authenc(hmac(sha224),cbc(des))", |
| 2894 | .cra_driver_name = "authenc-hmac-sha224-" |
| 2895 | "cbc-des-caam", |
| 2896 | .cra_blocksize = DES_BLOCK_SIZE, |
| 2897 | }, |
| 2898 | .setkey = aead_setkey, |
| 2899 | .setauthsize = aead_setauthsize, |
| 2900 | .encrypt = aead_encrypt, |
| 2901 | .decrypt = aead_decrypt, |
| 2902 | .ivsize = DES_BLOCK_SIZE, |
| 2903 | .maxauthsize = SHA224_DIGEST_SIZE, |
| 2904 | }, |
| 2905 | .caam = { |
| 2906 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 2907 | .class2_alg_type = OP_ALG_ALGSEL_SHA224 | |
| 2908 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2909 | }, |
| 2910 | }, |
| 2911 | { |
| 2912 | .aead = { |
| 2913 | .base = { |
| 2914 | .cra_name = "echainiv(authenc(hmac(sha224)," |
| 2915 | "cbc(des)))", |
| 2916 | .cra_driver_name = "echainiv-authenc-" |
| 2917 | "hmac-sha224-cbc-des-caam", |
| 2918 | .cra_blocksize = DES_BLOCK_SIZE, |
| 2919 | }, |
| 2920 | .setkey = aead_setkey, |
| 2921 | .setauthsize = aead_setauthsize, |
| 2922 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 2923 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2924 | .ivsize = DES_BLOCK_SIZE, |
| 2925 | .maxauthsize = SHA224_DIGEST_SIZE, |
| 2926 | }, |
| 2927 | .caam = { |
| 2928 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 2929 | .class2_alg_type = OP_ALG_ALGSEL_SHA224 | |
| 2930 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2931 | .geniv = true, |
| 2932 | }, |
| 2933 | }, |
| 2934 | { |
| 2935 | .aead = { |
| 2936 | .base = { |
| 2937 | .cra_name = "authenc(hmac(sha256),cbc(des))", |
| 2938 | .cra_driver_name = "authenc-hmac-sha256-" |
| 2939 | "cbc-des-caam", |
| 2940 | .cra_blocksize = DES_BLOCK_SIZE, |
| 2941 | }, |
| 2942 | .setkey = aead_setkey, |
| 2943 | .setauthsize = aead_setauthsize, |
| 2944 | .encrypt = aead_encrypt, |
| 2945 | .decrypt = aead_decrypt, |
| 2946 | .ivsize = DES_BLOCK_SIZE, |
| 2947 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 2948 | }, |
| 2949 | .caam = { |
| 2950 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 2951 | .class2_alg_type = OP_ALG_ALGSEL_SHA256 | |
| 2952 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2953 | }, |
| 2954 | }, |
| 2955 | { |
| 2956 | .aead = { |
| 2957 | .base = { |
| 2958 | .cra_name = "echainiv(authenc(hmac(sha256)," |
| 2959 | "cbc(des)))", |
| 2960 | .cra_driver_name = "echainiv-authenc-" |
| 2961 | "hmac-sha256-cbc-des-caam", |
| 2962 | .cra_blocksize = DES_BLOCK_SIZE, |
| 2963 | }, |
| 2964 | .setkey = aead_setkey, |
| 2965 | .setauthsize = aead_setauthsize, |
| 2966 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 2967 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2968 | .ivsize = DES_BLOCK_SIZE, |
| 2969 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 2970 | }, |
| 2971 | .caam = { |
| 2972 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 2973 | .class2_alg_type = OP_ALG_ALGSEL_SHA256 | |
| 2974 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2975 | .geniv = true, |
| 2976 | }, |
| 2977 | }, |
| 2978 | { |
| 2979 | .aead = { |
| 2980 | .base = { |
| 2981 | .cra_name = "authenc(hmac(sha384),cbc(des))", |
| 2982 | .cra_driver_name = "authenc-hmac-sha384-" |
| 2983 | "cbc-des-caam", |
| 2984 | .cra_blocksize = DES_BLOCK_SIZE, |
| 2985 | }, |
| 2986 | .setkey = aead_setkey, |
| 2987 | .setauthsize = aead_setauthsize, |
| 2988 | .encrypt = aead_encrypt, |
| 2989 | .decrypt = aead_decrypt, |
| 2990 | .ivsize = DES_BLOCK_SIZE, |
| 2991 | .maxauthsize = SHA384_DIGEST_SIZE, |
| 2992 | }, |
| 2993 | .caam = { |
| 2994 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 2995 | .class2_alg_type = OP_ALG_ALGSEL_SHA384 | |
| 2996 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 2997 | }, |
| 2998 | }, |
| 2999 | { |
| 3000 | .aead = { |
| 3001 | .base = { |
| 3002 | .cra_name = "echainiv(authenc(hmac(sha384)," |
| 3003 | "cbc(des)))", |
| 3004 | .cra_driver_name = "echainiv-authenc-" |
| 3005 | "hmac-sha384-cbc-des-caam", |
| 3006 | .cra_blocksize = DES_BLOCK_SIZE, |
| 3007 | }, |
| 3008 | .setkey = aead_setkey, |
| 3009 | .setauthsize = aead_setauthsize, |
| 3010 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 3011 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3012 | .ivsize = DES_BLOCK_SIZE, |
| 3013 | .maxauthsize = SHA384_DIGEST_SIZE, |
| 3014 | }, |
| 3015 | .caam = { |
| 3016 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 3017 | .class2_alg_type = OP_ALG_ALGSEL_SHA384 | |
| 3018 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3019 | .geniv = true, |
| 3020 | }, |
| 3021 | }, |
| 3022 | { |
| 3023 | .aead = { |
| 3024 | .base = { |
| 3025 | .cra_name = "authenc(hmac(sha512),cbc(des))", |
| 3026 | .cra_driver_name = "authenc-hmac-sha512-" |
| 3027 | "cbc-des-caam", |
| 3028 | .cra_blocksize = DES_BLOCK_SIZE, |
| 3029 | }, |
| 3030 | .setkey = aead_setkey, |
| 3031 | .setauthsize = aead_setauthsize, |
| 3032 | .encrypt = aead_encrypt, |
| 3033 | .decrypt = aead_decrypt, |
| 3034 | .ivsize = DES_BLOCK_SIZE, |
| 3035 | .maxauthsize = SHA512_DIGEST_SIZE, |
| 3036 | }, |
| 3037 | .caam = { |
| 3038 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 3039 | .class2_alg_type = OP_ALG_ALGSEL_SHA512 | |
| 3040 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3041 | }, |
| 3042 | }, |
| 3043 | { |
| 3044 | .aead = { |
| 3045 | .base = { |
| 3046 | .cra_name = "echainiv(authenc(hmac(sha512)," |
| 3047 | "cbc(des)))", |
| 3048 | .cra_driver_name = "echainiv-authenc-" |
| 3049 | "hmac-sha512-cbc-des-caam", |
| 3050 | .cra_blocksize = DES_BLOCK_SIZE, |
| 3051 | }, |
| 3052 | .setkey = aead_setkey, |
| 3053 | .setauthsize = aead_setauthsize, |
| 3054 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 3055 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3056 | .ivsize = DES_BLOCK_SIZE, |
| 3057 | .maxauthsize = SHA512_DIGEST_SIZE, |
| 3058 | }, |
| 3059 | .caam = { |
| 3060 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 3061 | .class2_alg_type = OP_ALG_ALGSEL_SHA512 | |
| 3062 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3063 | .geniv = true, |
| 3064 | }, |
| 3065 | }, |
| 3066 | { |
| 3067 | .aead = { |
| 3068 | .base = { |
| 3069 | .cra_name = "authenc(hmac(md5)," |
| 3070 | "rfc3686(ctr(aes)))", |
| 3071 | .cra_driver_name = "authenc-hmac-md5-" |
| 3072 | "rfc3686-ctr-aes-caam", |
| 3073 | .cra_blocksize = 1, |
| 3074 | }, |
| 3075 | .setkey = aead_setkey, |
| 3076 | .setauthsize = aead_setauthsize, |
| 3077 | .encrypt = aead_encrypt, |
| 3078 | .decrypt = aead_decrypt, |
| 3079 | .ivsize = CTR_RFC3686_IV_SIZE, |
| 3080 | .maxauthsize = MD5_DIGEST_SIZE, |
| 3081 | }, |
| 3082 | .caam = { |
| 3083 | .class1_alg_type = OP_ALG_ALGSEL_AES | |
| 3084 | OP_ALG_AAI_CTR_MOD128, |
| 3085 | .class2_alg_type = OP_ALG_ALGSEL_MD5 | |
| 3086 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3087 | .rfc3686 = true, |
| 3088 | }, |
| 3089 | }, |
| 3090 | { |
| 3091 | .aead = { |
| 3092 | .base = { |
| 3093 | .cra_name = "seqiv(authenc(" |
| 3094 | "hmac(md5),rfc3686(ctr(aes))))", |
| 3095 | .cra_driver_name = "seqiv-authenc-hmac-md5-" |
| 3096 | "rfc3686-ctr-aes-caam", |
| 3097 | .cra_blocksize = 1, |
| 3098 | }, |
| 3099 | .setkey = aead_setkey, |
| 3100 | .setauthsize = aead_setauthsize, |
| 3101 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 3102 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3103 | .ivsize = CTR_RFC3686_IV_SIZE, |
| 3104 | .maxauthsize = MD5_DIGEST_SIZE, |
| 3105 | }, |
| 3106 | .caam = { |
| 3107 | .class1_alg_type = OP_ALG_ALGSEL_AES | |
| 3108 | OP_ALG_AAI_CTR_MOD128, |
| 3109 | .class2_alg_type = OP_ALG_ALGSEL_MD5 | |
| 3110 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3111 | .rfc3686 = true, |
| 3112 | .geniv = true, |
| 3113 | }, |
| 3114 | }, |
| 3115 | { |
| 3116 | .aead = { |
| 3117 | .base = { |
| 3118 | .cra_name = "authenc(hmac(sha1)," |
| 3119 | "rfc3686(ctr(aes)))", |
| 3120 | .cra_driver_name = "authenc-hmac-sha1-" |
| 3121 | "rfc3686-ctr-aes-caam", |
| 3122 | .cra_blocksize = 1, |
| 3123 | }, |
| 3124 | .setkey = aead_setkey, |
| 3125 | .setauthsize = aead_setauthsize, |
| 3126 | .encrypt = aead_encrypt, |
| 3127 | .decrypt = aead_decrypt, |
| 3128 | .ivsize = CTR_RFC3686_IV_SIZE, |
| 3129 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 3130 | }, |
| 3131 | .caam = { |
| 3132 | .class1_alg_type = OP_ALG_ALGSEL_AES | |
| 3133 | OP_ALG_AAI_CTR_MOD128, |
| 3134 | .class2_alg_type = OP_ALG_ALGSEL_SHA1 | |
| 3135 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3136 | .rfc3686 = true, |
| 3137 | }, |
| 3138 | }, |
| 3139 | { |
| 3140 | .aead = { |
| 3141 | .base = { |
| 3142 | .cra_name = "seqiv(authenc(" |
| 3143 | "hmac(sha1),rfc3686(ctr(aes))))", |
| 3144 | .cra_driver_name = "seqiv-authenc-hmac-sha1-" |
| 3145 | "rfc3686-ctr-aes-caam", |
| 3146 | .cra_blocksize = 1, |
| 3147 | }, |
| 3148 | .setkey = aead_setkey, |
| 3149 | .setauthsize = aead_setauthsize, |
| 3150 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 3151 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3152 | .ivsize = CTR_RFC3686_IV_SIZE, |
| 3153 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 3154 | }, |
| 3155 | .caam = { |
| 3156 | .class1_alg_type = OP_ALG_ALGSEL_AES | |
| 3157 | OP_ALG_AAI_CTR_MOD128, |
| 3158 | .class2_alg_type = OP_ALG_ALGSEL_SHA1 | |
| 3159 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3160 | .rfc3686 = true, |
| 3161 | .geniv = true, |
| 3162 | }, |
| 3163 | }, |
| 3164 | { |
| 3165 | .aead = { |
| 3166 | .base = { |
| 3167 | .cra_name = "authenc(hmac(sha224)," |
| 3168 | "rfc3686(ctr(aes)))", |
| 3169 | .cra_driver_name = "authenc-hmac-sha224-" |
| 3170 | "rfc3686-ctr-aes-caam", |
| 3171 | .cra_blocksize = 1, |
| 3172 | }, |
| 3173 | .setkey = aead_setkey, |
| 3174 | .setauthsize = aead_setauthsize, |
| 3175 | .encrypt = aead_encrypt, |
| 3176 | .decrypt = aead_decrypt, |
| 3177 | .ivsize = CTR_RFC3686_IV_SIZE, |
| 3178 | .maxauthsize = SHA224_DIGEST_SIZE, |
| 3179 | }, |
| 3180 | .caam = { |
| 3181 | .class1_alg_type = OP_ALG_ALGSEL_AES | |
| 3182 | OP_ALG_AAI_CTR_MOD128, |
| 3183 | .class2_alg_type = OP_ALG_ALGSEL_SHA224 | |
| 3184 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3185 | .rfc3686 = true, |
| 3186 | }, |
| 3187 | }, |
| 3188 | { |
| 3189 | .aead = { |
| 3190 | .base = { |
| 3191 | .cra_name = "seqiv(authenc(" |
| 3192 | "hmac(sha224),rfc3686(ctr(aes))))", |
| 3193 | .cra_driver_name = "seqiv-authenc-hmac-sha224-" |
| 3194 | "rfc3686-ctr-aes-caam", |
| 3195 | .cra_blocksize = 1, |
| 3196 | }, |
| 3197 | .setkey = aead_setkey, |
| 3198 | .setauthsize = aead_setauthsize, |
| 3199 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 3200 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3201 | .ivsize = CTR_RFC3686_IV_SIZE, |
| 3202 | .maxauthsize = SHA224_DIGEST_SIZE, |
| 3203 | }, |
| 3204 | .caam = { |
| 3205 | .class1_alg_type = OP_ALG_ALGSEL_AES | |
| 3206 | OP_ALG_AAI_CTR_MOD128, |
| 3207 | .class2_alg_type = OP_ALG_ALGSEL_SHA224 | |
| 3208 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3209 | .rfc3686 = true, |
| 3210 | .geniv = true, |
| 3211 | }, |
| 3212 | }, |
| 3213 | { |
| 3214 | .aead = { |
| 3215 | .base = { |
| 3216 | .cra_name = "authenc(hmac(sha256)," |
| 3217 | "rfc3686(ctr(aes)))", |
| 3218 | .cra_driver_name = "authenc-hmac-sha256-" |
| 3219 | "rfc3686-ctr-aes-caam", |
| 3220 | .cra_blocksize = 1, |
| 3221 | }, |
| 3222 | .setkey = aead_setkey, |
| 3223 | .setauthsize = aead_setauthsize, |
| 3224 | .encrypt = aead_encrypt, |
| 3225 | .decrypt = aead_decrypt, |
| 3226 | .ivsize = CTR_RFC3686_IV_SIZE, |
| 3227 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 3228 | }, |
| 3229 | .caam = { |
| 3230 | .class1_alg_type = OP_ALG_ALGSEL_AES | |
| 3231 | OP_ALG_AAI_CTR_MOD128, |
| 3232 | .class2_alg_type = OP_ALG_ALGSEL_SHA256 | |
| 3233 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3234 | .rfc3686 = true, |
| 3235 | }, |
| 3236 | }, |
| 3237 | { |
| 3238 | .aead = { |
| 3239 | .base = { |
| 3240 | .cra_name = "seqiv(authenc(hmac(sha256)," |
| 3241 | "rfc3686(ctr(aes))))", |
| 3242 | .cra_driver_name = "seqiv-authenc-hmac-sha256-" |
| 3243 | "rfc3686-ctr-aes-caam", |
| 3244 | .cra_blocksize = 1, |
| 3245 | }, |
| 3246 | .setkey = aead_setkey, |
| 3247 | .setauthsize = aead_setauthsize, |
| 3248 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 3249 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3250 | .ivsize = CTR_RFC3686_IV_SIZE, |
| 3251 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 3252 | }, |
| 3253 | .caam = { |
| 3254 | .class1_alg_type = OP_ALG_ALGSEL_AES | |
| 3255 | OP_ALG_AAI_CTR_MOD128, |
| 3256 | .class2_alg_type = OP_ALG_ALGSEL_SHA256 | |
| 3257 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3258 | .rfc3686 = true, |
| 3259 | .geniv = true, |
| 3260 | }, |
| 3261 | }, |
| 3262 | { |
| 3263 | .aead = { |
| 3264 | .base = { |
| 3265 | .cra_name = "authenc(hmac(sha384)," |
| 3266 | "rfc3686(ctr(aes)))", |
| 3267 | .cra_driver_name = "authenc-hmac-sha384-" |
| 3268 | "rfc3686-ctr-aes-caam", |
| 3269 | .cra_blocksize = 1, |
| 3270 | }, |
| 3271 | .setkey = aead_setkey, |
| 3272 | .setauthsize = aead_setauthsize, |
| 3273 | .encrypt = aead_encrypt, |
| 3274 | .decrypt = aead_decrypt, |
| 3275 | .ivsize = CTR_RFC3686_IV_SIZE, |
| 3276 | .maxauthsize = SHA384_DIGEST_SIZE, |
| 3277 | }, |
| 3278 | .caam = { |
| 3279 | .class1_alg_type = OP_ALG_ALGSEL_AES | |
| 3280 | OP_ALG_AAI_CTR_MOD128, |
| 3281 | .class2_alg_type = OP_ALG_ALGSEL_SHA384 | |
| 3282 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3283 | .rfc3686 = true, |
| 3284 | }, |
| 3285 | }, |
| 3286 | { |
| 3287 | .aead = { |
| 3288 | .base = { |
| 3289 | .cra_name = "seqiv(authenc(hmac(sha384)," |
| 3290 | "rfc3686(ctr(aes))))", |
| 3291 | .cra_driver_name = "seqiv-authenc-hmac-sha384-" |
| 3292 | "rfc3686-ctr-aes-caam", |
| 3293 | .cra_blocksize = 1, |
| 3294 | }, |
| 3295 | .setkey = aead_setkey, |
| 3296 | .setauthsize = aead_setauthsize, |
| 3297 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 3298 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3299 | .ivsize = CTR_RFC3686_IV_SIZE, |
| 3300 | .maxauthsize = SHA384_DIGEST_SIZE, |
| 3301 | }, |
| 3302 | .caam = { |
| 3303 | .class1_alg_type = OP_ALG_ALGSEL_AES | |
| 3304 | OP_ALG_AAI_CTR_MOD128, |
| 3305 | .class2_alg_type = OP_ALG_ALGSEL_SHA384 | |
| 3306 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3307 | .rfc3686 = true, |
| 3308 | .geniv = true, |
| 3309 | }, |
| 3310 | }, |
| 3311 | { |
| 3312 | .aead = { |
| 3313 | .base = { |
| 3314 | .cra_name = "authenc(hmac(sha512)," |
| 3315 | "rfc3686(ctr(aes)))", |
| 3316 | .cra_driver_name = "authenc-hmac-sha512-" |
| 3317 | "rfc3686-ctr-aes-caam", |
| 3318 | .cra_blocksize = 1, |
| 3319 | }, |
| 3320 | .setkey = aead_setkey, |
| 3321 | .setauthsize = aead_setauthsize, |
| 3322 | .encrypt = aead_encrypt, |
| 3323 | .decrypt = aead_decrypt, |
| 3324 | .ivsize = CTR_RFC3686_IV_SIZE, |
| 3325 | .maxauthsize = SHA512_DIGEST_SIZE, |
| 3326 | }, |
| 3327 | .caam = { |
| 3328 | .class1_alg_type = OP_ALG_ALGSEL_AES | |
| 3329 | OP_ALG_AAI_CTR_MOD128, |
| 3330 | .class2_alg_type = OP_ALG_ALGSEL_SHA512 | |
| 3331 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3332 | .rfc3686 = true, |
| 3333 | }, |
| 3334 | }, |
| 3335 | { |
| 3336 | .aead = { |
| 3337 | .base = { |
| 3338 | .cra_name = "seqiv(authenc(hmac(sha512)," |
| 3339 | "rfc3686(ctr(aes))))", |
| 3340 | .cra_driver_name = "seqiv-authenc-hmac-sha512-" |
| 3341 | "rfc3686-ctr-aes-caam", |
| 3342 | .cra_blocksize = 1, |
| 3343 | }, |
| 3344 | .setkey = aead_setkey, |
| 3345 | .setauthsize = aead_setauthsize, |
| 3346 | .encrypt = aead_encrypt, |
Horia Geantă | 8b18e23 | 2016-08-29 14:52:14 +0300 | [diff] [blame] | 3347 | .decrypt = aead_decrypt, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3348 | .ivsize = CTR_RFC3686_IV_SIZE, |
| 3349 | .maxauthsize = SHA512_DIGEST_SIZE, |
| 3350 | }, |
| 3351 | .caam = { |
| 3352 | .class1_alg_type = OP_ALG_ALGSEL_AES | |
| 3353 | OP_ALG_AAI_CTR_MOD128, |
| 3354 | .class2_alg_type = OP_ALG_ALGSEL_SHA512 | |
| 3355 | OP_ALG_AAI_HMAC_PRECOMP, |
Herbert Xu | 479bcc7 | 2015-07-30 17:53:17 +0800 | [diff] [blame] | 3356 | .rfc3686 = true, |
| 3357 | .geniv = true, |
| 3358 | }, |
| 3359 | }, |
Horia Geantă | d6bbd4e | 2018-11-08 15:36:30 +0200 | [diff] [blame] | 3360 | { |
| 3361 | .aead = { |
| 3362 | .base = { |
| 3363 | .cra_name = "rfc7539(chacha20,poly1305)", |
| 3364 | .cra_driver_name = "rfc7539-chacha20-poly1305-" |
| 3365 | "caam", |
| 3366 | .cra_blocksize = 1, |
| 3367 | }, |
| 3368 | .setkey = chachapoly_setkey, |
| 3369 | .setauthsize = chachapoly_setauthsize, |
| 3370 | .encrypt = chachapoly_encrypt, |
| 3371 | .decrypt = chachapoly_decrypt, |
| 3372 | .ivsize = CHACHAPOLY_IV_SIZE, |
| 3373 | .maxauthsize = POLY1305_DIGEST_SIZE, |
| 3374 | }, |
| 3375 | .caam = { |
| 3376 | .class1_alg_type = OP_ALG_ALGSEL_CHACHA20 | |
| 3377 | OP_ALG_AAI_AEAD, |
| 3378 | .class2_alg_type = OP_ALG_ALGSEL_POLY1305 | |
| 3379 | OP_ALG_AAI_AEAD, |
Herbert Xu | 24586b5 | 2019-05-06 14:39:44 +0800 | [diff] [blame] | 3380 | .nodkp = true, |
Horia Geantă | d6bbd4e | 2018-11-08 15:36:30 +0200 | [diff] [blame] | 3381 | }, |
| 3382 | }, |
| 3383 | { |
| 3384 | .aead = { |
| 3385 | .base = { |
| 3386 | .cra_name = "rfc7539esp(chacha20,poly1305)", |
| 3387 | .cra_driver_name = "rfc7539esp-chacha20-" |
| 3388 | "poly1305-caam", |
| 3389 | .cra_blocksize = 1, |
| 3390 | }, |
| 3391 | .setkey = chachapoly_setkey, |
| 3392 | .setauthsize = chachapoly_setauthsize, |
| 3393 | .encrypt = chachapoly_encrypt, |
| 3394 | .decrypt = chachapoly_decrypt, |
| 3395 | .ivsize = 8, |
| 3396 | .maxauthsize = POLY1305_DIGEST_SIZE, |
| 3397 | }, |
| 3398 | .caam = { |
| 3399 | .class1_alg_type = OP_ALG_ALGSEL_CHACHA20 | |
| 3400 | OP_ALG_AAI_AEAD, |
| 3401 | .class2_alg_type = OP_ALG_ALGSEL_POLY1305 | |
| 3402 | OP_ALG_AAI_AEAD, |
Herbert Xu | 24586b5 | 2019-05-06 14:39:44 +0800 | [diff] [blame] | 3403 | .nodkp = true, |
Horia Geantă | d6bbd4e | 2018-11-08 15:36:30 +0200 | [diff] [blame] | 3404 | }, |
| 3405 | }, |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3406 | }; |
| 3407 | |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 3408 | static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam, |
| 3409 | bool uses_dkp) |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3410 | { |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 3411 | dma_addr_t dma_addr; |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 3412 | struct caam_drv_private *priv; |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 3413 | |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3414 | ctx->jrdev = caam_jr_alloc(); |
| 3415 | if (IS_ERR(ctx->jrdev)) { |
| 3416 | pr_err("Job Ring Device allocation for transform failed\n"); |
| 3417 | return PTR_ERR(ctx->jrdev); |
| 3418 | } |
| 3419 | |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 3420 | priv = dev_get_drvdata(ctx->jrdev->parent); |
| 3421 | if (priv->era >= 6 && uses_dkp) |
| 3422 | ctx->dir = DMA_BIDIRECTIONAL; |
| 3423 | else |
| 3424 | ctx->dir = DMA_TO_DEVICE; |
| 3425 | |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 3426 | dma_addr = dma_map_single_attrs(ctx->jrdev, ctx->sh_desc_enc, |
| 3427 | offsetof(struct caam_ctx, |
| 3428 | sh_desc_enc_dma), |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 3429 | ctx->dir, DMA_ATTR_SKIP_CPU_SYNC); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 3430 | if (dma_mapping_error(ctx->jrdev, dma_addr)) { |
| 3431 | dev_err(ctx->jrdev, "unable to map key, shared descriptors\n"); |
| 3432 | caam_jr_free(ctx->jrdev); |
| 3433 | return -ENOMEM; |
| 3434 | } |
| 3435 | |
| 3436 | ctx->sh_desc_enc_dma = dma_addr; |
| 3437 | ctx->sh_desc_dec_dma = dma_addr + offsetof(struct caam_ctx, |
| 3438 | sh_desc_dec); |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 3439 | ctx->key_dma = dma_addr + offsetof(struct caam_ctx, key); |
| 3440 | |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3441 | /* copy descriptor header template value */ |
Horia Geantă | db57656 | 2016-11-22 15:44:04 +0200 | [diff] [blame] | 3442 | ctx->cdata.algtype = OP_TYPE_CLASS1_ALG | caam->class1_alg_type; |
| 3443 | ctx->adata.algtype = OP_TYPE_CLASS2_ALG | caam->class2_alg_type; |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3444 | |
| 3445 | return 0; |
| 3446 | } |
| 3447 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 3448 | static int caam_cra_init(struct crypto_skcipher *tfm) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3449 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 3450 | struct skcipher_alg *alg = crypto_skcipher_alg(tfm); |
| 3451 | struct caam_skcipher_alg *caam_alg = |
| 3452 | container_of(alg, typeof(*caam_alg), skcipher); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3453 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 3454 | return caam_init_common(crypto_skcipher_ctx(tfm), &caam_alg->caam, |
| 3455 | false); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3456 | } |
| 3457 | |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3458 | static int caam_aead_init(struct crypto_aead *tfm) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3459 | { |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3460 | struct aead_alg *alg = crypto_aead_alg(tfm); |
| 3461 | struct caam_aead_alg *caam_alg = |
| 3462 | container_of(alg, struct caam_aead_alg, aead); |
| 3463 | struct caam_ctx *ctx = crypto_aead_ctx(tfm); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3464 | |
Herbert Xu | 24586b5 | 2019-05-06 14:39:44 +0800 | [diff] [blame] | 3465 | return caam_init_common(ctx, &caam_alg->caam, !caam_alg->caam.nodkp); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3466 | } |
| 3467 | |
| 3468 | static void caam_exit_common(struct caam_ctx *ctx) |
| 3469 | { |
Horia Geantă | bbf2234 | 2017-02-10 14:07:22 +0200 | [diff] [blame] | 3470 | dma_unmap_single_attrs(ctx->jrdev, ctx->sh_desc_enc_dma, |
| 3471 | offsetof(struct caam_ctx, sh_desc_enc_dma), |
Horia Geantă | 7e0880b | 2017-12-19 12:16:07 +0200 | [diff] [blame] | 3472 | ctx->dir, DMA_ATTR_SKIP_CPU_SYNC); |
Ruchika Gupta | cfc6f11 | 2013-10-25 12:01:03 +0530 | [diff] [blame] | 3473 | caam_jr_free(ctx->jrdev); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3474 | } |
| 3475 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 3476 | static void caam_cra_exit(struct crypto_skcipher *tfm) |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3477 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 3478 | caam_exit_common(crypto_skcipher_ctx(tfm)); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | static void caam_aead_exit(struct crypto_aead *tfm) |
| 3482 | { |
| 3483 | caam_exit_common(crypto_aead_ctx(tfm)); |
| 3484 | } |
| 3485 | |
Horia Geantă | 1b46c90 | 2019-05-03 17:17:39 +0300 | [diff] [blame] | 3486 | void caam_algapi_exit(void) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3487 | { |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3488 | int i; |
| 3489 | |
| 3490 | for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) { |
| 3491 | struct caam_aead_alg *t_alg = driver_aeads + i; |
| 3492 | |
| 3493 | if (t_alg->registered) |
| 3494 | crypto_unregister_aead(&t_alg->aead); |
| 3495 | } |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3496 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 3497 | for (i = 0; i < ARRAY_SIZE(driver_algs); i++) { |
| 3498 | struct caam_skcipher_alg *t_alg = driver_algs + i; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3499 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 3500 | if (t_alg->registered) |
| 3501 | crypto_unregister_skcipher(&t_alg->skcipher); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3502 | } |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3503 | } |
| 3504 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 3505 | static void caam_skcipher_alg_init(struct caam_skcipher_alg *t_alg) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3506 | { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 3507 | struct skcipher_alg *alg = &t_alg->skcipher; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3508 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 3509 | alg->base.cra_module = THIS_MODULE; |
| 3510 | alg->base.cra_priority = CAAM_CRA_PRIORITY; |
| 3511 | alg->base.cra_ctxsize = sizeof(struct caam_ctx); |
| 3512 | alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3513 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 3514 | alg->init = caam_cra_init; |
| 3515 | alg->exit = caam_cra_exit; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3516 | } |
| 3517 | |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3518 | static void caam_aead_alg_init(struct caam_aead_alg *t_alg) |
| 3519 | { |
| 3520 | struct aead_alg *alg = &t_alg->aead; |
| 3521 | |
| 3522 | alg->base.cra_module = THIS_MODULE; |
| 3523 | alg->base.cra_priority = CAAM_CRA_PRIORITY; |
| 3524 | alg->base.cra_ctxsize = sizeof(struct caam_ctx); |
Herbert Xu | 5e4b8c1 | 2015-08-13 17:29:06 +0800 | [diff] [blame] | 3525 | alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY; |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3526 | |
| 3527 | alg->init = caam_aead_init; |
| 3528 | alg->exit = caam_aead_exit; |
| 3529 | } |
| 3530 | |
Horia Geantă | 1b46c90 | 2019-05-03 17:17:39 +0300 | [diff] [blame] | 3531 | int caam_algapi_init(struct device *ctrldev) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3532 | { |
Horia Geantă | 1b46c90 | 2019-05-03 17:17:39 +0300 | [diff] [blame] | 3533 | struct caam_drv_private *priv = dev_get_drvdata(ctrldev); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3534 | int i = 0, err = 0; |
Horia Geantă | d6bbd4e | 2018-11-08 15:36:30 +0200 | [diff] [blame] | 3535 | u32 aes_vid, aes_inst, des_inst, md_vid, md_inst, ccha_inst, ptha_inst; |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 3536 | u32 arc4_inst; |
Victoria Milhoan | bf83490 | 2015-08-05 11:28:48 -0700 | [diff] [blame] | 3537 | unsigned int md_limit = SHA512_DIGEST_SIZE; |
Horia Geantă | df80bfd | 2019-04-16 19:27:12 +0300 | [diff] [blame] | 3538 | bool registered = false, gcm_support; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3539 | |
Victoria Milhoan | bf83490 | 2015-08-05 11:28:48 -0700 | [diff] [blame] | 3540 | /* |
| 3541 | * Register crypto algorithms the device supports. |
| 3542 | * First, detect presence and attributes of DES, AES, and MD blocks. |
| 3543 | */ |
Horia Geantă | d239b10 | 2018-11-08 15:36:27 +0200 | [diff] [blame] | 3544 | if (priv->era < 10) { |
Horia Geantă | df80bfd | 2019-04-16 19:27:12 +0300 | [diff] [blame] | 3545 | u32 cha_vid, cha_inst, aes_rn; |
Horia Geantă | d239b10 | 2018-11-08 15:36:27 +0200 | [diff] [blame] | 3546 | |
| 3547 | cha_vid = rd_reg32(&priv->ctrl->perfmon.cha_id_ls); |
| 3548 | aes_vid = cha_vid & CHA_ID_LS_AES_MASK; |
| 3549 | md_vid = (cha_vid & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT; |
| 3550 | |
| 3551 | cha_inst = rd_reg32(&priv->ctrl->perfmon.cha_num_ls); |
| 3552 | des_inst = (cha_inst & CHA_ID_LS_DES_MASK) >> |
| 3553 | CHA_ID_LS_DES_SHIFT; |
| 3554 | aes_inst = cha_inst & CHA_ID_LS_AES_MASK; |
| 3555 | md_inst = (cha_inst & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT; |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 3556 | arc4_inst = (cha_inst & CHA_ID_LS_ARC4_MASK) >> |
| 3557 | CHA_ID_LS_ARC4_SHIFT; |
Horia Geantă | d6bbd4e | 2018-11-08 15:36:30 +0200 | [diff] [blame] | 3558 | ccha_inst = 0; |
| 3559 | ptha_inst = 0; |
Horia Geantă | df80bfd | 2019-04-16 19:27:12 +0300 | [diff] [blame] | 3560 | |
| 3561 | aes_rn = rd_reg32(&priv->ctrl->perfmon.cha_rev_ls) & |
| 3562 | CHA_ID_LS_AES_MASK; |
| 3563 | gcm_support = !(aes_vid == CHA_VER_VID_AES_LP && aes_rn < 8); |
Horia Geantă | d239b10 | 2018-11-08 15:36:27 +0200 | [diff] [blame] | 3564 | } else { |
| 3565 | u32 aesa, mdha; |
| 3566 | |
| 3567 | aesa = rd_reg32(&priv->ctrl->vreg.aesa); |
| 3568 | mdha = rd_reg32(&priv->ctrl->vreg.mdha); |
| 3569 | |
| 3570 | aes_vid = (aesa & CHA_VER_VID_MASK) >> CHA_VER_VID_SHIFT; |
| 3571 | md_vid = (mdha & CHA_VER_VID_MASK) >> CHA_VER_VID_SHIFT; |
| 3572 | |
| 3573 | des_inst = rd_reg32(&priv->ctrl->vreg.desa) & CHA_VER_NUM_MASK; |
| 3574 | aes_inst = aesa & CHA_VER_NUM_MASK; |
| 3575 | md_inst = mdha & CHA_VER_NUM_MASK; |
Horia Geantă | d6bbd4e | 2018-11-08 15:36:30 +0200 | [diff] [blame] | 3576 | ccha_inst = rd_reg32(&priv->ctrl->vreg.ccha) & CHA_VER_NUM_MASK; |
| 3577 | ptha_inst = rd_reg32(&priv->ctrl->vreg.ptha) & CHA_VER_NUM_MASK; |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 3578 | arc4_inst = rd_reg32(&priv->ctrl->vreg.afha) & CHA_VER_NUM_MASK; |
Horia Geantă | df80bfd | 2019-04-16 19:27:12 +0300 | [diff] [blame] | 3579 | |
| 3580 | gcm_support = aesa & CHA_VER_MISC_AES_GCM; |
Horia Geantă | d239b10 | 2018-11-08 15:36:27 +0200 | [diff] [blame] | 3581 | } |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3582 | |
Victoria Milhoan | bf83490 | 2015-08-05 11:28:48 -0700 | [diff] [blame] | 3583 | /* If MD is present, limit digest size based on LP256 */ |
Horia Geantă | d239b10 | 2018-11-08 15:36:27 +0200 | [diff] [blame] | 3584 | if (md_inst && md_vid == CHA_VER_VID_MD_LP256) |
Victoria Milhoan | bf83490 | 2015-08-05 11:28:48 -0700 | [diff] [blame] | 3585 | md_limit = SHA256_DIGEST_SIZE; |
| 3586 | |
| 3587 | for (i = 0; i < ARRAY_SIZE(driver_algs); i++) { |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 3588 | struct caam_skcipher_alg *t_alg = driver_algs + i; |
| 3589 | u32 alg_sel = t_alg->caam.class1_alg_type & OP_ALG_ALGSEL_MASK; |
Victoria Milhoan | bf83490 | 2015-08-05 11:28:48 -0700 | [diff] [blame] | 3590 | |
| 3591 | /* Skip DES algorithms if not supported by device */ |
| 3592 | if (!des_inst && |
| 3593 | ((alg_sel == OP_ALG_ALGSEL_3DES) || |
| 3594 | (alg_sel == OP_ALG_ALGSEL_DES))) |
| 3595 | continue; |
| 3596 | |
| 3597 | /* Skip AES algorithms if not supported by device */ |
| 3598 | if (!aes_inst && (alg_sel == OP_ALG_ALGSEL_AES)) |
| 3599 | continue; |
| 3600 | |
Iuliana Prodan | eaed71a | 2019-02-08 15:50:09 +0200 | [diff] [blame] | 3601 | /* Skip ARC4 algorithms if not supported by device */ |
| 3602 | if (!arc4_inst && alg_sel == OP_ALG_ALGSEL_ARC4) |
| 3603 | continue; |
| 3604 | |
Sven Ebenfeld | 83d2c9a | 2016-11-07 18:51:34 +0100 | [diff] [blame] | 3605 | /* |
| 3606 | * Check support for AES modes not available |
| 3607 | * on LP devices. |
| 3608 | */ |
Horia Geantă | d239b10 | 2018-11-08 15:36:27 +0200 | [diff] [blame] | 3609 | if (aes_vid == CHA_VER_VID_AES_LP && |
| 3610 | (t_alg->caam.class1_alg_type & OP_ALG_AAI_MASK) == |
| 3611 | OP_ALG_AAI_XTS) |
| 3612 | continue; |
Sven Ebenfeld | 83d2c9a | 2016-11-07 18:51:34 +0100 | [diff] [blame] | 3613 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 3614 | caam_skcipher_alg_init(t_alg); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3615 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 3616 | err = crypto_register_skcipher(&t_alg->skcipher); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3617 | if (err) { |
Ruchika Gupta | cfc6f11 | 2013-10-25 12:01:03 +0530 | [diff] [blame] | 3618 | pr_warn("%s alg registration failed\n", |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 3619 | t_alg->skcipher.base.cra_driver_name); |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3620 | continue; |
| 3621 | } |
| 3622 | |
Horia Geantă | 5ca7bad | 2018-08-06 15:43:59 +0300 | [diff] [blame] | 3623 | t_alg->registered = true; |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3624 | registered = true; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3625 | } |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3626 | |
| 3627 | for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) { |
| 3628 | struct caam_aead_alg *t_alg = driver_aeads + i; |
Victoria Milhoan | bf83490 | 2015-08-05 11:28:48 -0700 | [diff] [blame] | 3629 | u32 c1_alg_sel = t_alg->caam.class1_alg_type & |
| 3630 | OP_ALG_ALGSEL_MASK; |
| 3631 | u32 c2_alg_sel = t_alg->caam.class2_alg_type & |
| 3632 | OP_ALG_ALGSEL_MASK; |
| 3633 | u32 alg_aai = t_alg->caam.class1_alg_type & OP_ALG_AAI_MASK; |
| 3634 | |
| 3635 | /* Skip DES algorithms if not supported by device */ |
| 3636 | if (!des_inst && |
| 3637 | ((c1_alg_sel == OP_ALG_ALGSEL_3DES) || |
| 3638 | (c1_alg_sel == OP_ALG_ALGSEL_DES))) |
| 3639 | continue; |
| 3640 | |
| 3641 | /* Skip AES algorithms if not supported by device */ |
| 3642 | if (!aes_inst && (c1_alg_sel == OP_ALG_ALGSEL_AES)) |
| 3643 | continue; |
| 3644 | |
Horia Geantă | d6bbd4e | 2018-11-08 15:36:30 +0200 | [diff] [blame] | 3645 | /* Skip CHACHA20 algorithms if not supported by device */ |
| 3646 | if (c1_alg_sel == OP_ALG_ALGSEL_CHACHA20 && !ccha_inst) |
| 3647 | continue; |
| 3648 | |
| 3649 | /* Skip POLY1305 algorithms if not supported by device */ |
| 3650 | if (c2_alg_sel == OP_ALG_ALGSEL_POLY1305 && !ptha_inst) |
| 3651 | continue; |
| 3652 | |
Horia Geantă | df80bfd | 2019-04-16 19:27:12 +0300 | [diff] [blame] | 3653 | /* Skip GCM algorithms if not supported by device */ |
| 3654 | if (c1_alg_sel == OP_ALG_ALGSEL_AES && |
| 3655 | alg_aai == OP_ALG_AAI_GCM && !gcm_support) |
Horia Geantă | d239b10 | 2018-11-08 15:36:27 +0200 | [diff] [blame] | 3656 | continue; |
Victoria Milhoan | bf83490 | 2015-08-05 11:28:48 -0700 | [diff] [blame] | 3657 | |
| 3658 | /* |
| 3659 | * Skip algorithms requiring message digests |
| 3660 | * if MD or MD size is not supported by device. |
| 3661 | */ |
Horia Geantă | 2dd3fde | 2018-12-21 14:47:46 +0200 | [diff] [blame] | 3662 | if (is_mdha(c2_alg_sel) && |
Horia Geantă | d6bbd4e | 2018-11-08 15:36:30 +0200 | [diff] [blame] | 3663 | (!md_inst || t_alg->aead.maxauthsize > md_limit)) |
| 3664 | continue; |
Herbert Xu | f2147b8 | 2015-06-16 13:54:23 +0800 | [diff] [blame] | 3665 | |
| 3666 | caam_aead_alg_init(t_alg); |
| 3667 | |
| 3668 | err = crypto_register_aead(&t_alg->aead); |
| 3669 | if (err) { |
| 3670 | pr_warn("%s alg registration failed\n", |
| 3671 | t_alg->aead.base.cra_driver_name); |
| 3672 | continue; |
| 3673 | } |
| 3674 | |
| 3675 | t_alg->registered = true; |
| 3676 | registered = true; |
| 3677 | } |
| 3678 | |
| 3679 | if (registered) |
Ruchika Gupta | cfc6f11 | 2013-10-25 12:01:03 +0530 | [diff] [blame] | 3680 | pr_info("caam algorithms registered in /proc/crypto\n"); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3681 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 3682 | return err; |
| 3683 | } |