Thomas Gleixner | 25763b3 | 2019-05-28 10:10:09 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Intel IXP4xx NPE-C crypto driver |
| 4 | * |
| 5 | * Copyright (C) 2008 Christian Hohnstaedt <chohnstaedt@innominate.com> |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/platform_device.h> |
| 9 | #include <linux/dma-mapping.h> |
| 10 | #include <linux/dmapool.h> |
| 11 | #include <linux/crypto.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/rtnetlink.h> |
| 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/spinlock.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/gfp.h> |
Michał Wróbel | 75258723 | 2012-04-05 20:34:21 +0800 | [diff] [blame] | 17 | #include <linux/module.h> |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 18 | |
| 19 | #include <crypto/ctr.h> |
Ard Biesheuvel | 3ca20b6 | 2019-08-15 12:00:56 +0300 | [diff] [blame] | 20 | #include <crypto/internal/des.h> |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 21 | #include <crypto/aes.h> |
Corentin LABBE | bb9634d | 2017-05-19 08:53:25 +0200 | [diff] [blame] | 22 | #include <crypto/hmac.h> |
Eric Biggers | a24d22b | 2020-11-12 21:20:21 -0800 | [diff] [blame] | 23 | #include <crypto/sha1.h> |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 24 | #include <crypto/algapi.h> |
Herbert Xu | 5290b42 | 2015-05-11 17:47:44 +0800 | [diff] [blame] | 25 | #include <crypto/internal/aead.h> |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 26 | #include <crypto/internal/skcipher.h> |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 27 | #include <crypto/authenc.h> |
| 28 | #include <crypto/scatterwalk.h> |
| 29 | |
Linus Walleij | 4af20dc | 2019-02-10 14:55:58 +0100 | [diff] [blame] | 30 | #include <linux/soc/ixp4xx/npe.h> |
| 31 | #include <linux/soc/ixp4xx/qmgr.h> |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 32 | |
| 33 | #define MAX_KEYLEN 32 |
| 34 | |
| 35 | /* hash: cfgword + 2 * digestlen; crypt: keylen + cfgword */ |
| 36 | #define NPE_CTX_LEN 80 |
| 37 | #define AES_BLOCK128 16 |
| 38 | |
| 39 | #define NPE_OP_HASH_VERIFY 0x01 |
| 40 | #define NPE_OP_CCM_ENABLE 0x04 |
| 41 | #define NPE_OP_CRYPT_ENABLE 0x08 |
| 42 | #define NPE_OP_HASH_ENABLE 0x10 |
| 43 | #define NPE_OP_NOT_IN_PLACE 0x20 |
| 44 | #define NPE_OP_HMAC_DISABLE 0x40 |
| 45 | #define NPE_OP_CRYPT_ENCRYPT 0x80 |
| 46 | |
| 47 | #define NPE_OP_CCM_GEN_MIC 0xcc |
| 48 | #define NPE_OP_HASH_GEN_ICV 0x50 |
| 49 | #define NPE_OP_ENC_GEN_KEY 0xc9 |
| 50 | |
| 51 | #define MOD_ECB 0x0000 |
| 52 | #define MOD_CTR 0x1000 |
| 53 | #define MOD_CBC_ENC 0x2000 |
| 54 | #define MOD_CBC_DEC 0x3000 |
| 55 | #define MOD_CCM_ENC 0x4000 |
| 56 | #define MOD_CCM_DEC 0x5000 |
| 57 | |
| 58 | #define KEYLEN_128 4 |
| 59 | #define KEYLEN_192 6 |
| 60 | #define KEYLEN_256 8 |
| 61 | |
| 62 | #define CIPH_DECR 0x0000 |
| 63 | #define CIPH_ENCR 0x0400 |
| 64 | |
| 65 | #define MOD_DES 0x0000 |
| 66 | #define MOD_TDEA2 0x0100 |
| 67 | #define MOD_3DES 0x0200 |
| 68 | #define MOD_AES 0x0800 |
| 69 | #define MOD_AES128 (0x0800 | KEYLEN_128) |
| 70 | #define MOD_AES192 (0x0900 | KEYLEN_192) |
| 71 | #define MOD_AES256 (0x0a00 | KEYLEN_256) |
| 72 | |
| 73 | #define MAX_IVLEN 16 |
| 74 | #define NPE_ID 2 /* NPE C */ |
| 75 | #define NPE_QLEN 16 |
| 76 | /* Space for registering when the first |
| 77 | * NPE_QLEN crypt_ctl are busy */ |
| 78 | #define NPE_QLEN_TOTAL 64 |
| 79 | |
| 80 | #define SEND_QID 29 |
| 81 | #define RECV_QID 30 |
| 82 | |
| 83 | #define CTL_FLAG_UNUSED 0x0000 |
| 84 | #define CTL_FLAG_USED 0x1000 |
| 85 | #define CTL_FLAG_PERFORM_ABLK 0x0001 |
| 86 | #define CTL_FLAG_GEN_ICV 0x0002 |
| 87 | #define CTL_FLAG_GEN_REVAES 0x0004 |
| 88 | #define CTL_FLAG_PERFORM_AEAD 0x0008 |
| 89 | #define CTL_FLAG_MASK 0x000f |
| 90 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 91 | #define HMAC_PAD_BLOCKLEN SHA1_BLOCK_SIZE |
| 92 | |
| 93 | #define MD5_DIGEST_SIZE 16 |
| 94 | |
| 95 | struct buffer_desc { |
| 96 | u32 phys_next; |
Krzysztof Hałasa | ce05729 | 2010-01-10 14:20:10 +0100 | [diff] [blame] | 97 | #ifdef __ARMEB__ |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 98 | u16 buf_len; |
| 99 | u16 pkt_len; |
Krzysztof Hałasa | ce05729 | 2010-01-10 14:20:10 +0100 | [diff] [blame] | 100 | #else |
| 101 | u16 pkt_len; |
| 102 | u16 buf_len; |
| 103 | #endif |
Herbert Xu | ff455ad9 | 2019-05-23 14:35:30 +0800 | [diff] [blame] | 104 | dma_addr_t phys_addr; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 105 | u32 __reserved[4]; |
| 106 | struct buffer_desc *next; |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 107 | enum dma_data_direction dir; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | struct crypt_ctl { |
Krzysztof Hałasa | ce05729 | 2010-01-10 14:20:10 +0100 | [diff] [blame] | 111 | #ifdef __ARMEB__ |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 112 | u8 mode; /* NPE_OP_* operation mode */ |
| 113 | u8 init_len; |
| 114 | u16 reserved; |
Krzysztof Hałasa | ce05729 | 2010-01-10 14:20:10 +0100 | [diff] [blame] | 115 | #else |
| 116 | u16 reserved; |
| 117 | u8 init_len; |
| 118 | u8 mode; /* NPE_OP_* operation mode */ |
| 119 | #endif |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 120 | u8 iv[MAX_IVLEN]; /* IV for CBC mode or CTR IV for CTR mode */ |
Herbert Xu | ff455ad9 | 2019-05-23 14:35:30 +0800 | [diff] [blame] | 121 | dma_addr_t icv_rev_aes; /* icv or rev aes */ |
| 122 | dma_addr_t src_buf; |
| 123 | dma_addr_t dst_buf; |
Krzysztof Hałasa | ce05729 | 2010-01-10 14:20:10 +0100 | [diff] [blame] | 124 | #ifdef __ARMEB__ |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 125 | u16 auth_offs; /* Authentication start offset */ |
| 126 | u16 auth_len; /* Authentication data length */ |
| 127 | u16 crypt_offs; /* Cryption start offset */ |
| 128 | u16 crypt_len; /* Cryption data length */ |
Krzysztof Hałasa | ce05729 | 2010-01-10 14:20:10 +0100 | [diff] [blame] | 129 | #else |
| 130 | u16 auth_len; /* Authentication data length */ |
| 131 | u16 auth_offs; /* Authentication start offset */ |
| 132 | u16 crypt_len; /* Cryption data length */ |
| 133 | u16 crypt_offs; /* Cryption start offset */ |
| 134 | #endif |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 135 | u32 aadAddr; /* Additional Auth Data Addr for CCM mode */ |
| 136 | u32 crypto_ctx; /* NPE Crypto Param structure address */ |
| 137 | |
| 138 | /* Used by Host: 4*4 bytes*/ |
Corentin Labbe | 3557084 | 2021-05-05 20:26:11 +0000 | [diff] [blame] | 139 | unsigned int ctl_flags; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 140 | union { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 141 | struct skcipher_request *ablk_req; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 142 | struct aead_request *aead_req; |
| 143 | struct crypto_tfm *tfm; |
| 144 | } data; |
| 145 | struct buffer_desc *regist_buf; |
| 146 | u8 *regist_ptr; |
| 147 | }; |
| 148 | |
| 149 | struct ablk_ctx { |
| 150 | struct buffer_desc *src; |
| 151 | struct buffer_desc *dst; |
Corentin Labbe | e8acf01 | 2021-05-05 20:26:09 +0000 | [diff] [blame] | 152 | u8 iv[MAX_IVLEN]; |
| 153 | bool encrypt; |
Corentin Labbe | dfb098d | 2021-05-05 20:26:10 +0000 | [diff] [blame] | 154 | struct skcipher_request fallback_req; // keep at the end |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | struct aead_ctx { |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 158 | struct buffer_desc *src; |
| 159 | struct buffer_desc *dst; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 160 | struct scatterlist ivlist; |
| 161 | /* used when the hmac is not on one sg entry */ |
| 162 | u8 *hmac_virt; |
| 163 | int encrypt; |
| 164 | }; |
| 165 | |
| 166 | struct ix_hash_algo { |
| 167 | u32 cfgword; |
| 168 | unsigned char *icv; |
| 169 | }; |
| 170 | |
| 171 | struct ix_sa_dir { |
| 172 | unsigned char *npe_ctx; |
| 173 | dma_addr_t npe_ctx_phys; |
| 174 | int npe_ctx_idx; |
| 175 | u8 npe_mode; |
| 176 | }; |
| 177 | |
| 178 | struct ixp_ctx { |
| 179 | struct ix_sa_dir encrypt; |
| 180 | struct ix_sa_dir decrypt; |
| 181 | int authkey_len; |
| 182 | u8 authkey[MAX_KEYLEN]; |
| 183 | int enckey_len; |
| 184 | u8 enckey[MAX_KEYLEN]; |
| 185 | u8 salt[MAX_IVLEN]; |
| 186 | u8 nonce[CTR_RFC3686_NONCE_SIZE]; |
Corentin Labbe | 3557084 | 2021-05-05 20:26:11 +0000 | [diff] [blame] | 187 | unsigned int salted; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 188 | atomic_t configuring; |
| 189 | struct completion completion; |
Corentin Labbe | dfb098d | 2021-05-05 20:26:10 +0000 | [diff] [blame] | 190 | struct crypto_skcipher *fallback_tfm; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | struct ixp_alg { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 194 | struct skcipher_alg crypto; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 195 | const struct ix_hash_algo *hash; |
| 196 | u32 cfg_enc; |
| 197 | u32 cfg_dec; |
| 198 | |
| 199 | int registered; |
| 200 | }; |
| 201 | |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 202 | struct ixp_aead_alg { |
| 203 | struct aead_alg crypto; |
| 204 | const struct ix_hash_algo *hash; |
| 205 | u32 cfg_enc; |
| 206 | u32 cfg_dec; |
| 207 | |
| 208 | int registered; |
| 209 | }; |
| 210 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 211 | static const struct ix_hash_algo hash_alg_md5 = { |
| 212 | .cfgword = 0xAA010004, |
| 213 | .icv = "\x01\x23\x45\x67\x89\xAB\xCD\xEF" |
| 214 | "\xFE\xDC\xBA\x98\x76\x54\x32\x10", |
| 215 | }; |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 216 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 217 | static const struct ix_hash_algo hash_alg_sha1 = { |
| 218 | .cfgword = 0x00000005, |
| 219 | .icv = "\x67\x45\x23\x01\xEF\xCD\xAB\x89\x98\xBA" |
| 220 | "\xDC\xFE\x10\x32\x54\x76\xC3\xD2\xE1\xF0", |
| 221 | }; |
| 222 | |
| 223 | static struct npe *npe_c; |
Corentin Labbe | 87d11a5 | 2021-05-05 20:26:14 +0000 | [diff] [blame^] | 224 | static struct dma_pool *buffer_pool; |
| 225 | static struct dma_pool *ctx_pool; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 226 | |
Corentin Labbe | 87d11a5 | 2021-05-05 20:26:14 +0000 | [diff] [blame^] | 227 | static struct crypt_ctl *crypt_virt; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 228 | static dma_addr_t crypt_phys; |
| 229 | |
| 230 | static int support_aes = 1; |
| 231 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 232 | #define DRIVER_NAME "ixp4xx_crypto" |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 233 | |
Russell King | d8cbc3f | 2013-06-10 18:52:52 +0100 | [diff] [blame] | 234 | static struct platform_device *pdev; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 235 | |
| 236 | static inline dma_addr_t crypt_virt2phys(struct crypt_ctl *virt) |
| 237 | { |
| 238 | return crypt_phys + (virt - crypt_virt) * sizeof(struct crypt_ctl); |
| 239 | } |
| 240 | |
| 241 | static inline struct crypt_ctl *crypt_phys2virt(dma_addr_t phys) |
| 242 | { |
| 243 | return crypt_virt + (phys - crypt_phys) / sizeof(struct crypt_ctl); |
| 244 | } |
| 245 | |
| 246 | static inline u32 cipher_cfg_enc(struct crypto_tfm *tfm) |
| 247 | { |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 248 | return container_of(tfm->__crt_alg, struct ixp_alg, crypto.base)->cfg_enc; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | static inline u32 cipher_cfg_dec(struct crypto_tfm *tfm) |
| 252 | { |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 253 | return container_of(tfm->__crt_alg, struct ixp_alg, crypto.base)->cfg_dec; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | static inline const struct ix_hash_algo *ix_hash(struct crypto_tfm *tfm) |
| 257 | { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 258 | return container_of(tfm->__crt_alg, struct ixp_alg, crypto.base)->hash; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | static int setup_crypt_desc(void) |
| 262 | { |
Russell King | 27c1789 | 2013-06-10 19:09:45 +0100 | [diff] [blame] | 263 | struct device *dev = &pdev->dev; |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 264 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 265 | BUILD_BUG_ON(sizeof(struct crypt_ctl) != 64); |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 266 | crypt_virt = dma_alloc_coherent(dev, |
| 267 | NPE_QLEN * sizeof(struct crypt_ctl), |
| 268 | &crypt_phys, GFP_ATOMIC); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 269 | if (!crypt_virt) |
| 270 | return -ENOMEM; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 271 | return 0; |
| 272 | } |
| 273 | |
Guobin Huang | 7dad7d0 | 2021-04-06 20:02:57 +0800 | [diff] [blame] | 274 | static DEFINE_SPINLOCK(desc_lock); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 275 | static struct crypt_ctl *get_crypt_desc(void) |
| 276 | { |
| 277 | int i; |
Corentin Labbe | 87d11a5 | 2021-05-05 20:26:14 +0000 | [diff] [blame^] | 278 | static int idx; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 279 | unsigned long flags; |
| 280 | |
| 281 | spin_lock_irqsave(&desc_lock, flags); |
| 282 | |
| 283 | if (unlikely(!crypt_virt)) |
| 284 | setup_crypt_desc(); |
| 285 | if (unlikely(!crypt_virt)) { |
| 286 | spin_unlock_irqrestore(&desc_lock, flags); |
| 287 | return NULL; |
| 288 | } |
| 289 | i = idx; |
| 290 | if (crypt_virt[i].ctl_flags == CTL_FLAG_UNUSED) { |
| 291 | if (++idx >= NPE_QLEN) |
| 292 | idx = 0; |
| 293 | crypt_virt[i].ctl_flags = CTL_FLAG_USED; |
| 294 | spin_unlock_irqrestore(&desc_lock, flags); |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 295 | return crypt_virt + i; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 296 | } else { |
| 297 | spin_unlock_irqrestore(&desc_lock, flags); |
| 298 | return NULL; |
| 299 | } |
| 300 | } |
| 301 | |
Guobin Huang | 7dad7d0 | 2021-04-06 20:02:57 +0800 | [diff] [blame] | 302 | static DEFINE_SPINLOCK(emerg_lock); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 303 | static struct crypt_ctl *get_crypt_desc_emerg(void) |
| 304 | { |
| 305 | int i; |
| 306 | static int idx = NPE_QLEN; |
| 307 | struct crypt_ctl *desc; |
| 308 | unsigned long flags; |
| 309 | |
| 310 | desc = get_crypt_desc(); |
| 311 | if (desc) |
| 312 | return desc; |
| 313 | if (unlikely(!crypt_virt)) |
| 314 | return NULL; |
| 315 | |
| 316 | spin_lock_irqsave(&emerg_lock, flags); |
| 317 | i = idx; |
| 318 | if (crypt_virt[i].ctl_flags == CTL_FLAG_UNUSED) { |
| 319 | if (++idx >= NPE_QLEN_TOTAL) |
| 320 | idx = NPE_QLEN; |
| 321 | crypt_virt[i].ctl_flags = CTL_FLAG_USED; |
| 322 | spin_unlock_irqrestore(&emerg_lock, flags); |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 323 | return crypt_virt + i; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 324 | } else { |
| 325 | spin_unlock_irqrestore(&emerg_lock, flags); |
| 326 | return NULL; |
| 327 | } |
| 328 | } |
| 329 | |
Herbert Xu | ff455ad9 | 2019-05-23 14:35:30 +0800 | [diff] [blame] | 330 | static void free_buf_chain(struct device *dev, struct buffer_desc *buf, |
| 331 | dma_addr_t phys) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 332 | { |
| 333 | while (buf) { |
| 334 | struct buffer_desc *buf1; |
| 335 | u32 phys1; |
| 336 | |
| 337 | buf1 = buf->next; |
| 338 | phys1 = buf->phys_next; |
Corentin Labbe | 9395c58 | 2021-05-05 20:26:08 +0000 | [diff] [blame] | 339 | dma_unmap_single(dev, buf->phys_addr, buf->buf_len, buf->dir); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 340 | dma_pool_free(buffer_pool, buf, phys); |
| 341 | buf = buf1; |
| 342 | phys = phys1; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | static struct tasklet_struct crypto_done_tasklet; |
| 347 | |
| 348 | static void finish_scattered_hmac(struct crypt_ctl *crypt) |
| 349 | { |
| 350 | struct aead_request *req = crypt->data.aead_req; |
| 351 | struct aead_ctx *req_ctx = aead_request_ctx(req); |
| 352 | struct crypto_aead *tfm = crypto_aead_reqtfm(req); |
| 353 | int authsize = crypto_aead_authsize(tfm); |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 354 | int decryptlen = req->assoclen + req->cryptlen - authsize; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 355 | |
| 356 | if (req_ctx->encrypt) { |
| 357 | scatterwalk_map_and_copy(req_ctx->hmac_virt, |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 358 | req->dst, decryptlen, authsize, 1); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 359 | } |
| 360 | dma_pool_free(buffer_pool, req_ctx->hmac_virt, crypt->icv_rev_aes); |
| 361 | } |
| 362 | |
| 363 | static void one_packet(dma_addr_t phys) |
| 364 | { |
Russell King | 27c1789 | 2013-06-10 19:09:45 +0100 | [diff] [blame] | 365 | struct device *dev = &pdev->dev; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 366 | struct crypt_ctl *crypt; |
| 367 | struct ixp_ctx *ctx; |
| 368 | int failed; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 369 | |
| 370 | failed = phys & 0x1 ? -EBADMSG : 0; |
| 371 | phys &= ~0x3; |
| 372 | crypt = crypt_phys2virt(phys); |
| 373 | |
| 374 | switch (crypt->ctl_flags & CTL_FLAG_MASK) { |
| 375 | case CTL_FLAG_PERFORM_AEAD: { |
| 376 | struct aead_request *req = crypt->data.aead_req; |
| 377 | struct aead_ctx *req_ctx = aead_request_ctx(req); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 378 | |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 379 | free_buf_chain(dev, req_ctx->src, crypt->src_buf); |
| 380 | free_buf_chain(dev, req_ctx->dst, crypt->dst_buf); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 381 | if (req_ctx->hmac_virt) { |
| 382 | finish_scattered_hmac(crypt); |
| 383 | } |
| 384 | req->base.complete(&req->base, failed); |
| 385 | break; |
| 386 | } |
| 387 | case CTL_FLAG_PERFORM_ABLK: { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 388 | struct skcipher_request *req = crypt->data.ablk_req; |
| 389 | struct ablk_ctx *req_ctx = skcipher_request_ctx(req); |
Corentin Labbe | e8acf01 | 2021-05-05 20:26:09 +0000 | [diff] [blame] | 390 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
| 391 | unsigned int ivsize = crypto_skcipher_ivsize(tfm); |
| 392 | unsigned int offset; |
| 393 | |
| 394 | if (ivsize > 0) { |
| 395 | offset = req->cryptlen - ivsize; |
| 396 | if (req_ctx->encrypt) { |
| 397 | scatterwalk_map_and_copy(req->iv, req->dst, |
| 398 | offset, ivsize, 0); |
| 399 | } else { |
| 400 | memcpy(req->iv, req_ctx->iv, ivsize); |
| 401 | memzero_explicit(req_ctx->iv, ivsize); |
| 402 | } |
| 403 | } |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 404 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 405 | if (req_ctx->dst) { |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 406 | free_buf_chain(dev, req_ctx->dst, crypt->dst_buf); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 407 | } |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 408 | free_buf_chain(dev, req_ctx->src, crypt->src_buf); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 409 | req->base.complete(&req->base, failed); |
| 410 | break; |
| 411 | } |
| 412 | case CTL_FLAG_GEN_ICV: |
| 413 | ctx = crypto_tfm_ctx(crypt->data.tfm); |
| 414 | dma_pool_free(ctx_pool, crypt->regist_ptr, |
| 415 | crypt->regist_buf->phys_addr); |
| 416 | dma_pool_free(buffer_pool, crypt->regist_buf, crypt->src_buf); |
| 417 | if (atomic_dec_and_test(&ctx->configuring)) |
| 418 | complete(&ctx->completion); |
| 419 | break; |
| 420 | case CTL_FLAG_GEN_REVAES: |
| 421 | ctx = crypto_tfm_ctx(crypt->data.tfm); |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 422 | *(u32 *)ctx->decrypt.npe_ctx &= cpu_to_be32(~CIPH_ENCR); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 423 | if (atomic_dec_and_test(&ctx->configuring)) |
| 424 | complete(&ctx->completion); |
| 425 | break; |
| 426 | default: |
| 427 | BUG(); |
| 428 | } |
| 429 | crypt->ctl_flags = CTL_FLAG_UNUSED; |
| 430 | } |
| 431 | |
| 432 | static void irqhandler(void *_unused) |
| 433 | { |
| 434 | tasklet_schedule(&crypto_done_tasklet); |
| 435 | } |
| 436 | |
| 437 | static void crypto_done_action(unsigned long arg) |
| 438 | { |
| 439 | int i; |
| 440 | |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 441 | for (i = 0; i < 4; i++) { |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 442 | dma_addr_t phys = qmgr_get_entry(RECV_QID); |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 443 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 444 | if (!phys) |
| 445 | return; |
| 446 | one_packet(phys); |
| 447 | } |
| 448 | tasklet_schedule(&crypto_done_tasklet); |
| 449 | } |
| 450 | |
Russell King | 27c1789 | 2013-06-10 19:09:45 +0100 | [diff] [blame] | 451 | static int init_ixp_crypto(struct device *dev) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 452 | { |
| 453 | int ret = -ENODEV; |
Christian Hohnstaedt | 295c01f | 2009-04-12 13:01:44 +0800 | [diff] [blame] | 454 | u32 msg[2] = { 0, 0 }; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 455 | |
| 456 | if (! ( ~(*IXP4XX_EXP_CFG2) & (IXP4XX_FEATURE_HASH | |
| 457 | IXP4XX_FEATURE_AES | IXP4XX_FEATURE_DES))) { |
Corentin Labbe | f5b82be | 2021-05-05 20:26:12 +0000 | [diff] [blame] | 458 | dev_err(dev, "ixp_crypto: No HW crypto available\n"); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 459 | return ret; |
| 460 | } |
| 461 | npe_c = npe_request(NPE_ID); |
| 462 | if (!npe_c) |
| 463 | return ret; |
| 464 | |
| 465 | if (!npe_running(npe_c)) { |
Christian Hohnstaedt | 295c01f | 2009-04-12 13:01:44 +0800 | [diff] [blame] | 466 | ret = npe_load_firmware(npe_c, npe_name(npe_c), dev); |
Quentin Lambert | b363700 | 2016-07-22 15:32:42 +0200 | [diff] [blame] | 467 | if (ret) |
Quentin Lambert | c5736a4 | 2016-07-22 15:32:41 +0200 | [diff] [blame] | 468 | goto npe_release; |
Christian Hohnstaedt | 295c01f | 2009-04-12 13:01:44 +0800 | [diff] [blame] | 469 | if (npe_recv_message(npe_c, msg, "STATUS_MSG")) |
| 470 | goto npe_error; |
| 471 | } else { |
| 472 | if (npe_send_message(npe_c, msg, "STATUS_MSG")) |
| 473 | goto npe_error; |
| 474 | |
| 475 | if (npe_recv_message(npe_c, msg, "STATUS_MSG")) |
| 476 | goto npe_error; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 477 | } |
| 478 | |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 479 | switch ((msg[1] >> 16) & 0xff) { |
Christian Hohnstaedt | 295c01f | 2009-04-12 13:01:44 +0800 | [diff] [blame] | 480 | case 3: |
Corentin Labbe | f5b82be | 2021-05-05 20:26:12 +0000 | [diff] [blame] | 481 | dev_warn(dev, "Firmware of %s lacks AES support\n", npe_name(npe_c)); |
Christian Hohnstaedt | 295c01f | 2009-04-12 13:01:44 +0800 | [diff] [blame] | 482 | support_aes = 0; |
| 483 | break; |
| 484 | case 4: |
| 485 | case 5: |
| 486 | support_aes = 1; |
| 487 | break; |
| 488 | default: |
Corentin Labbe | f5b82be | 2021-05-05 20:26:12 +0000 | [diff] [blame] | 489 | dev_err(dev, "Firmware of %s lacks crypto support\n", npe_name(npe_c)); |
Quentin Lambert | c5736a4 | 2016-07-22 15:32:41 +0200 | [diff] [blame] | 490 | ret = -ENODEV; |
| 491 | goto npe_release; |
Christian Hohnstaedt | 295c01f | 2009-04-12 13:01:44 +0800 | [diff] [blame] | 492 | } |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 493 | /* buffer_pool will also be used to sometimes store the hmac, |
| 494 | * so assure it is large enough |
| 495 | */ |
| 496 | BUILD_BUG_ON(SHA1_DIGEST_SIZE > sizeof(struct buffer_desc)); |
| 497 | buffer_pool = dma_pool_create("buffer", dev, |
| 498 | sizeof(struct buffer_desc), 32, 0); |
| 499 | ret = -ENOMEM; |
| 500 | if (!buffer_pool) { |
| 501 | goto err; |
| 502 | } |
| 503 | ctx_pool = dma_pool_create("context", dev, |
| 504 | NPE_CTX_LEN, 16, 0); |
| 505 | if (!ctx_pool) { |
| 506 | goto err; |
| 507 | } |
Krzysztof Hałasa | 1777f1a | 2009-03-04 08:01:22 +0800 | [diff] [blame] | 508 | ret = qmgr_request_queue(SEND_QID, NPE_QLEN_TOTAL, 0, 0, |
| 509 | "ixp_crypto:out", NULL); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 510 | if (ret) |
| 511 | goto err; |
Krzysztof Hałasa | 1777f1a | 2009-03-04 08:01:22 +0800 | [diff] [blame] | 512 | ret = qmgr_request_queue(RECV_QID, NPE_QLEN, 0, 0, |
| 513 | "ixp_crypto:in", NULL); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 514 | if (ret) { |
| 515 | qmgr_release_queue(SEND_QID); |
| 516 | goto err; |
| 517 | } |
| 518 | qmgr_set_irq(RECV_QID, QUEUE_IRQ_SRC_NOT_EMPTY, irqhandler, NULL); |
| 519 | tasklet_init(&crypto_done_tasklet, crypto_done_action, 0); |
| 520 | |
| 521 | qmgr_enable_irq(RECV_QID); |
| 522 | return 0; |
Christian Hohnstaedt | 295c01f | 2009-04-12 13:01:44 +0800 | [diff] [blame] | 523 | |
| 524 | npe_error: |
Corentin Labbe | f5b82be | 2021-05-05 20:26:12 +0000 | [diff] [blame] | 525 | dev_err(dev, "%s not responding\n", npe_name(npe_c)); |
Christian Hohnstaedt | 295c01f | 2009-04-12 13:01:44 +0800 | [diff] [blame] | 526 | ret = -EIO; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 527 | err: |
Markus Elfring | f9d1293 | 2015-11-15 16:51:21 +0100 | [diff] [blame] | 528 | dma_pool_destroy(ctx_pool); |
| 529 | dma_pool_destroy(buffer_pool); |
Quentin Lambert | c5736a4 | 2016-07-22 15:32:41 +0200 | [diff] [blame] | 530 | npe_release: |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 531 | npe_release(npe_c); |
| 532 | return ret; |
| 533 | } |
| 534 | |
Russell King | 27c1789 | 2013-06-10 19:09:45 +0100 | [diff] [blame] | 535 | static void release_ixp_crypto(struct device *dev) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 536 | { |
| 537 | qmgr_disable_irq(RECV_QID); |
| 538 | tasklet_kill(&crypto_done_tasklet); |
| 539 | |
| 540 | qmgr_release_queue(SEND_QID); |
| 541 | qmgr_release_queue(RECV_QID); |
| 542 | |
| 543 | dma_pool_destroy(ctx_pool); |
| 544 | dma_pool_destroy(buffer_pool); |
| 545 | |
| 546 | npe_release(npe_c); |
| 547 | |
| 548 | if (crypt_virt) { |
| 549 | dma_free_coherent(dev, |
Christophe JAILLET | f7ade9a | 2020-08-02 16:56:48 +0200 | [diff] [blame] | 550 | NPE_QLEN * sizeof(struct crypt_ctl), |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 551 | crypt_virt, crypt_phys); |
| 552 | } |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | static void reset_sa_dir(struct ix_sa_dir *dir) |
| 556 | { |
| 557 | memset(dir->npe_ctx, 0, NPE_CTX_LEN); |
| 558 | dir->npe_ctx_idx = 0; |
| 559 | dir->npe_mode = 0; |
| 560 | } |
| 561 | |
| 562 | static int init_sa_dir(struct ix_sa_dir *dir) |
| 563 | { |
| 564 | dir->npe_ctx = dma_pool_alloc(ctx_pool, GFP_KERNEL, &dir->npe_ctx_phys); |
| 565 | if (!dir->npe_ctx) { |
| 566 | return -ENOMEM; |
| 567 | } |
| 568 | reset_sa_dir(dir); |
| 569 | return 0; |
| 570 | } |
| 571 | |
| 572 | static void free_sa_dir(struct ix_sa_dir *dir) |
| 573 | { |
| 574 | memset(dir->npe_ctx, 0, NPE_CTX_LEN); |
| 575 | dma_pool_free(ctx_pool, dir->npe_ctx, dir->npe_ctx_phys); |
| 576 | } |
| 577 | |
| 578 | static int init_tfm(struct crypto_tfm *tfm) |
| 579 | { |
| 580 | struct ixp_ctx *ctx = crypto_tfm_ctx(tfm); |
| 581 | int ret; |
| 582 | |
| 583 | atomic_set(&ctx->configuring, 0); |
| 584 | ret = init_sa_dir(&ctx->encrypt); |
| 585 | if (ret) |
| 586 | return ret; |
| 587 | ret = init_sa_dir(&ctx->decrypt); |
| 588 | if (ret) { |
| 589 | free_sa_dir(&ctx->encrypt); |
| 590 | } |
| 591 | return ret; |
| 592 | } |
| 593 | |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 594 | static int init_tfm_ablk(struct crypto_skcipher *tfm) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 595 | { |
Corentin Labbe | dfb098d | 2021-05-05 20:26:10 +0000 | [diff] [blame] | 596 | struct crypto_tfm *ctfm = crypto_skcipher_tfm(tfm); |
| 597 | struct ixp_ctx *ctx = crypto_tfm_ctx(ctfm); |
| 598 | const char *name = crypto_tfm_alg_name(ctfm); |
| 599 | |
| 600 | ctx->fallback_tfm = crypto_alloc_skcipher(name, 0, CRYPTO_ALG_NEED_FALLBACK); |
| 601 | if (IS_ERR(ctx->fallback_tfm)) { |
| 602 | pr_err("ERROR: Cannot allocate fallback for %s %ld\n", |
| 603 | name, PTR_ERR(ctx->fallback_tfm)); |
| 604 | return PTR_ERR(ctx->fallback_tfm); |
| 605 | } |
| 606 | |
| 607 | pr_info("Fallback for %s is %s\n", |
| 608 | crypto_tfm_alg_driver_name(&tfm->base), |
| 609 | crypto_tfm_alg_driver_name(crypto_skcipher_tfm(ctx->fallback_tfm)) |
| 610 | ); |
| 611 | |
| 612 | crypto_skcipher_set_reqsize(tfm, sizeof(struct ablk_ctx) + crypto_skcipher_reqsize(ctx->fallback_tfm)); |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 613 | return init_tfm(crypto_skcipher_tfm(tfm)); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 614 | } |
| 615 | |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 616 | static int init_tfm_aead(struct crypto_aead *tfm) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 617 | { |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 618 | crypto_aead_set_reqsize(tfm, sizeof(struct aead_ctx)); |
| 619 | return init_tfm(crypto_aead_tfm(tfm)); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | static void exit_tfm(struct crypto_tfm *tfm) |
| 623 | { |
| 624 | struct ixp_ctx *ctx = crypto_tfm_ctx(tfm); |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 625 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 626 | free_sa_dir(&ctx->encrypt); |
| 627 | free_sa_dir(&ctx->decrypt); |
| 628 | } |
| 629 | |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 630 | static void exit_tfm_ablk(struct crypto_skcipher *tfm) |
| 631 | { |
Corentin Labbe | dfb098d | 2021-05-05 20:26:10 +0000 | [diff] [blame] | 632 | struct crypto_tfm *ctfm = crypto_skcipher_tfm(tfm); |
| 633 | struct ixp_ctx *ctx = crypto_tfm_ctx(ctfm); |
| 634 | |
| 635 | crypto_free_skcipher(ctx->fallback_tfm); |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 636 | exit_tfm(crypto_skcipher_tfm(tfm)); |
| 637 | } |
| 638 | |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 639 | static void exit_tfm_aead(struct crypto_aead *tfm) |
| 640 | { |
| 641 | exit_tfm(crypto_aead_tfm(tfm)); |
| 642 | } |
| 643 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 644 | static int register_chain_var(struct crypto_tfm *tfm, u8 xpad, u32 target, |
| 645 | int init_len, u32 ctx_addr, const u8 *key, int key_len) |
| 646 | { |
| 647 | struct ixp_ctx *ctx = crypto_tfm_ctx(tfm); |
| 648 | struct crypt_ctl *crypt; |
| 649 | struct buffer_desc *buf; |
| 650 | int i; |
| 651 | u8 *pad; |
Herbert Xu | ff455ad9 | 2019-05-23 14:35:30 +0800 | [diff] [blame] | 652 | dma_addr_t pad_phys, buf_phys; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 653 | |
| 654 | BUILD_BUG_ON(NPE_CTX_LEN < HMAC_PAD_BLOCKLEN); |
| 655 | pad = dma_pool_alloc(ctx_pool, GFP_KERNEL, &pad_phys); |
| 656 | if (!pad) |
| 657 | return -ENOMEM; |
| 658 | buf = dma_pool_alloc(buffer_pool, GFP_KERNEL, &buf_phys); |
| 659 | if (!buf) { |
| 660 | dma_pool_free(ctx_pool, pad, pad_phys); |
| 661 | return -ENOMEM; |
| 662 | } |
| 663 | crypt = get_crypt_desc_emerg(); |
| 664 | if (!crypt) { |
| 665 | dma_pool_free(ctx_pool, pad, pad_phys); |
| 666 | dma_pool_free(buffer_pool, buf, buf_phys); |
| 667 | return -EAGAIN; |
| 668 | } |
| 669 | |
| 670 | memcpy(pad, key, key_len); |
| 671 | memset(pad + key_len, 0, HMAC_PAD_BLOCKLEN - key_len); |
| 672 | for (i = 0; i < HMAC_PAD_BLOCKLEN; i++) { |
| 673 | pad[i] ^= xpad; |
| 674 | } |
| 675 | |
| 676 | crypt->data.tfm = tfm; |
| 677 | crypt->regist_ptr = pad; |
| 678 | crypt->regist_buf = buf; |
| 679 | |
| 680 | crypt->auth_offs = 0; |
| 681 | crypt->auth_len = HMAC_PAD_BLOCKLEN; |
| 682 | crypt->crypto_ctx = ctx_addr; |
| 683 | crypt->src_buf = buf_phys; |
| 684 | crypt->icv_rev_aes = target; |
| 685 | crypt->mode = NPE_OP_HASH_GEN_ICV; |
| 686 | crypt->init_len = init_len; |
| 687 | crypt->ctl_flags |= CTL_FLAG_GEN_ICV; |
| 688 | |
| 689 | buf->next = 0; |
| 690 | buf->buf_len = HMAC_PAD_BLOCKLEN; |
| 691 | buf->pkt_len = 0; |
| 692 | buf->phys_addr = pad_phys; |
| 693 | |
| 694 | atomic_inc(&ctx->configuring); |
| 695 | qmgr_put_entry(SEND_QID, crypt_virt2phys(crypt)); |
| 696 | BUG_ON(qmgr_stat_overflow(SEND_QID)); |
| 697 | return 0; |
| 698 | } |
| 699 | |
Corentin Labbe | 3557084 | 2021-05-05 20:26:11 +0000 | [diff] [blame] | 700 | static int setup_auth(struct crypto_tfm *tfm, int encrypt, unsigned int authsize, |
| 701 | const u8 *key, int key_len, unsigned int digest_len) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 702 | { |
| 703 | u32 itarget, otarget, npe_ctx_addr; |
| 704 | unsigned char *cinfo; |
| 705 | int init_len, ret = 0; |
| 706 | u32 cfgword; |
| 707 | struct ix_sa_dir *dir; |
| 708 | struct ixp_ctx *ctx = crypto_tfm_ctx(tfm); |
| 709 | const struct ix_hash_algo *algo; |
| 710 | |
| 711 | dir = encrypt ? &ctx->encrypt : &ctx->decrypt; |
| 712 | cinfo = dir->npe_ctx + dir->npe_ctx_idx; |
| 713 | algo = ix_hash(tfm); |
| 714 | |
| 715 | /* write cfg word to cryptinfo */ |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 716 | cfgword = algo->cfgword | (authsize << 6); /* (authsize/4) << 8 */ |
Krzysztof Hałasa | ce05729 | 2010-01-10 14:20:10 +0100 | [diff] [blame] | 717 | #ifndef __ARMEB__ |
| 718 | cfgword ^= 0xAA000000; /* change the "byte swap" flags */ |
| 719 | #endif |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 720 | *(u32 *)cinfo = cpu_to_be32(cfgword); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 721 | cinfo += sizeof(cfgword); |
| 722 | |
| 723 | /* write ICV to cryptinfo */ |
| 724 | memcpy(cinfo, algo->icv, digest_len); |
| 725 | cinfo += digest_len; |
| 726 | |
| 727 | itarget = dir->npe_ctx_phys + dir->npe_ctx_idx |
| 728 | + sizeof(algo->cfgword); |
| 729 | otarget = itarget + digest_len; |
| 730 | init_len = cinfo - (dir->npe_ctx + dir->npe_ctx_idx); |
| 731 | npe_ctx_addr = dir->npe_ctx_phys + dir->npe_ctx_idx; |
| 732 | |
| 733 | dir->npe_ctx_idx += init_len; |
| 734 | dir->npe_mode |= NPE_OP_HASH_ENABLE; |
| 735 | |
| 736 | if (!encrypt) |
| 737 | dir->npe_mode |= NPE_OP_HASH_VERIFY; |
| 738 | |
| 739 | ret = register_chain_var(tfm, HMAC_OPAD_VALUE, otarget, |
| 740 | init_len, npe_ctx_addr, key, key_len); |
| 741 | if (ret) |
| 742 | return ret; |
| 743 | return register_chain_var(tfm, HMAC_IPAD_VALUE, itarget, |
| 744 | init_len, npe_ctx_addr, key, key_len); |
| 745 | } |
| 746 | |
| 747 | static int gen_rev_aes_key(struct crypto_tfm *tfm) |
| 748 | { |
| 749 | struct crypt_ctl *crypt; |
| 750 | struct ixp_ctx *ctx = crypto_tfm_ctx(tfm); |
| 751 | struct ix_sa_dir *dir = &ctx->decrypt; |
| 752 | |
| 753 | crypt = get_crypt_desc_emerg(); |
| 754 | if (!crypt) { |
| 755 | return -EAGAIN; |
| 756 | } |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 757 | *(u32 *)dir->npe_ctx |= cpu_to_be32(CIPH_ENCR); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 758 | |
| 759 | crypt->data.tfm = tfm; |
| 760 | crypt->crypt_offs = 0; |
| 761 | crypt->crypt_len = AES_BLOCK128; |
| 762 | crypt->src_buf = 0; |
| 763 | crypt->crypto_ctx = dir->npe_ctx_phys; |
| 764 | crypt->icv_rev_aes = dir->npe_ctx_phys + sizeof(u32); |
| 765 | crypt->mode = NPE_OP_ENC_GEN_KEY; |
| 766 | crypt->init_len = dir->npe_ctx_idx; |
| 767 | crypt->ctl_flags |= CTL_FLAG_GEN_REVAES; |
| 768 | |
| 769 | atomic_inc(&ctx->configuring); |
| 770 | qmgr_put_entry(SEND_QID, crypt_virt2phys(crypt)); |
| 771 | BUG_ON(qmgr_stat_overflow(SEND_QID)); |
| 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | static int setup_cipher(struct crypto_tfm *tfm, int encrypt, |
| 776 | const u8 *key, int key_len) |
| 777 | { |
| 778 | u8 *cinfo; |
| 779 | u32 cipher_cfg; |
| 780 | u32 keylen_cfg = 0; |
| 781 | struct ix_sa_dir *dir; |
| 782 | struct ixp_ctx *ctx = crypto_tfm_ctx(tfm); |
Eric Biggers | c4c4db0 | 2019-12-30 21:19:37 -0600 | [diff] [blame] | 783 | int err; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 784 | |
| 785 | dir = encrypt ? &ctx->encrypt : &ctx->decrypt; |
| 786 | cinfo = dir->npe_ctx; |
| 787 | |
| 788 | if (encrypt) { |
| 789 | cipher_cfg = cipher_cfg_enc(tfm); |
| 790 | dir->npe_mode |= NPE_OP_CRYPT_ENCRYPT; |
| 791 | } else { |
| 792 | cipher_cfg = cipher_cfg_dec(tfm); |
| 793 | } |
| 794 | if (cipher_cfg & MOD_AES) { |
| 795 | switch (key_len) { |
Krzysztof Hałasa | 9792eb1 | 2010-12-28 13:08:18 +0100 | [diff] [blame] | 796 | case 16: keylen_cfg = MOD_AES128; break; |
| 797 | case 24: keylen_cfg = MOD_AES192; break; |
| 798 | case 32: keylen_cfg = MOD_AES256; break; |
| 799 | default: |
Krzysztof Hałasa | 9792eb1 | 2010-12-28 13:08:18 +0100 | [diff] [blame] | 800 | return -EINVAL; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 801 | } |
| 802 | cipher_cfg |= keylen_cfg; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 803 | } else { |
Eric Biggers | c4c4db0 | 2019-12-30 21:19:37 -0600 | [diff] [blame] | 804 | err = crypto_des_verify_key(tfm, key); |
| 805 | if (err) |
| 806 | return err; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 807 | } |
| 808 | /* write cfg word to cryptinfo */ |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 809 | *(u32 *)cinfo = cpu_to_be32(cipher_cfg); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 810 | cinfo += sizeof(cipher_cfg); |
| 811 | |
| 812 | /* write cipher key to cryptinfo */ |
| 813 | memcpy(cinfo, key, key_len); |
| 814 | /* NPE wants keylen set to DES3_EDE_KEY_SIZE even for single DES */ |
| 815 | if (key_len < DES3_EDE_KEY_SIZE && !(cipher_cfg & MOD_AES)) { |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 816 | memset(cinfo + key_len, 0, DES3_EDE_KEY_SIZE - key_len); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 817 | key_len = DES3_EDE_KEY_SIZE; |
| 818 | } |
| 819 | dir->npe_ctx_idx = sizeof(cipher_cfg) + key_len; |
| 820 | dir->npe_mode |= NPE_OP_CRYPT_ENABLE; |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 821 | if ((cipher_cfg & MOD_AES) && !encrypt) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 822 | return gen_rev_aes_key(tfm); |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 823 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 824 | return 0; |
| 825 | } |
| 826 | |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 827 | static struct buffer_desc *chainup_buffers(struct device *dev, |
Corentin Labbe | 3557084 | 2021-05-05 20:26:11 +0000 | [diff] [blame] | 828 | struct scatterlist *sg, unsigned int nbytes, |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 829 | struct buffer_desc *buf, gfp_t flags, |
| 830 | enum dma_data_direction dir) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 831 | { |
Cristian Stoica | 5be4d4c | 2015-01-20 10:06:16 +0200 | [diff] [blame] | 832 | for (; nbytes > 0; sg = sg_next(sg)) { |
Corentin Labbe | 3557084 | 2021-05-05 20:26:11 +0000 | [diff] [blame] | 833 | unsigned int len = min(nbytes, sg->length); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 834 | struct buffer_desc *next_buf; |
Herbert Xu | ff455ad9 | 2019-05-23 14:35:30 +0800 | [diff] [blame] | 835 | dma_addr_t next_buf_phys; |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 836 | void *ptr; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 837 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 838 | nbytes -= len; |
Geliang Tang | 796b40c | 2017-03-23 21:16:30 +0800 | [diff] [blame] | 839 | ptr = sg_virt(sg); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 840 | next_buf = dma_pool_alloc(buffer_pool, flags, &next_buf_phys); |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 841 | if (!next_buf) { |
| 842 | buf = NULL; |
| 843 | break; |
| 844 | } |
| 845 | sg_dma_address(sg) = dma_map_single(dev, ptr, len, dir); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 846 | buf->next = next_buf; |
| 847 | buf->phys_next = next_buf_phys; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 848 | buf = next_buf; |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 849 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 850 | buf->phys_addr = sg_dma_address(sg); |
| 851 | buf->buf_len = len; |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 852 | buf->dir = dir; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 853 | } |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 854 | buf->next = NULL; |
| 855 | buf->phys_next = 0; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 856 | return buf; |
| 857 | } |
| 858 | |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 859 | static int ablk_setkey(struct crypto_skcipher *tfm, const u8 *key, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 860 | unsigned int key_len) |
| 861 | { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 862 | struct ixp_ctx *ctx = crypto_skcipher_ctx(tfm); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 863 | int ret; |
| 864 | |
| 865 | init_completion(&ctx->completion); |
| 866 | atomic_inc(&ctx->configuring); |
| 867 | |
| 868 | reset_sa_dir(&ctx->encrypt); |
| 869 | reset_sa_dir(&ctx->decrypt); |
| 870 | |
| 871 | ctx->encrypt.npe_mode = NPE_OP_HMAC_DISABLE; |
| 872 | ctx->decrypt.npe_mode = NPE_OP_HMAC_DISABLE; |
| 873 | |
| 874 | ret = setup_cipher(&tfm->base, 0, key, key_len); |
| 875 | if (ret) |
| 876 | goto out; |
| 877 | ret = setup_cipher(&tfm->base, 1, key, key_len); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 878 | out: |
| 879 | if (!atomic_dec_and_test(&ctx->configuring)) |
| 880 | wait_for_completion(&ctx->completion); |
Corentin Labbe | dfb098d | 2021-05-05 20:26:10 +0000 | [diff] [blame] | 881 | if (ret) |
| 882 | return ret; |
| 883 | crypto_skcipher_clear_flags(ctx->fallback_tfm, CRYPTO_TFM_REQ_MASK); |
| 884 | crypto_skcipher_set_flags(ctx->fallback_tfm, tfm->base.crt_flags & CRYPTO_TFM_REQ_MASK); |
| 885 | |
| 886 | return crypto_skcipher_setkey(ctx->fallback_tfm, key, key_len); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 887 | } |
| 888 | |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 889 | static int ablk_des3_setkey(struct crypto_skcipher *tfm, const u8 *key, |
Herbert Xu | dba434a | 2019-04-11 16:51:11 +0800 | [diff] [blame] | 890 | unsigned int key_len) |
| 891 | { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 892 | return verify_skcipher_des3_key(tfm, key) ?: |
Ard Biesheuvel | 3ca20b6 | 2019-08-15 12:00:56 +0300 | [diff] [blame] | 893 | ablk_setkey(tfm, key, key_len); |
Herbert Xu | dba434a | 2019-04-11 16:51:11 +0800 | [diff] [blame] | 894 | } |
| 895 | |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 896 | static int ablk_rfc3686_setkey(struct crypto_skcipher *tfm, const u8 *key, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 897 | unsigned int key_len) |
| 898 | { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 899 | struct ixp_ctx *ctx = crypto_skcipher_ctx(tfm); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 900 | |
| 901 | /* the nonce is stored in bytes at end of key */ |
| 902 | if (key_len < CTR_RFC3686_NONCE_SIZE) |
| 903 | return -EINVAL; |
| 904 | |
| 905 | memcpy(ctx->nonce, key + (key_len - CTR_RFC3686_NONCE_SIZE), |
| 906 | CTR_RFC3686_NONCE_SIZE); |
| 907 | |
| 908 | key_len -= CTR_RFC3686_NONCE_SIZE; |
| 909 | return ablk_setkey(tfm, key, key_len); |
| 910 | } |
| 911 | |
Corentin Labbe | dfb098d | 2021-05-05 20:26:10 +0000 | [diff] [blame] | 912 | static int ixp4xx_cipher_fallback(struct skcipher_request *areq, int encrypt) |
| 913 | { |
| 914 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); |
| 915 | struct ixp_ctx *op = crypto_skcipher_ctx(tfm); |
| 916 | struct ablk_ctx *rctx = skcipher_request_ctx(areq); |
| 917 | int err; |
| 918 | |
| 919 | skcipher_request_set_tfm(&rctx->fallback_req, op->fallback_tfm); |
| 920 | skcipher_request_set_callback(&rctx->fallback_req, areq->base.flags, |
| 921 | areq->base.complete, areq->base.data); |
| 922 | skcipher_request_set_crypt(&rctx->fallback_req, areq->src, areq->dst, |
| 923 | areq->cryptlen, areq->iv); |
| 924 | if (encrypt) |
| 925 | err = crypto_skcipher_encrypt(&rctx->fallback_req); |
| 926 | else |
| 927 | err = crypto_skcipher_decrypt(&rctx->fallback_req); |
| 928 | return err; |
| 929 | } |
| 930 | |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 931 | static int ablk_perform(struct skcipher_request *req, int encrypt) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 932 | { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 933 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
| 934 | struct ixp_ctx *ctx = crypto_skcipher_ctx(tfm); |
Corentin Labbe | 3557084 | 2021-05-05 20:26:11 +0000 | [diff] [blame] | 935 | unsigned int ivsize = crypto_skcipher_ivsize(tfm); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 936 | struct ix_sa_dir *dir; |
| 937 | struct crypt_ctl *crypt; |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 938 | unsigned int nbytes = req->cryptlen; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 939 | enum dma_data_direction src_direction = DMA_BIDIRECTIONAL; |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 940 | struct ablk_ctx *req_ctx = skcipher_request_ctx(req); |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 941 | struct buffer_desc src_hook; |
Russell King | 27c1789 | 2013-06-10 19:09:45 +0100 | [diff] [blame] | 942 | struct device *dev = &pdev->dev; |
Corentin Labbe | e8acf01 | 2021-05-05 20:26:09 +0000 | [diff] [blame] | 943 | unsigned int offset; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 944 | gfp_t flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ? |
| 945 | GFP_KERNEL : GFP_ATOMIC; |
| 946 | |
Corentin Labbe | dfb098d | 2021-05-05 20:26:10 +0000 | [diff] [blame] | 947 | if (sg_nents(req->src) > 1 || sg_nents(req->dst) > 1) |
| 948 | return ixp4xx_cipher_fallback(req, encrypt); |
| 949 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 950 | if (qmgr_stat_full(SEND_QID)) |
| 951 | return -EAGAIN; |
| 952 | if (atomic_read(&ctx->configuring)) |
| 953 | return -EAGAIN; |
| 954 | |
| 955 | dir = encrypt ? &ctx->encrypt : &ctx->decrypt; |
Corentin Labbe | e8acf01 | 2021-05-05 20:26:09 +0000 | [diff] [blame] | 956 | req_ctx->encrypt = encrypt; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 957 | |
| 958 | crypt = get_crypt_desc(); |
| 959 | if (!crypt) |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 960 | return -ENOMEM; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 961 | |
| 962 | crypt->data.ablk_req = req; |
| 963 | crypt->crypto_ctx = dir->npe_ctx_phys; |
| 964 | crypt->mode = dir->npe_mode; |
| 965 | crypt->init_len = dir->npe_ctx_idx; |
| 966 | |
| 967 | crypt->crypt_offs = 0; |
| 968 | crypt->crypt_len = nbytes; |
| 969 | |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 970 | BUG_ON(ivsize && !req->iv); |
| 971 | memcpy(crypt->iv, req->iv, ivsize); |
Corentin Labbe | e8acf01 | 2021-05-05 20:26:09 +0000 | [diff] [blame] | 972 | if (ivsize > 0 && !encrypt) { |
| 973 | offset = req->cryptlen - ivsize; |
| 974 | scatterwalk_map_and_copy(req_ctx->iv, req->src, offset, ivsize, 0); |
| 975 | } |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 976 | if (req->src != req->dst) { |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 977 | struct buffer_desc dst_hook; |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 978 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 979 | crypt->mode |= NPE_OP_NOT_IN_PLACE; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 980 | /* This was never tested by Intel |
| 981 | * for more than one dst buffer, I think. */ |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 982 | req_ctx->dst = NULL; |
| 983 | if (!chainup_buffers(dev, req->dst, nbytes, &dst_hook, |
| 984 | flags, DMA_FROM_DEVICE)) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 985 | goto free_buf_dest; |
| 986 | src_direction = DMA_TO_DEVICE; |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 987 | req_ctx->dst = dst_hook.next; |
| 988 | crypt->dst_buf = dst_hook.phys_next; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 989 | } else { |
| 990 | req_ctx->dst = NULL; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 991 | } |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 992 | req_ctx->src = NULL; |
| 993 | if (!chainup_buffers(dev, req->src, nbytes, &src_hook, |
| 994 | flags, src_direction)) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 995 | goto free_buf_src; |
| 996 | |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 997 | req_ctx->src = src_hook.next; |
| 998 | crypt->src_buf = src_hook.phys_next; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 999 | crypt->ctl_flags |= CTL_FLAG_PERFORM_ABLK; |
| 1000 | qmgr_put_entry(SEND_QID, crypt_virt2phys(crypt)); |
| 1001 | BUG_ON(qmgr_stat_overflow(SEND_QID)); |
| 1002 | return -EINPROGRESS; |
| 1003 | |
| 1004 | free_buf_src: |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 1005 | free_buf_chain(dev, req_ctx->src, crypt->src_buf); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1006 | free_buf_dest: |
| 1007 | if (req->src != req->dst) { |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 1008 | free_buf_chain(dev, req_ctx->dst, crypt->dst_buf); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1009 | } |
| 1010 | crypt->ctl_flags = CTL_FLAG_UNUSED; |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 1011 | return -ENOMEM; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1012 | } |
| 1013 | |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1014 | static int ablk_encrypt(struct skcipher_request *req) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1015 | { |
| 1016 | return ablk_perform(req, 1); |
| 1017 | } |
| 1018 | |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1019 | static int ablk_decrypt(struct skcipher_request *req) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1020 | { |
| 1021 | return ablk_perform(req, 0); |
| 1022 | } |
| 1023 | |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1024 | static int ablk_rfc3686_crypt(struct skcipher_request *req) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1025 | { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1026 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
| 1027 | struct ixp_ctx *ctx = crypto_skcipher_ctx(tfm); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1028 | u8 iv[CTR_RFC3686_BLOCK_SIZE]; |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1029 | u8 *info = req->iv; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1030 | int ret; |
| 1031 | |
| 1032 | /* set up counter block */ |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 1033 | memcpy(iv, ctx->nonce, CTR_RFC3686_NONCE_SIZE); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1034 | memcpy(iv + CTR_RFC3686_NONCE_SIZE, info, CTR_RFC3686_IV_SIZE); |
| 1035 | |
| 1036 | /* initialize counter portion of counter block */ |
| 1037 | *(__be32 *)(iv + CTR_RFC3686_NONCE_SIZE + CTR_RFC3686_IV_SIZE) = |
| 1038 | cpu_to_be32(1); |
| 1039 | |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1040 | req->iv = iv; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1041 | ret = ablk_perform(req, 1); |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1042 | req->iv = info; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1043 | return ret; |
| 1044 | } |
| 1045 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1046 | static int aead_perform(struct aead_request *req, int encrypt, |
| 1047 | int cryptoffset, int eff_cryptlen, u8 *iv) |
| 1048 | { |
| 1049 | struct crypto_aead *tfm = crypto_aead_reqtfm(req); |
| 1050 | struct ixp_ctx *ctx = crypto_aead_ctx(tfm); |
Corentin Labbe | 3557084 | 2021-05-05 20:26:11 +0000 | [diff] [blame] | 1051 | unsigned int ivsize = crypto_aead_ivsize(tfm); |
| 1052 | unsigned int authsize = crypto_aead_authsize(tfm); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1053 | struct ix_sa_dir *dir; |
| 1054 | struct crypt_ctl *crypt; |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 1055 | unsigned int cryptlen; |
| 1056 | struct buffer_desc *buf, src_hook; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1057 | struct aead_ctx *req_ctx = aead_request_ctx(req); |
Russell King | 27c1789 | 2013-06-10 19:09:45 +0100 | [diff] [blame] | 1058 | struct device *dev = &pdev->dev; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1059 | gfp_t flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ? |
| 1060 | GFP_KERNEL : GFP_ATOMIC; |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1061 | enum dma_data_direction src_direction = DMA_BIDIRECTIONAL; |
| 1062 | unsigned int lastlen; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1063 | |
| 1064 | if (qmgr_stat_full(SEND_QID)) |
| 1065 | return -EAGAIN; |
| 1066 | if (atomic_read(&ctx->configuring)) |
| 1067 | return -EAGAIN; |
| 1068 | |
| 1069 | if (encrypt) { |
| 1070 | dir = &ctx->encrypt; |
| 1071 | cryptlen = req->cryptlen; |
| 1072 | } else { |
| 1073 | dir = &ctx->decrypt; |
| 1074 | /* req->cryptlen includes the authsize when decrypting */ |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 1075 | cryptlen = req->cryptlen - authsize; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1076 | eff_cryptlen -= authsize; |
| 1077 | } |
| 1078 | crypt = get_crypt_desc(); |
| 1079 | if (!crypt) |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 1080 | return -ENOMEM; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1081 | |
| 1082 | crypt->data.aead_req = req; |
| 1083 | crypt->crypto_ctx = dir->npe_ctx_phys; |
| 1084 | crypt->mode = dir->npe_mode; |
| 1085 | crypt->init_len = dir->npe_ctx_idx; |
| 1086 | |
| 1087 | crypt->crypt_offs = cryptoffset; |
| 1088 | crypt->crypt_len = eff_cryptlen; |
| 1089 | |
| 1090 | crypt->auth_offs = 0; |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1091 | crypt->auth_len = req->assoclen + cryptlen; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1092 | BUG_ON(ivsize && !req->iv); |
| 1093 | memcpy(crypt->iv, req->iv, ivsize); |
| 1094 | |
Herbert Xu | 0f987e2 | 2016-01-19 09:00:21 +0800 | [diff] [blame] | 1095 | buf = chainup_buffers(dev, req->src, crypt->auth_len, |
| 1096 | &src_hook, flags, src_direction); |
| 1097 | req_ctx->src = src_hook.next; |
| 1098 | crypt->src_buf = src_hook.phys_next; |
| 1099 | if (!buf) |
| 1100 | goto free_buf_src; |
| 1101 | |
| 1102 | lastlen = buf->buf_len; |
| 1103 | if (lastlen >= authsize) |
| 1104 | crypt->icv_rev_aes = buf->phys_addr + |
| 1105 | buf->buf_len - authsize; |
| 1106 | |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1107 | req_ctx->dst = NULL; |
| 1108 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1109 | if (req->src != req->dst) { |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1110 | struct buffer_desc dst_hook; |
| 1111 | |
| 1112 | crypt->mode |= NPE_OP_NOT_IN_PLACE; |
| 1113 | src_direction = DMA_TO_DEVICE; |
| 1114 | |
| 1115 | buf = chainup_buffers(dev, req->dst, crypt->auth_len, |
| 1116 | &dst_hook, flags, DMA_FROM_DEVICE); |
| 1117 | req_ctx->dst = dst_hook.next; |
| 1118 | crypt->dst_buf = dst_hook.phys_next; |
| 1119 | |
| 1120 | if (!buf) |
| 1121 | goto free_buf_dst; |
| 1122 | |
| 1123 | if (encrypt) { |
| 1124 | lastlen = buf->buf_len; |
| 1125 | if (lastlen >= authsize) |
| 1126 | crypt->icv_rev_aes = buf->phys_addr + |
| 1127 | buf->buf_len - authsize; |
| 1128 | } |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1129 | } |
| 1130 | |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1131 | if (unlikely(lastlen < authsize)) { |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1132 | /* The 12 hmac bytes are scattered, |
| 1133 | * we need to copy them into a safe buffer */ |
| 1134 | req_ctx->hmac_virt = dma_pool_alloc(buffer_pool, flags, |
| 1135 | &crypt->icv_rev_aes); |
| 1136 | if (unlikely(!req_ctx->hmac_virt)) |
Herbert Xu | 2838957 | 2017-08-02 16:40:47 +0800 | [diff] [blame] | 1137 | goto free_buf_dst; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1138 | if (!encrypt) { |
| 1139 | scatterwalk_map_and_copy(req_ctx->hmac_virt, |
| 1140 | req->src, cryptlen, authsize, 0); |
| 1141 | } |
| 1142 | req_ctx->encrypt = encrypt; |
| 1143 | } else { |
| 1144 | req_ctx->hmac_virt = NULL; |
| 1145 | } |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 1146 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1147 | crypt->ctl_flags |= CTL_FLAG_PERFORM_AEAD; |
| 1148 | qmgr_put_entry(SEND_QID, crypt_virt2phys(crypt)); |
| 1149 | BUG_ON(qmgr_stat_overflow(SEND_QID)); |
| 1150 | return -EINPROGRESS; |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1151 | |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1152 | free_buf_dst: |
| 1153 | free_buf_chain(dev, req_ctx->dst, crypt->dst_buf); |
Herbert Xu | 2838957 | 2017-08-02 16:40:47 +0800 | [diff] [blame] | 1154 | free_buf_src: |
| 1155 | free_buf_chain(dev, req_ctx->src, crypt->src_buf); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1156 | crypt->ctl_flags = CTL_FLAG_UNUSED; |
Christian Hohnstaedt | 0d44dc5 | 2009-03-27 15:09:05 +0800 | [diff] [blame] | 1157 | return -ENOMEM; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | static int aead_setup(struct crypto_aead *tfm, unsigned int authsize) |
| 1161 | { |
| 1162 | struct ixp_ctx *ctx = crypto_aead_ctx(tfm); |
Corentin Labbe | 3557084 | 2021-05-05 20:26:11 +0000 | [diff] [blame] | 1163 | unsigned int digest_len = crypto_aead_maxauthsize(tfm); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1164 | int ret; |
| 1165 | |
| 1166 | if (!ctx->enckey_len && !ctx->authkey_len) |
| 1167 | return 0; |
| 1168 | init_completion(&ctx->completion); |
| 1169 | atomic_inc(&ctx->configuring); |
| 1170 | |
| 1171 | reset_sa_dir(&ctx->encrypt); |
| 1172 | reset_sa_dir(&ctx->decrypt); |
| 1173 | |
| 1174 | ret = setup_cipher(&tfm->base, 0, ctx->enckey, ctx->enckey_len); |
| 1175 | if (ret) |
| 1176 | goto out; |
| 1177 | ret = setup_cipher(&tfm->base, 1, ctx->enckey, ctx->enckey_len); |
| 1178 | if (ret) |
| 1179 | goto out; |
| 1180 | ret = setup_auth(&tfm->base, 0, authsize, ctx->authkey, |
| 1181 | ctx->authkey_len, digest_len); |
| 1182 | if (ret) |
| 1183 | goto out; |
| 1184 | ret = setup_auth(&tfm->base, 1, authsize, ctx->authkey, |
| 1185 | ctx->authkey_len, digest_len); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1186 | out: |
| 1187 | if (!atomic_dec_and_test(&ctx->configuring)) |
| 1188 | wait_for_completion(&ctx->completion); |
| 1189 | return ret; |
| 1190 | } |
| 1191 | |
| 1192 | static int aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize) |
| 1193 | { |
Herbert Xu | 6da9c23 | 2015-05-21 15:11:06 +0800 | [diff] [blame] | 1194 | int max = crypto_aead_maxauthsize(tfm) >> 2; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1195 | |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 1196 | if ((authsize >> 2) < 1 || (authsize >> 2) > max || (authsize & 3)) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1197 | return -EINVAL; |
| 1198 | return aead_setup(tfm, authsize); |
| 1199 | } |
| 1200 | |
| 1201 | static int aead_setkey(struct crypto_aead *tfm, const u8 *key, |
| 1202 | unsigned int keylen) |
| 1203 | { |
| 1204 | struct ixp_ctx *ctx = crypto_aead_ctx(tfm); |
Mathias Krause | 5690278 | 2013-10-15 13:49:32 +0200 | [diff] [blame] | 1205 | struct crypto_authenc_keys keys; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1206 | |
Mathias Krause | 5690278 | 2013-10-15 13:49:32 +0200 | [diff] [blame] | 1207 | if (crypto_authenc_extractkeys(&keys, key, keylen) != 0) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1208 | goto badkey; |
| 1209 | |
Mathias Krause | 5690278 | 2013-10-15 13:49:32 +0200 | [diff] [blame] | 1210 | if (keys.authkeylen > sizeof(ctx->authkey)) |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1211 | goto badkey; |
| 1212 | |
Mathias Krause | 5690278 | 2013-10-15 13:49:32 +0200 | [diff] [blame] | 1213 | if (keys.enckeylen > sizeof(ctx->enckey)) |
| 1214 | goto badkey; |
| 1215 | |
| 1216 | memcpy(ctx->authkey, keys.authkey, keys.authkeylen); |
| 1217 | memcpy(ctx->enckey, keys.enckey, keys.enckeylen); |
| 1218 | ctx->authkey_len = keys.authkeylen; |
| 1219 | ctx->enckey_len = keys.enckeylen; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1220 | |
Tudor-Dan Ambarus | 0e7da29 | 2018-03-23 12:42:21 +0200 | [diff] [blame] | 1221 | memzero_explicit(&keys, sizeof(keys)); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1222 | return aead_setup(tfm, crypto_aead_authsize(tfm)); |
| 1223 | badkey: |
Tudor-Dan Ambarus | 0e7da29 | 2018-03-23 12:42:21 +0200 | [diff] [blame] | 1224 | memzero_explicit(&keys, sizeof(keys)); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1225 | return -EINVAL; |
| 1226 | } |
| 1227 | |
Herbert Xu | dba434a | 2019-04-11 16:51:11 +0800 | [diff] [blame] | 1228 | static int des3_aead_setkey(struct crypto_aead *tfm, const u8 *key, |
| 1229 | unsigned int keylen) |
| 1230 | { |
| 1231 | struct ixp_ctx *ctx = crypto_aead_ctx(tfm); |
Herbert Xu | dba434a | 2019-04-11 16:51:11 +0800 | [diff] [blame] | 1232 | struct crypto_authenc_keys keys; |
| 1233 | int err; |
| 1234 | |
| 1235 | err = crypto_authenc_extractkeys(&keys, key, keylen); |
| 1236 | if (unlikely(err)) |
| 1237 | goto badkey; |
| 1238 | |
| 1239 | err = -EINVAL; |
| 1240 | if (keys.authkeylen > sizeof(ctx->authkey)) |
| 1241 | goto badkey; |
| 1242 | |
Ard Biesheuvel | 3ca20b6 | 2019-08-15 12:00:56 +0300 | [diff] [blame] | 1243 | err = verify_aead_des3_key(tfm, keys.enckey, keys.enckeylen); |
| 1244 | if (err) |
Herbert Xu | dba434a | 2019-04-11 16:51:11 +0800 | [diff] [blame] | 1245 | goto badkey; |
| 1246 | |
| 1247 | memcpy(ctx->authkey, keys.authkey, keys.authkeylen); |
| 1248 | memcpy(ctx->enckey, keys.enckey, keys.enckeylen); |
| 1249 | ctx->authkey_len = keys.authkeylen; |
| 1250 | ctx->enckey_len = keys.enckeylen; |
| 1251 | |
| 1252 | memzero_explicit(&keys, sizeof(keys)); |
| 1253 | return aead_setup(tfm, crypto_aead_authsize(tfm)); |
| 1254 | badkey: |
Herbert Xu | dba434a | 2019-04-11 16:51:11 +0800 | [diff] [blame] | 1255 | memzero_explicit(&keys, sizeof(keys)); |
| 1256 | return err; |
| 1257 | } |
| 1258 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1259 | static int aead_encrypt(struct aead_request *req) |
| 1260 | { |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1261 | return aead_perform(req, 1, req->assoclen, req->cryptlen, req->iv); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | static int aead_decrypt(struct aead_request *req) |
| 1265 | { |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1266 | return aead_perform(req, 0, req->assoclen, req->cryptlen, req->iv); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | static struct ixp_alg ixp4xx_algos[] = { |
| 1270 | { |
| 1271 | .crypto = { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1272 | .base.cra_name = "cbc(des)", |
| 1273 | .base.cra_blocksize = DES_BLOCK_SIZE, |
| 1274 | |
| 1275 | .min_keysize = DES_KEY_SIZE, |
| 1276 | .max_keysize = DES_KEY_SIZE, |
| 1277 | .ivsize = DES_BLOCK_SIZE, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1278 | }, |
| 1279 | .cfg_enc = CIPH_ENCR | MOD_DES | MOD_CBC_ENC | KEYLEN_192, |
| 1280 | .cfg_dec = CIPH_DECR | MOD_DES | MOD_CBC_DEC | KEYLEN_192, |
| 1281 | |
| 1282 | }, { |
| 1283 | .crypto = { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1284 | .base.cra_name = "ecb(des)", |
| 1285 | .base.cra_blocksize = DES_BLOCK_SIZE, |
| 1286 | .min_keysize = DES_KEY_SIZE, |
| 1287 | .max_keysize = DES_KEY_SIZE, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1288 | }, |
| 1289 | .cfg_enc = CIPH_ENCR | MOD_DES | MOD_ECB | KEYLEN_192, |
| 1290 | .cfg_dec = CIPH_DECR | MOD_DES | MOD_ECB | KEYLEN_192, |
| 1291 | }, { |
| 1292 | .crypto = { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1293 | .base.cra_name = "cbc(des3_ede)", |
| 1294 | .base.cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 1295 | |
| 1296 | .min_keysize = DES3_EDE_KEY_SIZE, |
| 1297 | .max_keysize = DES3_EDE_KEY_SIZE, |
| 1298 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 1299 | .setkey = ablk_des3_setkey, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1300 | }, |
| 1301 | .cfg_enc = CIPH_ENCR | MOD_3DES | MOD_CBC_ENC | KEYLEN_192, |
| 1302 | .cfg_dec = CIPH_DECR | MOD_3DES | MOD_CBC_DEC | KEYLEN_192, |
| 1303 | }, { |
| 1304 | .crypto = { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1305 | .base.cra_name = "ecb(des3_ede)", |
| 1306 | .base.cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 1307 | |
| 1308 | .min_keysize = DES3_EDE_KEY_SIZE, |
| 1309 | .max_keysize = DES3_EDE_KEY_SIZE, |
| 1310 | .setkey = ablk_des3_setkey, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1311 | }, |
| 1312 | .cfg_enc = CIPH_ENCR | MOD_3DES | MOD_ECB | KEYLEN_192, |
| 1313 | .cfg_dec = CIPH_DECR | MOD_3DES | MOD_ECB | KEYLEN_192, |
| 1314 | }, { |
| 1315 | .crypto = { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1316 | .base.cra_name = "cbc(aes)", |
| 1317 | .base.cra_blocksize = AES_BLOCK_SIZE, |
| 1318 | |
| 1319 | .min_keysize = AES_MIN_KEY_SIZE, |
| 1320 | .max_keysize = AES_MAX_KEY_SIZE, |
| 1321 | .ivsize = AES_BLOCK_SIZE, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1322 | }, |
| 1323 | .cfg_enc = CIPH_ENCR | MOD_AES | MOD_CBC_ENC, |
| 1324 | .cfg_dec = CIPH_DECR | MOD_AES | MOD_CBC_DEC, |
| 1325 | }, { |
| 1326 | .crypto = { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1327 | .base.cra_name = "ecb(aes)", |
| 1328 | .base.cra_blocksize = AES_BLOCK_SIZE, |
| 1329 | |
| 1330 | .min_keysize = AES_MIN_KEY_SIZE, |
| 1331 | .max_keysize = AES_MAX_KEY_SIZE, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1332 | }, |
| 1333 | .cfg_enc = CIPH_ENCR | MOD_AES | MOD_ECB, |
| 1334 | .cfg_dec = CIPH_DECR | MOD_AES | MOD_ECB, |
| 1335 | }, { |
| 1336 | .crypto = { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1337 | .base.cra_name = "ctr(aes)", |
| 1338 | .base.cra_blocksize = 1, |
| 1339 | |
| 1340 | .min_keysize = AES_MIN_KEY_SIZE, |
| 1341 | .max_keysize = AES_MAX_KEY_SIZE, |
| 1342 | .ivsize = AES_BLOCK_SIZE, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1343 | }, |
| 1344 | .cfg_enc = CIPH_ENCR | MOD_AES | MOD_CTR, |
| 1345 | .cfg_dec = CIPH_ENCR | MOD_AES | MOD_CTR, |
| 1346 | }, { |
| 1347 | .crypto = { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1348 | .base.cra_name = "rfc3686(ctr(aes))", |
| 1349 | .base.cra_blocksize = 1, |
| 1350 | |
| 1351 | .min_keysize = AES_MIN_KEY_SIZE, |
| 1352 | .max_keysize = AES_MAX_KEY_SIZE, |
| 1353 | .ivsize = AES_BLOCK_SIZE, |
| 1354 | .setkey = ablk_rfc3686_setkey, |
| 1355 | .encrypt = ablk_rfc3686_crypt, |
| 1356 | .decrypt = ablk_rfc3686_crypt, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1357 | }, |
| 1358 | .cfg_enc = CIPH_ENCR | MOD_AES | MOD_CTR, |
| 1359 | .cfg_dec = CIPH_ENCR | MOD_AES | MOD_CTR, |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1360 | } }; |
| 1361 | |
| 1362 | static struct ixp_aead_alg ixp4xx_aeads[] = { |
| 1363 | { |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1364 | .crypto = { |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1365 | .base = { |
| 1366 | .cra_name = "authenc(hmac(md5),cbc(des))", |
| 1367 | .cra_blocksize = DES_BLOCK_SIZE, |
| 1368 | }, |
| 1369 | .ivsize = DES_BLOCK_SIZE, |
| 1370 | .maxauthsize = MD5_DIGEST_SIZE, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1371 | }, |
| 1372 | .hash = &hash_alg_md5, |
| 1373 | .cfg_enc = CIPH_ENCR | MOD_DES | MOD_CBC_ENC | KEYLEN_192, |
| 1374 | .cfg_dec = CIPH_DECR | MOD_DES | MOD_CBC_DEC | KEYLEN_192, |
| 1375 | }, { |
| 1376 | .crypto = { |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1377 | .base = { |
| 1378 | .cra_name = "authenc(hmac(md5),cbc(des3_ede))", |
| 1379 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 1380 | }, |
| 1381 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 1382 | .maxauthsize = MD5_DIGEST_SIZE, |
Herbert Xu | dba434a | 2019-04-11 16:51:11 +0800 | [diff] [blame] | 1383 | .setkey = des3_aead_setkey, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1384 | }, |
| 1385 | .hash = &hash_alg_md5, |
| 1386 | .cfg_enc = CIPH_ENCR | MOD_3DES | MOD_CBC_ENC | KEYLEN_192, |
| 1387 | .cfg_dec = CIPH_DECR | MOD_3DES | MOD_CBC_DEC | KEYLEN_192, |
| 1388 | }, { |
| 1389 | .crypto = { |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1390 | .base = { |
| 1391 | .cra_name = "authenc(hmac(sha1),cbc(des))", |
| 1392 | .cra_blocksize = DES_BLOCK_SIZE, |
| 1393 | }, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1394 | .ivsize = DES_BLOCK_SIZE, |
| 1395 | .maxauthsize = SHA1_DIGEST_SIZE, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1396 | }, |
| 1397 | .hash = &hash_alg_sha1, |
| 1398 | .cfg_enc = CIPH_ENCR | MOD_DES | MOD_CBC_ENC | KEYLEN_192, |
| 1399 | .cfg_dec = CIPH_DECR | MOD_DES | MOD_CBC_DEC | KEYLEN_192, |
| 1400 | }, { |
| 1401 | .crypto = { |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1402 | .base = { |
| 1403 | .cra_name = "authenc(hmac(sha1),cbc(des3_ede))", |
| 1404 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 1405 | }, |
| 1406 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 1407 | .maxauthsize = SHA1_DIGEST_SIZE, |
Herbert Xu | dba434a | 2019-04-11 16:51:11 +0800 | [diff] [blame] | 1408 | .setkey = des3_aead_setkey, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1409 | }, |
| 1410 | .hash = &hash_alg_sha1, |
| 1411 | .cfg_enc = CIPH_ENCR | MOD_3DES | MOD_CBC_ENC | KEYLEN_192, |
| 1412 | .cfg_dec = CIPH_DECR | MOD_3DES | MOD_CBC_DEC | KEYLEN_192, |
| 1413 | }, { |
| 1414 | .crypto = { |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1415 | .base = { |
| 1416 | .cra_name = "authenc(hmac(md5),cbc(aes))", |
| 1417 | .cra_blocksize = AES_BLOCK_SIZE, |
| 1418 | }, |
| 1419 | .ivsize = AES_BLOCK_SIZE, |
| 1420 | .maxauthsize = MD5_DIGEST_SIZE, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1421 | }, |
| 1422 | .hash = &hash_alg_md5, |
| 1423 | .cfg_enc = CIPH_ENCR | MOD_AES | MOD_CBC_ENC, |
| 1424 | .cfg_dec = CIPH_DECR | MOD_AES | MOD_CBC_DEC, |
| 1425 | }, { |
| 1426 | .crypto = { |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1427 | .base = { |
| 1428 | .cra_name = "authenc(hmac(sha1),cbc(aes))", |
| 1429 | .cra_blocksize = AES_BLOCK_SIZE, |
| 1430 | }, |
| 1431 | .ivsize = AES_BLOCK_SIZE, |
| 1432 | .maxauthsize = SHA1_DIGEST_SIZE, |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1433 | }, |
| 1434 | .hash = &hash_alg_sha1, |
| 1435 | .cfg_enc = CIPH_ENCR | MOD_AES | MOD_CBC_ENC, |
| 1436 | .cfg_dec = CIPH_DECR | MOD_AES | MOD_CBC_DEC, |
| 1437 | } }; |
| 1438 | |
| 1439 | #define IXP_POSTFIX "-ixp4xx" |
Russell King | d8cbc3f | 2013-06-10 18:52:52 +0100 | [diff] [blame] | 1440 | |
| 1441 | static const struct platform_device_info ixp_dev_info __initdata = { |
| 1442 | .name = DRIVER_NAME, |
| 1443 | .id = 0, |
| 1444 | .dma_mask = DMA_BIT_MASK(32), |
| 1445 | }; |
| 1446 | |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1447 | static int __init ixp_module_init(void) |
| 1448 | { |
| 1449 | int num = ARRAY_SIZE(ixp4xx_algos); |
Krzysztof Hałasa | efb753b | 2013-12-31 11:51:16 +0100 | [diff] [blame] | 1450 | int i, err; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1451 | |
Russell King | d8cbc3f | 2013-06-10 18:52:52 +0100 | [diff] [blame] | 1452 | pdev = platform_device_register_full(&ixp_dev_info); |
| 1453 | if (IS_ERR(pdev)) |
| 1454 | return PTR_ERR(pdev); |
| 1455 | |
Russell King | 27c1789 | 2013-06-10 19:09:45 +0100 | [diff] [blame] | 1456 | err = init_ixp_crypto(&pdev->dev); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1457 | if (err) { |
Russell King | d8cbc3f | 2013-06-10 18:52:52 +0100 | [diff] [blame] | 1458 | platform_device_unregister(pdev); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1459 | return err; |
| 1460 | } |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 1461 | for (i = 0; i < num; i++) { |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1462 | struct skcipher_alg *cra = &ixp4xx_algos[i].crypto; |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1463 | |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1464 | if (snprintf(cra->base.cra_driver_name, CRYPTO_MAX_ALG_NAME, |
| 1465 | "%s"IXP_POSTFIX, cra->base.cra_name) >= |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1466 | CRYPTO_MAX_ALG_NAME) |
| 1467 | { |
| 1468 | continue; |
| 1469 | } |
| 1470 | if (!support_aes && (ixp4xx_algos[i].cfg_enc & MOD_AES)) { |
| 1471 | continue; |
| 1472 | } |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1473 | |
| 1474 | /* block ciphers */ |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1475 | cra->base.cra_flags = CRYPTO_ALG_KERN_DRIVER_ONLY | |
Mikulas Patocka | b8aa7dc | 2020-07-09 23:20:41 -0700 | [diff] [blame] | 1476 | CRYPTO_ALG_ASYNC | |
Corentin Labbe | dfb098d | 2021-05-05 20:26:10 +0000 | [diff] [blame] | 1477 | CRYPTO_ALG_ALLOCATES_MEMORY | |
| 1478 | CRYPTO_ALG_NEED_FALLBACK; |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1479 | if (!cra->setkey) |
| 1480 | cra->setkey = ablk_setkey; |
| 1481 | if (!cra->encrypt) |
| 1482 | cra->encrypt = ablk_encrypt; |
| 1483 | if (!cra->decrypt) |
| 1484 | cra->decrypt = ablk_decrypt; |
| 1485 | cra->init = init_tfm_ablk; |
| 1486 | cra->exit = exit_tfm_ablk; |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1487 | |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1488 | cra->base.cra_ctxsize = sizeof(struct ixp_ctx); |
| 1489 | cra->base.cra_module = THIS_MODULE; |
| 1490 | cra->base.cra_alignmask = 3; |
| 1491 | cra->base.cra_priority = 300; |
| 1492 | if (crypto_register_skcipher(cra)) |
Corentin Labbe | f5b82be | 2021-05-05 20:26:12 +0000 | [diff] [blame] | 1493 | dev_err(&pdev->dev, "Failed to register '%s'\n", |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1494 | cra->base.cra_name); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1495 | else |
| 1496 | ixp4xx_algos[i].registered = 1; |
| 1497 | } |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1498 | |
| 1499 | for (i = 0; i < ARRAY_SIZE(ixp4xx_aeads); i++) { |
| 1500 | struct aead_alg *cra = &ixp4xx_aeads[i].crypto; |
| 1501 | |
| 1502 | if (snprintf(cra->base.cra_driver_name, CRYPTO_MAX_ALG_NAME, |
| 1503 | "%s"IXP_POSTFIX, cra->base.cra_name) >= |
| 1504 | CRYPTO_MAX_ALG_NAME) |
| 1505 | continue; |
| 1506 | if (!support_aes && (ixp4xx_algos[i].cfg_enc & MOD_AES)) |
| 1507 | continue; |
| 1508 | |
| 1509 | /* authenc */ |
| 1510 | cra->base.cra_flags = CRYPTO_ALG_KERN_DRIVER_ONLY | |
Mikulas Patocka | b8aa7dc | 2020-07-09 23:20:41 -0700 | [diff] [blame] | 1511 | CRYPTO_ALG_ASYNC | |
| 1512 | CRYPTO_ALG_ALLOCATES_MEMORY; |
Herbert Xu | dba434a | 2019-04-11 16:51:11 +0800 | [diff] [blame] | 1513 | cra->setkey = cra->setkey ?: aead_setkey; |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1514 | cra->setauthsize = aead_setauthsize; |
| 1515 | cra->encrypt = aead_encrypt; |
| 1516 | cra->decrypt = aead_decrypt; |
| 1517 | cra->init = init_tfm_aead; |
| 1518 | cra->exit = exit_tfm_aead; |
| 1519 | |
| 1520 | cra->base.cra_ctxsize = sizeof(struct ixp_ctx); |
| 1521 | cra->base.cra_module = THIS_MODULE; |
| 1522 | cra->base.cra_alignmask = 3; |
| 1523 | cra->base.cra_priority = 300; |
| 1524 | |
| 1525 | if (crypto_register_aead(cra)) |
Corentin Labbe | f5b82be | 2021-05-05 20:26:12 +0000 | [diff] [blame] | 1526 | dev_err(&pdev->dev, "Failed to register '%s'\n", |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1527 | cra->base.cra_driver_name); |
| 1528 | else |
| 1529 | ixp4xx_aeads[i].registered = 1; |
| 1530 | } |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1531 | return 0; |
| 1532 | } |
| 1533 | |
| 1534 | static void __exit ixp_module_exit(void) |
| 1535 | { |
| 1536 | int num = ARRAY_SIZE(ixp4xx_algos); |
| 1537 | int i; |
| 1538 | |
Herbert Xu | d7295a8 | 2015-07-30 17:53:18 +0800 | [diff] [blame] | 1539 | for (i = 0; i < ARRAY_SIZE(ixp4xx_aeads); i++) { |
| 1540 | if (ixp4xx_aeads[i].registered) |
| 1541 | crypto_unregister_aead(&ixp4xx_aeads[i].crypto); |
| 1542 | } |
| 1543 | |
Corentin Labbe | 39e39cf | 2021-05-05 20:26:13 +0000 | [diff] [blame] | 1544 | for (i = 0; i < num; i++) { |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1545 | if (ixp4xx_algos[i].registered) |
Ard Biesheuvel | 4aaf384 | 2019-11-09 18:09:40 +0100 | [diff] [blame] | 1546 | crypto_unregister_skcipher(&ixp4xx_algos[i].crypto); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1547 | } |
Russell King | 27c1789 | 2013-06-10 19:09:45 +0100 | [diff] [blame] | 1548 | release_ixp_crypto(&pdev->dev); |
Russell King | d8cbc3f | 2013-06-10 18:52:52 +0100 | [diff] [blame] | 1549 | platform_device_unregister(pdev); |
Christian Hohnstaedt | 81bef01 | 2008-06-25 14:38:47 +0800 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | module_init(ixp_module_init); |
| 1553 | module_exit(ixp_module_exit); |
| 1554 | |
| 1555 | MODULE_LICENSE("GPL"); |
| 1556 | MODULE_AUTHOR("Christian Hohnstaedt <chohnstaedt@innominate.com>"); |
| 1557 | MODULE_DESCRIPTION("IXP4xx hardware crypto"); |
| 1558 | |