diff options
author | Behan Webster <behanw@converseincode.com> | 2014-04-04 17:18:00 -0400 |
---|---|---|
committer | Behan Webster <behanw@converseincode.com> | 2014-10-14 04:51:23 -0400 |
commit | 37e5265437a02e66e8c345f563241e79b4b7f087 (patch) | |
tree | 91676171d241de3ff3295c762899877da136272d /drivers/crypto/qat | |
parent | 7bc53c3f9ac8c0d6b6ffa92b4b7493576233e78e (diff) |
crypto: LLVMLinux: Remove VLAIS from crypto/.../qat_algs.c
Replaced the use of a Variable Length Array In Struct (VLAIS) with a C99
compliant equivalent. This patch allocates the appropriate amount of memory
using a char array using the SHASH_DESC_ON_STACK macro.
The new code can be compiled with both gcc and clang.
Signed-off-by: Behan Webster <behanw@converseincode.com>
Reviewed-by: Mark Charlebois <charlebm@gmail.com>
Reviewed-by: Jan-Simon Möller <dl9pf@gmx.de>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/qat')
-rw-r--r-- | drivers/crypto/qat/qat_common/qat_algs.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/drivers/crypto/qat/qat_common/qat_algs.c b/drivers/crypto/qat/qat_common/qat_algs.c index 3e26fa2b293f..f2e2f158cfbe 100644 --- a/drivers/crypto/qat/qat_common/qat_algs.c +++ b/drivers/crypto/qat/qat_common/qat_algs.c | |||
@@ -149,10 +149,7 @@ static int qat_alg_do_precomputes(struct icp_qat_hw_auth_algo_blk *hash, | |||
149 | unsigned int auth_keylen) | 149 | unsigned int auth_keylen) |
150 | { | 150 | { |
151 | struct qat_auth_state auth_state; | 151 | struct qat_auth_state auth_state; |
152 | struct { | 152 | SHASH_DESC_ON_STACK(shash, ctx->hash_tfm); |
153 | struct shash_desc shash; | ||
154 | char ctx[crypto_shash_descsize(ctx->hash_tfm)]; | ||
155 | } desc; | ||
156 | struct sha1_state sha1; | 153 | struct sha1_state sha1; |
157 | struct sha256_state sha256; | 154 | struct sha256_state sha256; |
158 | struct sha512_state sha512; | 155 | struct sha512_state sha512; |
@@ -165,12 +162,12 @@ static int qat_alg_do_precomputes(struct icp_qat_hw_auth_algo_blk *hash, | |||
165 | int i, offset; | 162 | int i, offset; |
166 | 163 | ||
167 | memset(auth_state.data, '\0', MAX_AUTH_STATE_SIZE + 64); | 164 | memset(auth_state.data, '\0', MAX_AUTH_STATE_SIZE + 64); |
168 | desc.shash.tfm = ctx->hash_tfm; | 165 | shash->tfm = ctx->hash_tfm; |
169 | desc.shash.flags = 0x0; | 166 | shash->flags = 0x0; |
170 | 167 | ||
171 | if (auth_keylen > block_size) { | 168 | if (auth_keylen > block_size) { |
172 | char buff[SHA512_BLOCK_SIZE]; | 169 | char buff[SHA512_BLOCK_SIZE]; |
173 | int ret = crypto_shash_digest(&desc.shash, auth_key, | 170 | int ret = crypto_shash_digest(shash, auth_key, |
174 | auth_keylen, buff); | 171 | auth_keylen, buff); |
175 | if (ret) | 172 | if (ret) |
176 | return ret; | 173 | return ret; |
@@ -193,10 +190,10 @@ static int qat_alg_do_precomputes(struct icp_qat_hw_auth_algo_blk *hash, | |||
193 | *opad_ptr ^= 0x5C; | 190 | *opad_ptr ^= 0x5C; |
194 | } | 191 | } |
195 | 192 | ||
196 | if (crypto_shash_init(&desc.shash)) | 193 | if (crypto_shash_init(shash)) |
197 | return -EFAULT; | 194 | return -EFAULT; |
198 | 195 | ||
199 | if (crypto_shash_update(&desc.shash, ipad, block_size)) | 196 | if (crypto_shash_update(shash, ipad, block_size)) |
200 | return -EFAULT; | 197 | return -EFAULT; |
201 | 198 | ||
202 | hash_state_out = (__be32 *)hash->sha.state1; | 199 | hash_state_out = (__be32 *)hash->sha.state1; |
@@ -204,19 +201,19 @@ static int qat_alg_do_precomputes(struct icp_qat_hw_auth_algo_blk *hash, | |||
204 | 201 | ||
205 | switch (ctx->qat_hash_alg) { | 202 | switch (ctx->qat_hash_alg) { |
206 | case ICP_QAT_HW_AUTH_ALGO_SHA1: | 203 | case ICP_QAT_HW_AUTH_ALGO_SHA1: |
207 | if (crypto_shash_export(&desc.shash, &sha1)) | 204 | if (crypto_shash_export(shash, &sha1)) |
208 | return -EFAULT; | 205 | return -EFAULT; |
209 | for (i = 0; i < digest_size >> 2; i++, hash_state_out++) | 206 | for (i = 0; i < digest_size >> 2; i++, hash_state_out++) |
210 | *hash_state_out = cpu_to_be32(*(sha1.state + i)); | 207 | *hash_state_out = cpu_to_be32(*(sha1.state + i)); |
211 | break; | 208 | break; |
212 | case ICP_QAT_HW_AUTH_ALGO_SHA256: | 209 | case ICP_QAT_HW_AUTH_ALGO_SHA256: |
213 | if (crypto_shash_export(&desc.shash, &sha256)) | 210 | if (crypto_shash_export(shash, &sha256)) |
214 | return -EFAULT; | 211 | return -EFAULT; |
215 | for (i = 0; i < digest_size >> 2; i++, hash_state_out++) | 212 | for (i = 0; i < digest_size >> 2; i++, hash_state_out++) |
216 | *hash_state_out = cpu_to_be32(*(sha256.state + i)); | 213 | *hash_state_out = cpu_to_be32(*(sha256.state + i)); |
217 | break; | 214 | break; |
218 | case ICP_QAT_HW_AUTH_ALGO_SHA512: | 215 | case ICP_QAT_HW_AUTH_ALGO_SHA512: |
219 | if (crypto_shash_export(&desc.shash, &sha512)) | 216 | if (crypto_shash_export(shash, &sha512)) |
220 | return -EFAULT; | 217 | return -EFAULT; |
221 | for (i = 0; i < digest_size >> 3; i++, hash512_state_out++) | 218 | for (i = 0; i < digest_size >> 3; i++, hash512_state_out++) |
222 | *hash512_state_out = cpu_to_be64(*(sha512.state + i)); | 219 | *hash512_state_out = cpu_to_be64(*(sha512.state + i)); |
@@ -225,10 +222,10 @@ static int qat_alg_do_precomputes(struct icp_qat_hw_auth_algo_blk *hash, | |||
225 | return -EFAULT; | 222 | return -EFAULT; |
226 | } | 223 | } |
227 | 224 | ||
228 | if (crypto_shash_init(&desc.shash)) | 225 | if (crypto_shash_init(shash)) |
229 | return -EFAULT; | 226 | return -EFAULT; |
230 | 227 | ||
231 | if (crypto_shash_update(&desc.shash, opad, block_size)) | 228 | if (crypto_shash_update(shash, opad, block_size)) |
232 | return -EFAULT; | 229 | return -EFAULT; |
233 | 230 | ||
234 | offset = round_up(qat_get_inter_state_size(ctx->qat_hash_alg), 8); | 231 | offset = round_up(qat_get_inter_state_size(ctx->qat_hash_alg), 8); |
@@ -237,19 +234,19 @@ static int qat_alg_do_precomputes(struct icp_qat_hw_auth_algo_blk *hash, | |||
237 | 234 | ||
238 | switch (ctx->qat_hash_alg) { | 235 | switch (ctx->qat_hash_alg) { |
239 | case ICP_QAT_HW_AUTH_ALGO_SHA1: | 236 | case ICP_QAT_HW_AUTH_ALGO_SHA1: |
240 | if (crypto_shash_export(&desc.shash, &sha1)) | 237 | if (crypto_shash_export(shash, &sha1)) |
241 | return -EFAULT; | 238 | return -EFAULT; |
242 | for (i = 0; i < digest_size >> 2; i++, hash_state_out++) | 239 | for (i = 0; i < digest_size >> 2; i++, hash_state_out++) |
243 | *hash_state_out = cpu_to_be32(*(sha1.state + i)); | 240 | *hash_state_out = cpu_to_be32(*(sha1.state + i)); |
244 | break; | 241 | break; |
245 | case ICP_QAT_HW_AUTH_ALGO_SHA256: | 242 | case ICP_QAT_HW_AUTH_ALGO_SHA256: |
246 | if (crypto_shash_export(&desc.shash, &sha256)) | 243 | if (crypto_shash_export(shash, &sha256)) |
247 | return -EFAULT; | 244 | return -EFAULT; |
248 | for (i = 0; i < digest_size >> 2; i++, hash_state_out++) | 245 | for (i = 0; i < digest_size >> 2; i++, hash_state_out++) |
249 | *hash_state_out = cpu_to_be32(*(sha256.state + i)); | 246 | *hash_state_out = cpu_to_be32(*(sha256.state + i)); |
250 | break; | 247 | break; |
251 | case ICP_QAT_HW_AUTH_ALGO_SHA512: | 248 | case ICP_QAT_HW_AUTH_ALGO_SHA512: |
252 | if (crypto_shash_export(&desc.shash, &sha512)) | 249 | if (crypto_shash_export(shash, &sha512)) |
253 | return -EFAULT; | 250 | return -EFAULT; |
254 | for (i = 0; i < digest_size >> 3; i++, hash512_state_out++) | 251 | for (i = 0; i < digest_size >> 3; i++, hash512_state_out++) |
255 | *hash512_state_out = cpu_to_be64(*(sha512.state + i)); | 252 | *hash512_state_out = cpu_to_be64(*(sha512.state + i)); |