hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/drivers/crypto/hifn_795x.c
....@@ -1,16 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * 2007+ Copyright (c) Evgeniy Polyakov <johnpol@2ka.mipt.ru>
34 * All rights reserved.
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation; either version 2 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
145 */
156
167 #include <linux/kernel.h>
....@@ -30,7 +21,8 @@
3021 #include <linux/ktime.h>
3122
3223 #include <crypto/algapi.h>
33
-#include <crypto/des.h>
24
+#include <crypto/internal/des.h>
25
+#include <crypto/internal/skcipher.h>
3426
3527 static char hifn_pll_ref[sizeof("extNNN")] = "ext";
3628 module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
....@@ -605,7 +597,7 @@
605597
606598 struct hifn_crypto_alg {
607599 struct list_head entry;
608
- struct crypto_alg alg;
600
+ struct skcipher_alg alg;
609601 struct hifn_device *dev;
610602 };
611603
....@@ -788,8 +780,8 @@
788780 dev->pk_clk_freq) * 256;
789781
790782 dev->rng.name = dev->name;
791
- dev->rng.data_present = hifn_rng_data_present,
792
- dev->rng.data_read = hifn_rng_data_read,
783
+ dev->rng.data_present = hifn_rng_data_present;
784
+ dev->rng.data_read = hifn_rng_data_read;
793785 dev->rng.priv = (unsigned long)dev;
794786
795787 return hwrng_register(&dev->rng);
....@@ -1243,7 +1235,8 @@
12431235 int idx;
12441236 dma_addr_t addr;
12451237
1246
- addr = pci_map_page(dev->pdev, page, offset, size, PCI_DMA_TODEVICE);
1238
+ addr = dma_map_page(&dev->pdev->dev, page, offset, size,
1239
+ DMA_TO_DEVICE);
12471240
12481241 idx = dma->srci;
12491242
....@@ -1301,7 +1294,8 @@
13011294 int idx;
13021295 dma_addr_t addr;
13031296
1304
- addr = pci_map_page(dev->pdev, page, offset, size, PCI_DMA_FROMDEVICE);
1297
+ addr = dma_map_page(&dev->pdev->dev, page, offset, size,
1298
+ DMA_FROM_DEVICE);
13051299
13061300 idx = dma->dsti;
13071301 dma->dstr[idx].p = __cpu_to_le32(addr);
....@@ -1413,7 +1407,7 @@
14131407 w->num = 0;
14141408 }
14151409
1416
-static int ablkcipher_add(unsigned int *drestp, struct scatterlist *dst,
1410
+static int skcipher_add(unsigned int *drestp, struct scatterlist *dst,
14171411 unsigned int size, unsigned int *nbytesp)
14181412 {
14191413 unsigned int copy, drest = *drestp, nbytes = *nbytesp;
....@@ -1442,11 +1436,11 @@
14421436 return idx;
14431437 }
14441438
1445
-static int hifn_cipher_walk(struct ablkcipher_request *req,
1439
+static int hifn_cipher_walk(struct skcipher_request *req,
14461440 struct hifn_cipher_walk *w)
14471441 {
14481442 struct scatterlist *dst, *t;
1449
- unsigned int nbytes = req->nbytes, offset, copy, diff;
1443
+ unsigned int nbytes = req->cryptlen, offset, copy, diff;
14501444 int idx, tidx, err;
14511445
14521446 tidx = idx = 0;
....@@ -1468,7 +1462,7 @@
14681462
14691463 t = &w->cache[idx];
14701464
1471
- err = ablkcipher_add(&dlen, dst, slen, &nbytes);
1465
+ err = skcipher_add(&dlen, dst, slen, &nbytes);
14721466 if (err < 0)
14731467 return err;
14741468
....@@ -1507,7 +1501,7 @@
15071501
15081502 dst = &req->dst[idx];
15091503
1510
- err = ablkcipher_add(&dlen, dst, nbytes, &nbytes);
1504
+ err = skcipher_add(&dlen, dst, nbytes, &nbytes);
15111505 if (err < 0)
15121506 return err;
15131507
....@@ -1527,13 +1521,13 @@
15271521 return tidx;
15281522 }
15291523
1530
-static int hifn_setup_session(struct ablkcipher_request *req)
1524
+static int hifn_setup_session(struct skcipher_request *req)
15311525 {
15321526 struct hifn_context *ctx = crypto_tfm_ctx(req->base.tfm);
1533
- struct hifn_request_context *rctx = ablkcipher_request_ctx(req);
1527
+ struct hifn_request_context *rctx = skcipher_request_ctx(req);
15341528 struct hifn_device *dev = ctx->dev;
15351529 unsigned long dlen, flags;
1536
- unsigned int nbytes = req->nbytes, idx = 0;
1530
+ unsigned int nbytes = req->cryptlen, idx = 0;
15371531 int err = -EINVAL, sg_num;
15381532 struct scatterlist *dst;
15391533
....@@ -1572,7 +1566,7 @@
15721566 goto err_out;
15731567 }
15741568
1575
- err = hifn_setup_dma(dev, ctx, rctx, req->src, req->dst, req->nbytes, req);
1569
+ err = hifn_setup_dma(dev, ctx, rctx, req->src, req->dst, req->cryptlen, req);
15761570 if (err)
15771571 goto err_out;
15781572
....@@ -1619,7 +1613,7 @@
16191613 return 0;
16201614 }
16211615
1622
-static int ablkcipher_get(void *saddr, unsigned int *srestp, unsigned int offset,
1616
+static int skcipher_get(void *saddr, unsigned int *srestp, unsigned int offset,
16231617 struct scatterlist *dst, unsigned int size, unsigned int *nbytesp)
16241618 {
16251619 unsigned int srest = *srestp, nbytes = *nbytesp, copy;
....@@ -1669,12 +1663,12 @@
16691663 BUG_ON(dev->started < 0);
16701664 }
16711665
1672
-static void hifn_process_ready(struct ablkcipher_request *req, int error)
1666
+static void hifn_process_ready(struct skcipher_request *req, int error)
16731667 {
1674
- struct hifn_request_context *rctx = ablkcipher_request_ctx(req);
1668
+ struct hifn_request_context *rctx = skcipher_request_ctx(req);
16751669
16761670 if (rctx->walk.flags & ASYNC_FLAGS_MISALIGNED) {
1677
- unsigned int nbytes = req->nbytes;
1671
+ unsigned int nbytes = req->cryptlen;
16781672 int idx = 0, err;
16791673 struct scatterlist *dst, *t;
16801674 void *saddr;
....@@ -1697,7 +1691,7 @@
16971691
16981692 saddr = kmap_atomic(sg_page(t));
16991693
1700
- err = ablkcipher_get(saddr, &t->length, t->offset,
1694
+ err = skcipher_get(saddr, &t->length, t->offset,
17011695 dst, nbytes, &nbytes);
17021696 if (err < 0) {
17031697 kunmap_atomic(saddr);
....@@ -1919,7 +1913,7 @@
19191913 {
19201914 unsigned long flags;
19211915 struct crypto_async_request *async_req;
1922
- struct ablkcipher_request *req;
1916
+ struct skcipher_request *req;
19231917 struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
19241918 int i;
19251919
....@@ -1935,7 +1929,7 @@
19351929
19361930 spin_lock_irqsave(&dev->lock, flags);
19371931 while ((async_req = crypto_dequeue_request(&dev->queue))) {
1938
- req = ablkcipher_request_cast(async_req);
1932
+ req = skcipher_request_cast(async_req);
19391933 spin_unlock_irqrestore(&dev->lock, flags);
19401934
19411935 hifn_process_ready(req, -ENODEV);
....@@ -1945,27 +1939,16 @@
19451939 spin_unlock_irqrestore(&dev->lock, flags);
19461940 }
19471941
1948
-static int hifn_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
1942
+static int hifn_setkey(struct crypto_skcipher *cipher, const u8 *key,
19491943 unsigned int len)
19501944 {
1951
- struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
1952
- struct hifn_context *ctx = crypto_tfm_ctx(tfm);
1945
+ struct hifn_context *ctx = crypto_skcipher_ctx(cipher);
19531946 struct hifn_device *dev = ctx->dev;
1947
+ int err;
19541948
1955
- if (len > HIFN_MAX_CRYPT_KEY_LENGTH) {
1956
- crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
1957
- return -1;
1958
- }
1959
-
1960
- if (len == HIFN_DES_KEY_LENGTH) {
1961
- u32 tmp[DES_EXPKEY_WORDS];
1962
- int ret = des_ekey(tmp, key);
1963
-
1964
- if (unlikely(ret == 0) && (tfm->crt_flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
1965
- tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
1966
- return -EINVAL;
1967
- }
1968
- }
1949
+ err = verify_skcipher_des_key(cipher, key);
1950
+ if (err)
1951
+ return err;
19691952
19701953 dev->flags &= ~HIFN_FLAG_OLD_KEY;
19711954
....@@ -1975,36 +1958,55 @@
19751958 return 0;
19761959 }
19771960
1978
-static int hifn_handle_req(struct ablkcipher_request *req)
1961
+static int hifn_des3_setkey(struct crypto_skcipher *cipher, const u8 *key,
1962
+ unsigned int len)
1963
+{
1964
+ struct hifn_context *ctx = crypto_skcipher_ctx(cipher);
1965
+ struct hifn_device *dev = ctx->dev;
1966
+ int err;
1967
+
1968
+ err = verify_skcipher_des3_key(cipher, key);
1969
+ if (err)
1970
+ return err;
1971
+
1972
+ dev->flags &= ~HIFN_FLAG_OLD_KEY;
1973
+
1974
+ memcpy(ctx->key, key, len);
1975
+ ctx->keysize = len;
1976
+
1977
+ return 0;
1978
+}
1979
+
1980
+static int hifn_handle_req(struct skcipher_request *req)
19791981 {
19801982 struct hifn_context *ctx = crypto_tfm_ctx(req->base.tfm);
19811983 struct hifn_device *dev = ctx->dev;
19821984 int err = -EAGAIN;
19831985
1984
- if (dev->started + DIV_ROUND_UP(req->nbytes, PAGE_SIZE) <= HIFN_QUEUE_LENGTH)
1986
+ if (dev->started + DIV_ROUND_UP(req->cryptlen, PAGE_SIZE) <= HIFN_QUEUE_LENGTH)
19851987 err = hifn_setup_session(req);
19861988
19871989 if (err == -EAGAIN) {
19881990 unsigned long flags;
19891991
19901992 spin_lock_irqsave(&dev->lock, flags);
1991
- err = ablkcipher_enqueue_request(&dev->queue, req);
1993
+ err = crypto_enqueue_request(&dev->queue, &req->base);
19921994 spin_unlock_irqrestore(&dev->lock, flags);
19931995 }
19941996
19951997 return err;
19961998 }
19971999
1998
-static int hifn_setup_crypto_req(struct ablkcipher_request *req, u8 op,
2000
+static int hifn_setup_crypto_req(struct skcipher_request *req, u8 op,
19992001 u8 type, u8 mode)
20002002 {
20012003 struct hifn_context *ctx = crypto_tfm_ctx(req->base.tfm);
2002
- struct hifn_request_context *rctx = ablkcipher_request_ctx(req);
2004
+ struct hifn_request_context *rctx = skcipher_request_ctx(req);
20032005 unsigned ivsize;
20042006
2005
- ivsize = crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(req));
2007
+ ivsize = crypto_skcipher_ivsize(crypto_skcipher_reqtfm(req));
20062008
2007
- if (req->info && mode != ACRYPTO_MODE_ECB) {
2009
+ if (req->iv && mode != ACRYPTO_MODE_ECB) {
20082010 if (type == ACRYPTO_TYPE_AES_128)
20092011 ivsize = HIFN_AES_IV_LENGTH;
20102012 else if (type == ACRYPTO_TYPE_DES)
....@@ -2023,7 +2025,7 @@
20232025 rctx->op = op;
20242026 rctx->mode = mode;
20252027 rctx->type = type;
2026
- rctx->iv = req->info;
2028
+ rctx->iv = req->iv;
20272029 rctx->ivsize = ivsize;
20282030
20292031 /*
....@@ -2038,7 +2040,7 @@
20382040 static int hifn_process_queue(struct hifn_device *dev)
20392041 {
20402042 struct crypto_async_request *async_req, *backlog;
2041
- struct ablkcipher_request *req;
2043
+ struct skcipher_request *req;
20422044 unsigned long flags;
20432045 int err = 0;
20442046
....@@ -2054,7 +2056,7 @@
20542056 if (backlog)
20552057 backlog->complete(backlog, -EINPROGRESS);
20562058
2057
- req = ablkcipher_request_cast(async_req);
2059
+ req = skcipher_request_cast(async_req);
20582060
20592061 err = hifn_handle_req(req);
20602062 if (err)
....@@ -2064,7 +2066,7 @@
20642066 return err;
20652067 }
20662068
2067
-static int hifn_setup_crypto(struct ablkcipher_request *req, u8 op,
2069
+static int hifn_setup_crypto(struct skcipher_request *req, u8 op,
20682070 u8 type, u8 mode)
20692071 {
20702072 int err;
....@@ -2084,22 +2086,22 @@
20842086 /*
20852087 * AES ecryption functions.
20862088 */
2087
-static inline int hifn_encrypt_aes_ecb(struct ablkcipher_request *req)
2089
+static inline int hifn_encrypt_aes_ecb(struct skcipher_request *req)
20882090 {
20892091 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
20902092 ACRYPTO_TYPE_AES_128, ACRYPTO_MODE_ECB);
20912093 }
2092
-static inline int hifn_encrypt_aes_cbc(struct ablkcipher_request *req)
2094
+static inline int hifn_encrypt_aes_cbc(struct skcipher_request *req)
20932095 {
20942096 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
20952097 ACRYPTO_TYPE_AES_128, ACRYPTO_MODE_CBC);
20962098 }
2097
-static inline int hifn_encrypt_aes_cfb(struct ablkcipher_request *req)
2099
+static inline int hifn_encrypt_aes_cfb(struct skcipher_request *req)
20982100 {
20992101 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
21002102 ACRYPTO_TYPE_AES_128, ACRYPTO_MODE_CFB);
21012103 }
2102
-static inline int hifn_encrypt_aes_ofb(struct ablkcipher_request *req)
2104
+static inline int hifn_encrypt_aes_ofb(struct skcipher_request *req)
21032105 {
21042106 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
21052107 ACRYPTO_TYPE_AES_128, ACRYPTO_MODE_OFB);
....@@ -2108,22 +2110,22 @@
21082110 /*
21092111 * AES decryption functions.
21102112 */
2111
-static inline int hifn_decrypt_aes_ecb(struct ablkcipher_request *req)
2113
+static inline int hifn_decrypt_aes_ecb(struct skcipher_request *req)
21122114 {
21132115 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
21142116 ACRYPTO_TYPE_AES_128, ACRYPTO_MODE_ECB);
21152117 }
2116
-static inline int hifn_decrypt_aes_cbc(struct ablkcipher_request *req)
2118
+static inline int hifn_decrypt_aes_cbc(struct skcipher_request *req)
21172119 {
21182120 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
21192121 ACRYPTO_TYPE_AES_128, ACRYPTO_MODE_CBC);
21202122 }
2121
-static inline int hifn_decrypt_aes_cfb(struct ablkcipher_request *req)
2123
+static inline int hifn_decrypt_aes_cfb(struct skcipher_request *req)
21222124 {
21232125 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
21242126 ACRYPTO_TYPE_AES_128, ACRYPTO_MODE_CFB);
21252127 }
2126
-static inline int hifn_decrypt_aes_ofb(struct ablkcipher_request *req)
2128
+static inline int hifn_decrypt_aes_ofb(struct skcipher_request *req)
21272129 {
21282130 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
21292131 ACRYPTO_TYPE_AES_128, ACRYPTO_MODE_OFB);
....@@ -2132,22 +2134,22 @@
21322134 /*
21332135 * DES ecryption functions.
21342136 */
2135
-static inline int hifn_encrypt_des_ecb(struct ablkcipher_request *req)
2137
+static inline int hifn_encrypt_des_ecb(struct skcipher_request *req)
21362138 {
21372139 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
21382140 ACRYPTO_TYPE_DES, ACRYPTO_MODE_ECB);
21392141 }
2140
-static inline int hifn_encrypt_des_cbc(struct ablkcipher_request *req)
2142
+static inline int hifn_encrypt_des_cbc(struct skcipher_request *req)
21412143 {
21422144 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
21432145 ACRYPTO_TYPE_DES, ACRYPTO_MODE_CBC);
21442146 }
2145
-static inline int hifn_encrypt_des_cfb(struct ablkcipher_request *req)
2147
+static inline int hifn_encrypt_des_cfb(struct skcipher_request *req)
21462148 {
21472149 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
21482150 ACRYPTO_TYPE_DES, ACRYPTO_MODE_CFB);
21492151 }
2150
-static inline int hifn_encrypt_des_ofb(struct ablkcipher_request *req)
2152
+static inline int hifn_encrypt_des_ofb(struct skcipher_request *req)
21512153 {
21522154 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
21532155 ACRYPTO_TYPE_DES, ACRYPTO_MODE_OFB);
....@@ -2156,22 +2158,22 @@
21562158 /*
21572159 * DES decryption functions.
21582160 */
2159
-static inline int hifn_decrypt_des_ecb(struct ablkcipher_request *req)
2161
+static inline int hifn_decrypt_des_ecb(struct skcipher_request *req)
21602162 {
21612163 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
21622164 ACRYPTO_TYPE_DES, ACRYPTO_MODE_ECB);
21632165 }
2164
-static inline int hifn_decrypt_des_cbc(struct ablkcipher_request *req)
2166
+static inline int hifn_decrypt_des_cbc(struct skcipher_request *req)
21652167 {
21662168 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
21672169 ACRYPTO_TYPE_DES, ACRYPTO_MODE_CBC);
21682170 }
2169
-static inline int hifn_decrypt_des_cfb(struct ablkcipher_request *req)
2171
+static inline int hifn_decrypt_des_cfb(struct skcipher_request *req)
21702172 {
21712173 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
21722174 ACRYPTO_TYPE_DES, ACRYPTO_MODE_CFB);
21732175 }
2174
-static inline int hifn_decrypt_des_ofb(struct ablkcipher_request *req)
2176
+static inline int hifn_decrypt_des_ofb(struct skcipher_request *req)
21752177 {
21762178 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
21772179 ACRYPTO_TYPE_DES, ACRYPTO_MODE_OFB);
....@@ -2180,44 +2182,44 @@
21802182 /*
21812183 * 3DES ecryption functions.
21822184 */
2183
-static inline int hifn_encrypt_3des_ecb(struct ablkcipher_request *req)
2185
+static inline int hifn_encrypt_3des_ecb(struct skcipher_request *req)
21842186 {
21852187 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
21862188 ACRYPTO_TYPE_3DES, ACRYPTO_MODE_ECB);
21872189 }
2188
-static inline int hifn_encrypt_3des_cbc(struct ablkcipher_request *req)
2190
+static inline int hifn_encrypt_3des_cbc(struct skcipher_request *req)
21892191 {
21902192 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
21912193 ACRYPTO_TYPE_3DES, ACRYPTO_MODE_CBC);
21922194 }
2193
-static inline int hifn_encrypt_3des_cfb(struct ablkcipher_request *req)
2195
+static inline int hifn_encrypt_3des_cfb(struct skcipher_request *req)
21942196 {
21952197 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
21962198 ACRYPTO_TYPE_3DES, ACRYPTO_MODE_CFB);
21972199 }
2198
-static inline int hifn_encrypt_3des_ofb(struct ablkcipher_request *req)
2200
+static inline int hifn_encrypt_3des_ofb(struct skcipher_request *req)
21992201 {
22002202 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
22012203 ACRYPTO_TYPE_3DES, ACRYPTO_MODE_OFB);
22022204 }
22032205
22042206 /* 3DES decryption functions. */
2205
-static inline int hifn_decrypt_3des_ecb(struct ablkcipher_request *req)
2207
+static inline int hifn_decrypt_3des_ecb(struct skcipher_request *req)
22062208 {
22072209 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
22082210 ACRYPTO_TYPE_3DES, ACRYPTO_MODE_ECB);
22092211 }
2210
-static inline int hifn_decrypt_3des_cbc(struct ablkcipher_request *req)
2212
+static inline int hifn_decrypt_3des_cbc(struct skcipher_request *req)
22112213 {
22122214 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
22132215 ACRYPTO_TYPE_3DES, ACRYPTO_MODE_CBC);
22142216 }
2215
-static inline int hifn_decrypt_3des_cfb(struct ablkcipher_request *req)
2217
+static inline int hifn_decrypt_3des_cfb(struct skcipher_request *req)
22162218 {
22172219 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
22182220 ACRYPTO_TYPE_3DES, ACRYPTO_MODE_CFB);
22192221 }
2220
-static inline int hifn_decrypt_3des_ofb(struct ablkcipher_request *req)
2222
+static inline int hifn_decrypt_3des_ofb(struct skcipher_request *req)
22212223 {
22222224 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
22232225 ACRYPTO_TYPE_3DES, ACRYPTO_MODE_OFB);
....@@ -2227,50 +2229,50 @@
22272229 char name[CRYPTO_MAX_ALG_NAME];
22282230 char drv_name[CRYPTO_MAX_ALG_NAME];
22292231 unsigned int bsize;
2230
- struct ablkcipher_alg ablkcipher;
2232
+ struct skcipher_alg skcipher;
22312233 };
22322234
2233
-static struct hifn_alg_template hifn_alg_templates[] = {
2235
+static const struct hifn_alg_template hifn_alg_templates[] = {
22342236 /*
22352237 * 3DES ECB, CBC, CFB and OFB modes.
22362238 */
22372239 {
22382240 .name = "cfb(des3_ede)", .drv_name = "cfb-3des", .bsize = 8,
2239
- .ablkcipher = {
2241
+ .skcipher = {
22402242 .min_keysize = HIFN_3DES_KEY_LENGTH,
22412243 .max_keysize = HIFN_3DES_KEY_LENGTH,
2242
- .setkey = hifn_setkey,
2244
+ .setkey = hifn_des3_setkey,
22432245 .encrypt = hifn_encrypt_3des_cfb,
22442246 .decrypt = hifn_decrypt_3des_cfb,
22452247 },
22462248 },
22472249 {
22482250 .name = "ofb(des3_ede)", .drv_name = "ofb-3des", .bsize = 8,
2249
- .ablkcipher = {
2251
+ .skcipher = {
22502252 .min_keysize = HIFN_3DES_KEY_LENGTH,
22512253 .max_keysize = HIFN_3DES_KEY_LENGTH,
2252
- .setkey = hifn_setkey,
2254
+ .setkey = hifn_des3_setkey,
22532255 .encrypt = hifn_encrypt_3des_ofb,
22542256 .decrypt = hifn_decrypt_3des_ofb,
22552257 },
22562258 },
22572259 {
22582260 .name = "cbc(des3_ede)", .drv_name = "cbc-3des", .bsize = 8,
2259
- .ablkcipher = {
2261
+ .skcipher = {
22602262 .ivsize = HIFN_IV_LENGTH,
22612263 .min_keysize = HIFN_3DES_KEY_LENGTH,
22622264 .max_keysize = HIFN_3DES_KEY_LENGTH,
2263
- .setkey = hifn_setkey,
2265
+ .setkey = hifn_des3_setkey,
22642266 .encrypt = hifn_encrypt_3des_cbc,
22652267 .decrypt = hifn_decrypt_3des_cbc,
22662268 },
22672269 },
22682270 {
22692271 .name = "ecb(des3_ede)", .drv_name = "ecb-3des", .bsize = 8,
2270
- .ablkcipher = {
2272
+ .skcipher = {
22712273 .min_keysize = HIFN_3DES_KEY_LENGTH,
22722274 .max_keysize = HIFN_3DES_KEY_LENGTH,
2273
- .setkey = hifn_setkey,
2275
+ .setkey = hifn_des3_setkey,
22742276 .encrypt = hifn_encrypt_3des_ecb,
22752277 .decrypt = hifn_decrypt_3des_ecb,
22762278 },
....@@ -2281,7 +2283,7 @@
22812283 */
22822284 {
22832285 .name = "cfb(des)", .drv_name = "cfb-des", .bsize = 8,
2284
- .ablkcipher = {
2286
+ .skcipher = {
22852287 .min_keysize = HIFN_DES_KEY_LENGTH,
22862288 .max_keysize = HIFN_DES_KEY_LENGTH,
22872289 .setkey = hifn_setkey,
....@@ -2291,7 +2293,7 @@
22912293 },
22922294 {
22932295 .name = "ofb(des)", .drv_name = "ofb-des", .bsize = 8,
2294
- .ablkcipher = {
2296
+ .skcipher = {
22952297 .min_keysize = HIFN_DES_KEY_LENGTH,
22962298 .max_keysize = HIFN_DES_KEY_LENGTH,
22972299 .setkey = hifn_setkey,
....@@ -2301,7 +2303,7 @@
23012303 },
23022304 {
23032305 .name = "cbc(des)", .drv_name = "cbc-des", .bsize = 8,
2304
- .ablkcipher = {
2306
+ .skcipher = {
23052307 .ivsize = HIFN_IV_LENGTH,
23062308 .min_keysize = HIFN_DES_KEY_LENGTH,
23072309 .max_keysize = HIFN_DES_KEY_LENGTH,
....@@ -2312,7 +2314,7 @@
23122314 },
23132315 {
23142316 .name = "ecb(des)", .drv_name = "ecb-des", .bsize = 8,
2315
- .ablkcipher = {
2317
+ .skcipher = {
23162318 .min_keysize = HIFN_DES_KEY_LENGTH,
23172319 .max_keysize = HIFN_DES_KEY_LENGTH,
23182320 .setkey = hifn_setkey,
....@@ -2326,7 +2328,7 @@
23262328 */
23272329 {
23282330 .name = "ecb(aes)", .drv_name = "ecb-aes", .bsize = 16,
2329
- .ablkcipher = {
2331
+ .skcipher = {
23302332 .min_keysize = AES_MIN_KEY_SIZE,
23312333 .max_keysize = AES_MAX_KEY_SIZE,
23322334 .setkey = hifn_setkey,
....@@ -2336,7 +2338,7 @@
23362338 },
23372339 {
23382340 .name = "cbc(aes)", .drv_name = "cbc-aes", .bsize = 16,
2339
- .ablkcipher = {
2341
+ .skcipher = {
23402342 .ivsize = HIFN_AES_IV_LENGTH,
23412343 .min_keysize = AES_MIN_KEY_SIZE,
23422344 .max_keysize = AES_MAX_KEY_SIZE,
....@@ -2347,7 +2349,7 @@
23472349 },
23482350 {
23492351 .name = "cfb(aes)", .drv_name = "cfb-aes", .bsize = 16,
2350
- .ablkcipher = {
2352
+ .skcipher = {
23512353 .min_keysize = AES_MIN_KEY_SIZE,
23522354 .max_keysize = AES_MAX_KEY_SIZE,
23532355 .setkey = hifn_setkey,
....@@ -2357,7 +2359,7 @@
23572359 },
23582360 {
23592361 .name = "ofb(aes)", .drv_name = "ofb-aes", .bsize = 16,
2360
- .ablkcipher = {
2362
+ .skcipher = {
23612363 .min_keysize = AES_MIN_KEY_SIZE,
23622364 .max_keysize = AES_MAX_KEY_SIZE,
23632365 .setkey = hifn_setkey,
....@@ -2367,18 +2369,19 @@
23672369 },
23682370 };
23692371
2370
-static int hifn_cra_init(struct crypto_tfm *tfm)
2372
+static int hifn_init_tfm(struct crypto_skcipher *tfm)
23712373 {
2372
- struct crypto_alg *alg = tfm->__crt_alg;
2374
+ struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
23732375 struct hifn_crypto_alg *ha = crypto_alg_to_hifn(alg);
2374
- struct hifn_context *ctx = crypto_tfm_ctx(tfm);
2376
+ struct hifn_context *ctx = crypto_skcipher_ctx(tfm);
23752377
23762378 ctx->dev = ha->dev;
2377
- tfm->crt_ablkcipher.reqsize = sizeof(struct hifn_request_context);
2379
+ crypto_skcipher_set_reqsize(tfm, sizeof(struct hifn_request_context));
2380
+
23782381 return 0;
23792382 }
23802383
2381
-static int hifn_alg_alloc(struct hifn_device *dev, struct hifn_alg_template *t)
2384
+static int hifn_alg_alloc(struct hifn_device *dev, const struct hifn_alg_template *t)
23822385 {
23832386 struct hifn_crypto_alg *alg;
23842387 int err;
....@@ -2387,26 +2390,25 @@
23872390 if (!alg)
23882391 return -ENOMEM;
23892392
2390
- snprintf(alg->alg.cra_name, CRYPTO_MAX_ALG_NAME, "%s", t->name);
2391
- snprintf(alg->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s-%s",
2393
+ alg->alg = t->skcipher;
2394
+ alg->alg.init = hifn_init_tfm;
2395
+
2396
+ snprintf(alg->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, "%s", t->name);
2397
+ snprintf(alg->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s-%s",
23922398 t->drv_name, dev->name);
23932399
2394
- alg->alg.cra_priority = 300;
2395
- alg->alg.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
2396
- CRYPTO_ALG_KERN_DRIVER_ONLY | CRYPTO_ALG_ASYNC;
2397
- alg->alg.cra_blocksize = t->bsize;
2398
- alg->alg.cra_ctxsize = sizeof(struct hifn_context);
2399
- alg->alg.cra_alignmask = 0;
2400
- alg->alg.cra_type = &crypto_ablkcipher_type;
2401
- alg->alg.cra_module = THIS_MODULE;
2402
- alg->alg.cra_u.ablkcipher = t->ablkcipher;
2403
- alg->alg.cra_init = hifn_cra_init;
2400
+ alg->alg.base.cra_priority = 300;
2401
+ alg->alg.base.cra_flags = CRYPTO_ALG_KERN_DRIVER_ONLY | CRYPTO_ALG_ASYNC;
2402
+ alg->alg.base.cra_blocksize = t->bsize;
2403
+ alg->alg.base.cra_ctxsize = sizeof(struct hifn_context);
2404
+ alg->alg.base.cra_alignmask = 0;
2405
+ alg->alg.base.cra_module = THIS_MODULE;
24042406
24052407 alg->dev = dev;
24062408
24072409 list_add_tail(&alg->entry, &dev->alg_list);
24082410
2409
- err = crypto_register_alg(&alg->alg);
2411
+ err = crypto_register_skcipher(&alg->alg);
24102412 if (err) {
24112413 list_del(&alg->entry);
24122414 kfree(alg);
....@@ -2421,7 +2423,7 @@
24212423
24222424 list_for_each_entry_safe(a, n, &dev->alg_list, entry) {
24232425 list_del(&a->entry);
2424
- crypto_unregister_alg(&a->alg);
2426
+ crypto_unregister_skcipher(&a->alg);
24252427 kfree(a);
24262428 }
24272429 }
....@@ -2470,7 +2472,7 @@
24702472 return err;
24712473 pci_set_master(pdev);
24722474
2473
- err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2475
+ err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
24742476 if (err)
24752477 goto err_out_disable_pci_device;
24762478
....@@ -2507,15 +2509,16 @@
25072509 addr = pci_resource_start(pdev, i);
25082510 size = pci_resource_len(pdev, i);
25092511
2510
- dev->bar[i] = ioremap_nocache(addr, size);
2512
+ dev->bar[i] = ioremap(addr, size);
25112513 if (!dev->bar[i]) {
25122514 err = -ENOMEM;
25132515 goto err_out_unmap_bars;
25142516 }
25152517 }
25162518
2517
- dev->desc_virt = pci_zalloc_consistent(pdev, sizeof(struct hifn_dma),
2518
- &dev->desc_dma);
2519
+ dev->desc_virt = dma_alloc_coherent(&pdev->dev,
2520
+ sizeof(struct hifn_dma),
2521
+ &dev->desc_dma, GFP_KERNEL);
25192522 if (!dev->desc_virt) {
25202523 dev_err(&pdev->dev, "Failed to allocate descriptor rings.\n");
25212524 err = -ENOMEM;
....@@ -2572,8 +2575,8 @@
25722575 free_irq(dev->irq, dev);
25732576 tasklet_kill(&dev->tasklet);
25742577 err_out_free_desc:
2575
- pci_free_consistent(pdev, sizeof(struct hifn_dma),
2576
- dev->desc_virt, dev->desc_dma);
2578
+ dma_free_coherent(&pdev->dev, sizeof(struct hifn_dma), dev->desc_virt,
2579
+ dev->desc_dma);
25772580
25782581 err_out_unmap_bars:
25792582 for (i = 0; i < 3; ++i)
....@@ -2610,8 +2613,8 @@
26102613
26112614 hifn_flush(dev);
26122615
2613
- pci_free_consistent(pdev, sizeof(struct hifn_dma),
2614
- dev->desc_virt, dev->desc_dma);
2616
+ dma_free_coherent(&pdev->dev, sizeof(struct hifn_dma),
2617
+ dev->desc_virt, dev->desc_dma);
26152618 for (i = 0; i < 3; ++i)
26162619 if (dev->bar[i])
26172620 iounmap(dev->bar[i]);
....@@ -2641,9 +2644,6 @@
26412644 {
26422645 unsigned int freq;
26432646 int err;
2644
-
2645
- /* HIFN supports only 32-bit addresses */
2646
- BUILD_BUG_ON(sizeof(dma_addr_t) != 4);
26472647
26482648 if (strncmp(hifn_pll_ref, "ext", 3) &&
26492649 strncmp(hifn_pll_ref, "pci", 3)) {