Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: seed - stop using cra_alignmask

Instead of specifying a nonzero alignmask, use the unaligned access
helpers. This eliminates unnecessary alignment operations on most CPUs,
which can handle unaligned accesses efficiently, and brings us a step
closer to eventually removing support for the alignmask field.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Eric Biggers and committed by
Herbert Xu
047ea6d8 7e006158

+21 -27
+21 -27
crypto/seed.c
··· 13 13 #include <linux/init.h> 14 14 #include <linux/types.h> 15 15 #include <linux/errno.h> 16 - #include <asm/byteorder.h> 16 + #include <linux/unaligned.h> 17 17 18 18 #define SEED_NUM_KCONSTANTS 16 19 19 #define SEED_KEY_SIZE 16 ··· 329 329 { 330 330 struct seed_ctx *ctx = crypto_tfm_ctx(tfm); 331 331 u32 *keyout = ctx->keysched; 332 - const __be32 *key = (const __be32 *)in_key; 333 332 u32 i, t0, t1, x1, x2, x3, x4; 334 333 335 - x1 = be32_to_cpu(key[0]); 336 - x2 = be32_to_cpu(key[1]); 337 - x3 = be32_to_cpu(key[2]); 338 - x4 = be32_to_cpu(key[3]); 334 + x1 = get_unaligned_be32(&in_key[0]); 335 + x2 = get_unaligned_be32(&in_key[4]); 336 + x3 = get_unaligned_be32(&in_key[8]); 337 + x4 = get_unaligned_be32(&in_key[12]); 339 338 340 339 for (i = 0; i < SEED_NUM_KCONSTANTS; i++) { 341 340 t0 = x1 + x3 - KC[i]; ··· 363 364 static void seed_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 364 365 { 365 366 const struct seed_ctx *ctx = crypto_tfm_ctx(tfm); 366 - const __be32 *src = (const __be32 *)in; 367 - __be32 *dst = (__be32 *)out; 368 367 u32 x1, x2, x3, x4, t0, t1; 369 368 const u32 *ks = ctx->keysched; 370 369 371 - x1 = be32_to_cpu(src[0]); 372 - x2 = be32_to_cpu(src[1]); 373 - x3 = be32_to_cpu(src[2]); 374 - x4 = be32_to_cpu(src[3]); 370 + x1 = get_unaligned_be32(&in[0]); 371 + x2 = get_unaligned_be32(&in[4]); 372 + x3 = get_unaligned_be32(&in[8]); 373 + x4 = get_unaligned_be32(&in[12]); 375 374 376 375 OP(x1, x2, x3, x4, 0); 377 376 OP(x3, x4, x1, x2, 2); ··· 388 391 OP(x1, x2, x3, x4, 28); 389 392 OP(x3, x4, x1, x2, 30); 390 393 391 - dst[0] = cpu_to_be32(x3); 392 - dst[1] = cpu_to_be32(x4); 393 - dst[2] = cpu_to_be32(x1); 394 - dst[3] = cpu_to_be32(x2); 394 + put_unaligned_be32(x3, &out[0]); 395 + put_unaligned_be32(x4, &out[4]); 396 + put_unaligned_be32(x1, &out[8]); 397 + put_unaligned_be32(x2, &out[12]); 395 398 } 396 399 397 400 /* decrypt a block of text */ ··· 399 402 static void seed_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 400 403 { 401 404 const struct seed_ctx *ctx = crypto_tfm_ctx(tfm); 402 - const __be32 *src = (const __be32 *)in; 403 - __be32 *dst = (__be32 *)out; 404 405 u32 x1, x2, x3, x4, t0, t1; 405 406 const u32 *ks = ctx->keysched; 406 407 407 - x1 = be32_to_cpu(src[0]); 408 - x2 = be32_to_cpu(src[1]); 409 - x3 = be32_to_cpu(src[2]); 410 - x4 = be32_to_cpu(src[3]); 408 + x1 = get_unaligned_be32(&in[0]); 409 + x2 = get_unaligned_be32(&in[4]); 410 + x3 = get_unaligned_be32(&in[8]); 411 + x4 = get_unaligned_be32(&in[12]); 411 412 412 413 OP(x1, x2, x3, x4, 30); 413 414 OP(x3, x4, x1, x2, 28); ··· 424 429 OP(x1, x2, x3, x4, 2); 425 430 OP(x3, x4, x1, x2, 0); 426 431 427 - dst[0] = cpu_to_be32(x3); 428 - dst[1] = cpu_to_be32(x4); 429 - dst[2] = cpu_to_be32(x1); 430 - dst[3] = cpu_to_be32(x2); 432 + put_unaligned_be32(x3, &out[0]); 433 + put_unaligned_be32(x4, &out[4]); 434 + put_unaligned_be32(x1, &out[8]); 435 + put_unaligned_be32(x2, &out[12]); 431 436 } 432 437 433 438 ··· 438 443 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 439 444 .cra_blocksize = SEED_BLOCK_SIZE, 440 445 .cra_ctxsize = sizeof(struct seed_ctx), 441 - .cra_alignmask = 3, 442 446 .cra_module = THIS_MODULE, 443 447 .cra_u = { 444 448 .cipher = {