apm821xx: don't select swconfig for the MR24
[openwrt/openwrt.git] / target / linux / apm821xx / patches-4.14 / 120-0006-crypto-crypto4xx-performance-optimizations.patch
1 From 30afcbb01a750a1ef0cee8a0861a347912c2e4fb Mon Sep 17 00:00:00 2001
2 From: Christian Lamparter <chunkeey@gmail.com>
3 Date: Thu, 21 Dec 2017 16:00:01 +0100
4 Subject: [PATCH 6/6] crypto: crypto4xx - performance optimizations
5
6 This patch provides a cheap 2MiB/s+ (~ 6%) performance
7 improvement over the current code. This is because the
8 compiler can now optimize several endian swap memcpy.
9
10 Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
11 ---
12 drivers/crypto/amcc/crypto4xx_alg.c | 32 +++++++++++++++++++-------------
13 drivers/crypto/amcc/crypto4xx_core.c | 22 +++++++++++-----------
14 drivers/crypto/amcc/crypto4xx_core.h | 6 ++++--
15 3 files changed, 34 insertions(+), 26 deletions(-)
16
17 --- a/drivers/crypto/amcc/crypto4xx_alg.c
18 +++ b/drivers/crypto/amcc/crypto4xx_alg.c
19 @@ -74,32 +74,38 @@ static void set_dynamic_sa_command_1(str
20 sa->sa_command_1.bf.copy_hdr = cp_hdr;
21 }
22
23 -int crypto4xx_encrypt(struct ablkcipher_request *req)
24 +static inline int crypto4xx_crypt(struct ablkcipher_request *req,
25 + const unsigned int ivlen, bool decrypt)
26 {
27 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
28 - unsigned int ivlen = crypto_ablkcipher_ivsize(
29 - crypto_ablkcipher_reqtfm(req));
30 __le32 iv[ivlen];
31
32 if (ivlen)
33 crypto4xx_memcpy_to_le32(iv, req->info, ivlen);
34
35 return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
36 - req->nbytes, iv, ivlen, ctx->sa_out, ctx->sa_len, 0);
37 + req->nbytes, iv, ivlen, decrypt ? ctx->sa_in : ctx->sa_out,
38 + ctx->sa_len, 0);
39 }
40
41 -int crypto4xx_decrypt(struct ablkcipher_request *req)
42 +int crypto4xx_encrypt_noiv(struct ablkcipher_request *req)
43 {
44 - struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
45 - unsigned int ivlen = crypto_ablkcipher_ivsize(
46 - crypto_ablkcipher_reqtfm(req));
47 - __le32 iv[ivlen];
48 + return crypto4xx_crypt(req, 0, false);
49 +}
50
51 - if (ivlen)
52 - crypto4xx_memcpy_to_le32(iv, req->info, ivlen);
53 +int crypto4xx_encrypt_iv(struct ablkcipher_request *req)
54 +{
55 + return crypto4xx_crypt(req, AES_IV_SIZE, false);
56 +}
57
58 - return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
59 - req->nbytes, iv, ivlen, ctx->sa_in, ctx->sa_len, 0);
60 +int crypto4xx_decrypt_noiv(struct ablkcipher_request *req)
61 +{
62 + return crypto4xx_crypt(req, 0, true);
63 +}
64 +
65 +int crypto4xx_decrypt_iv(struct ablkcipher_request *req)
66 +{
67 + return crypto4xx_crypt(req, AES_IV_SIZE, true);
68 }
69
70 /**
71 --- a/drivers/crypto/amcc/crypto4xx_core.c
72 +++ b/drivers/crypto/amcc/crypto4xx_core.c
73 @@ -582,7 +582,7 @@ static void crypto4xx_aead_done(struct c
74 struct scatterlist *dst = pd_uinfo->dest_va;
75 size_t cp_len = crypto_aead_authsize(
76 crypto_aead_reqtfm(aead_req));
77 - u32 icv[cp_len];
78 + u32 icv[AES_BLOCK_SIZE];
79 int err = 0;
80
81 if (pd_uinfo->using_sd) {
82 @@ -597,7 +597,7 @@ static void crypto4xx_aead_done(struct c
83 if (pd_uinfo->sa_va->sa_command_0.bf.dir == DIR_OUTBOUND) {
84 /* append icv at the end */
85 crypto4xx_memcpy_from_le32(icv, pd_uinfo->sr_va->save_digest,
86 - cp_len);
87 + sizeof(icv));
88
89 scatterwalk_map_and_copy(icv, dst, aead_req->cryptlen,
90 cp_len, 1);
91 @@ -607,7 +607,7 @@ static void crypto4xx_aead_done(struct c
92 aead_req->assoclen + aead_req->cryptlen -
93 cp_len, cp_len, 0);
94
95 - crypto4xx_memcpy_from_le32(icv, icv, cp_len);
96 + crypto4xx_memcpy_from_le32(icv, icv, sizeof(icv));
97
98 if (crypto_memneq(icv, pd_uinfo->sr_va->save_digest, cp_len))
99 err = -EBADMSG;
100 @@ -1124,8 +1124,8 @@ static struct crypto4xx_alg_common crypt
101 .max_keysize = AES_MAX_KEY_SIZE,
102 .ivsize = AES_IV_SIZE,
103 .setkey = crypto4xx_setkey_aes_cbc,
104 - .encrypt = crypto4xx_encrypt,
105 - .decrypt = crypto4xx_decrypt,
106 + .encrypt = crypto4xx_encrypt_iv,
107 + .decrypt = crypto4xx_decrypt_iv,
108 }
109 }
110 }},
111 @@ -1148,8 +1148,8 @@ static struct crypto4xx_alg_common crypt
112 .max_keysize = AES_MAX_KEY_SIZE,
113 .ivsize = AES_IV_SIZE,
114 .setkey = crypto4xx_setkey_aes_cfb,
115 - .encrypt = crypto4xx_encrypt,
116 - .decrypt = crypto4xx_decrypt,
117 + .encrypt = crypto4xx_encrypt_iv,
118 + .decrypt = crypto4xx_decrypt_iv,
119 }
120 }
121 } },
122 @@ -1197,8 +1197,8 @@ static struct crypto4xx_alg_common crypt
123 .min_keysize = AES_MIN_KEY_SIZE,
124 .max_keysize = AES_MAX_KEY_SIZE,
125 .setkey = crypto4xx_setkey_aes_ecb,
126 - .encrypt = crypto4xx_encrypt,
127 - .decrypt = crypto4xx_decrypt,
128 + .encrypt = crypto4xx_encrypt_noiv,
129 + .decrypt = crypto4xx_decrypt_noiv,
130 }
131 }
132 } },
133 @@ -1221,8 +1221,8 @@ static struct crypto4xx_alg_common crypt
134 .max_keysize = AES_MAX_KEY_SIZE,
135 .ivsize = AES_IV_SIZE,
136 .setkey = crypto4xx_setkey_aes_ofb,
137 - .encrypt = crypto4xx_encrypt,
138 - .decrypt = crypto4xx_decrypt,
139 + .encrypt = crypto4xx_encrypt_iv,
140 + .decrypt = crypto4xx_decrypt_iv,
141 }
142 }
143 } },
144 --- a/drivers/crypto/amcc/crypto4xx_core.h
145 +++ b/drivers/crypto/amcc/crypto4xx_core.h
146 @@ -168,8 +168,10 @@ int crypto4xx_setkey_aes_ofb(struct cryp
147 const u8 *key, unsigned int keylen);
148 int crypto4xx_setkey_rfc3686(struct crypto_ablkcipher *cipher,
149 const u8 *key, unsigned int keylen);
150 -int crypto4xx_encrypt(struct ablkcipher_request *req);
151 -int crypto4xx_decrypt(struct ablkcipher_request *req);
152 +int crypto4xx_encrypt_iv(struct ablkcipher_request *req);
153 +int crypto4xx_decrypt_iv(struct ablkcipher_request *req);
154 +int crypto4xx_encrypt_noiv(struct ablkcipher_request *req);
155 +int crypto4xx_decrypt_noiv(struct ablkcipher_request *req);
156 int crypto4xx_rfc3686_encrypt(struct ablkcipher_request *req);
157 int crypto4xx_rfc3686_decrypt(struct ablkcipher_request *req);
158 int crypto4xx_sha1_alg_init(struct crypto_tfm *tfm);