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