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: x86/aegis128 - improve assembly function prototypes

Adjust the prototypes of the AEGIS assembly functions:

- Use proper types instead of 'void *', when applicable.

- Move the length parameter to after the buffers it describes rather
than before, to match the usual convention. Also shorten its name to
just len (which is the name used in the assembly code).

- Declare register aliases at the beginning of each function rather than
once per file. This was necessary because len was moved, but also it
allows adding some aliases where raw registers were used before.

- Put assoclen and cryptlen in the correct order when declaring the
finalization function in the .c file.

- Remove the unnecessary "crypto_" prefix.

Reviewed-by: Ondrej Mosnacek <omosnace@redhat.com>
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
8da94b30 af2aff7c

+112 -85
+66 -39
arch/x86/crypto/aegis128-aesni-asm.S
··· 19 19 #define T0 %xmm6 20 20 #define T1 %xmm7 21 21 22 - #define STATEP %rdi 23 - #define LEN %esi 24 - #define SRC %rdx 25 - #define DST %rcx 26 - 27 22 .section .rodata.cst16.aegis128_const, "aM", @progbits, 32 28 23 .align 16 29 24 .Laegis128_const_0: ··· 67 72 * %r9 68 73 */ 69 74 SYM_FUNC_START_LOCAL(__load_partial) 75 + .set LEN, %ecx 76 + .set SRC, %rsi 70 77 xor %r9d, %r9d 71 78 pxor MSG, MSG 72 79 ··· 135 138 * %r10 136 139 */ 137 140 SYM_FUNC_START_LOCAL(__store_partial) 141 + .set LEN, %ecx 142 + .set DST, %rdx 138 143 mov LEN, %r8d 139 144 mov DST, %r9 140 145 ··· 183 184 SYM_FUNC_END(__store_partial) 184 185 185 186 /* 186 - * void crypto_aegis128_aesni_init(void *state, const void *key, const void *iv); 187 + * void aegis128_aesni_init(struct aegis_state *state, 188 + * const struct aegis_block *key, 189 + * const u8 iv[AEGIS128_NONCE_SIZE]); 187 190 */ 188 - SYM_FUNC_START(crypto_aegis128_aesni_init) 191 + SYM_FUNC_START(aegis128_aesni_init) 192 + .set STATEP, %rdi 193 + .set KEYP, %rsi 194 + .set IVP, %rdx 189 195 FRAME_BEGIN 190 196 191 197 /* load IV: */ 192 - movdqu (%rdx), T1 198 + movdqu (IVP), T1 193 199 194 200 /* load key: */ 195 - movdqa (%rsi), KEY 201 + movdqa (KEYP), KEY 196 202 pxor KEY, T1 197 203 movdqa T1, STATE0 198 204 movdqa KEY, STATE3 ··· 230 226 231 227 FRAME_END 232 228 RET 233 - SYM_FUNC_END(crypto_aegis128_aesni_init) 229 + SYM_FUNC_END(aegis128_aesni_init) 234 230 235 231 /* 236 - * void crypto_aegis128_aesni_ad(void *state, unsigned int length, 237 - * const void *data); 232 + * void aegis128_aesni_ad(struct aegis_state *state, const u8 *data, 233 + * unsigned int len); 238 234 */ 239 - SYM_FUNC_START(crypto_aegis128_aesni_ad) 235 + SYM_FUNC_START(aegis128_aesni_ad) 236 + .set STATEP, %rdi 237 + .set SRC, %rsi 238 + .set LEN, %edx 240 239 FRAME_BEGIN 241 240 242 241 cmp $0x10, LEN ··· 341 334 .Lad_out: 342 335 FRAME_END 343 336 RET 344 - SYM_FUNC_END(crypto_aegis128_aesni_ad) 337 + SYM_FUNC_END(aegis128_aesni_ad) 345 338 346 339 .macro encrypt_block s0 s1 s2 s3 s4 i 347 340 movdqu (\i * 0x10)(SRC), MSG ··· 362 355 .endm 363 356 364 357 /* 365 - * void crypto_aegis128_aesni_enc(void *state, unsigned int length, 366 - * const void *src, void *dst); 358 + * void aegis128_aesni_enc(struct aegis_state *state, const u8 *src, u8 *dst, 359 + * unsigned int len); 367 360 */ 368 - SYM_FUNC_START(crypto_aegis128_aesni_enc) 361 + SYM_FUNC_START(aegis128_aesni_enc) 362 + .set STATEP, %rdi 363 + .set SRC, %rsi 364 + .set DST, %rdx 365 + .set LEN, %ecx 369 366 FRAME_BEGIN 370 367 371 368 cmp $0x10, LEN ··· 443 432 .Lenc_out: 444 433 FRAME_END 445 434 RET 446 - SYM_FUNC_END(crypto_aegis128_aesni_enc) 435 + SYM_FUNC_END(aegis128_aesni_enc) 447 436 448 437 /* 449 - * void crypto_aegis128_aesni_enc_tail(void *state, unsigned int length, 450 - * const void *src, void *dst); 438 + * void aegis128_aesni_enc_tail(struct aegis_state *state, const u8 *src, 439 + * u8 *dst, unsigned int len); 451 440 */ 452 - SYM_FUNC_START(crypto_aegis128_aesni_enc_tail) 441 + SYM_FUNC_START(aegis128_aesni_enc_tail) 442 + .set STATEP, %rdi 443 + .set SRC, %rsi 444 + .set DST, %rdx 445 + .set LEN, %ecx 453 446 FRAME_BEGIN 454 447 455 448 /* load the state: */ ··· 487 472 488 473 FRAME_END 489 474 RET 490 - SYM_FUNC_END(crypto_aegis128_aesni_enc_tail) 475 + SYM_FUNC_END(aegis128_aesni_enc_tail) 491 476 492 477 .macro decrypt_block s0 s1 s2 s3 s4 i 493 478 movdqu (\i * 0x10)(SRC), MSG ··· 507 492 .endm 508 493 509 494 /* 510 - * void crypto_aegis128_aesni_dec(void *state, unsigned int length, 511 - * const void *src, void *dst); 495 + * void aegis128_aesni_dec(struct aegis_state *state, const u8 *src, u8 *dst, 496 + * unsigned int len); 512 497 */ 513 - SYM_FUNC_START(crypto_aegis128_aesni_dec) 498 + SYM_FUNC_START(aegis128_aesni_dec) 499 + .set STATEP, %rdi 500 + .set SRC, %rsi 501 + .set DST, %rdx 502 + .set LEN, %ecx 514 503 FRAME_BEGIN 515 504 516 505 cmp $0x10, LEN ··· 588 569 .Ldec_out: 589 570 FRAME_END 590 571 RET 591 - SYM_FUNC_END(crypto_aegis128_aesni_dec) 572 + SYM_FUNC_END(aegis128_aesni_dec) 592 573 593 574 /* 594 - * void crypto_aegis128_aesni_dec_tail(void *state, unsigned int length, 595 - * const void *src, void *dst); 575 + * void aegis128_aesni_dec_tail(struct aegis_state *state, const u8 *src, 576 + * u8 *dst, unsigned int len); 596 577 */ 597 - SYM_FUNC_START(crypto_aegis128_aesni_dec_tail) 578 + SYM_FUNC_START(aegis128_aesni_dec_tail) 579 + .set STATEP, %rdi 580 + .set SRC, %rsi 581 + .set DST, %rdx 582 + .set LEN, %ecx 598 583 FRAME_BEGIN 599 584 600 585 /* load the state: */ ··· 642 619 643 620 FRAME_END 644 621 RET 645 - SYM_FUNC_END(crypto_aegis128_aesni_dec_tail) 622 + SYM_FUNC_END(aegis128_aesni_dec_tail) 646 623 647 624 /* 648 - * void crypto_aegis128_aesni_final(void *state, void *tag_xor, 649 - * unsigned int assoclen, 650 - * unsigned int cryptlen); 625 + * void aegis128_aesni_final(struct aegis_state *state, 626 + * struct aegis_block *tag_xor, 627 + * unsigned int assoclen, unsigned int cryptlen); 651 628 */ 652 - SYM_FUNC_START(crypto_aegis128_aesni_final) 629 + SYM_FUNC_START(aegis128_aesni_final) 630 + .set STATEP, %rdi 631 + .set TAG_XOR, %rsi 632 + .set ASSOCLEN, %edx 633 + .set CRYPTLEN, %ecx 653 634 FRAME_BEGIN 654 635 655 636 /* load the state: */ ··· 664 637 movdqu 0x40(STATEP), STATE4 665 638 666 639 /* prepare length block: */ 667 - movd %edx, MSG 668 - pinsrd $2, %ecx, MSG 640 + movd ASSOCLEN, MSG 641 + pinsrd $2, CRYPTLEN, MSG 669 642 psllq $3, MSG /* multiply by 8 (to get bit count) */ 670 643 671 644 pxor STATE3, MSG ··· 680 653 aegis128_update; pxor MSG, STATE3 681 654 682 655 /* xor tag: */ 683 - movdqu (%rsi), MSG 656 + movdqu (TAG_XOR), MSG 684 657 685 658 pxor STATE0, MSG 686 659 pxor STATE1, MSG ··· 688 661 pxor STATE3, MSG 689 662 pxor STATE4, MSG 690 663 691 - movdqu MSG, (%rsi) 664 + movdqu MSG, (TAG_XOR) 692 665 693 666 FRAME_END 694 667 RET 695 - SYM_FUNC_END(crypto_aegis128_aesni_final) 668 + SYM_FUNC_END(aegis128_aesni_final)
+46 -46
arch/x86/crypto/aegis128-aesni-glue.c
··· 23 23 #define AEGIS128_MIN_AUTH_SIZE 8 24 24 #define AEGIS128_MAX_AUTH_SIZE 16 25 25 26 - asmlinkage void crypto_aegis128_aesni_init(void *state, void *key, void *iv); 27 - 28 - asmlinkage void crypto_aegis128_aesni_ad( 29 - void *state, unsigned int length, const void *data); 30 - 31 - asmlinkage void crypto_aegis128_aesni_enc( 32 - void *state, unsigned int length, const void *src, void *dst); 33 - 34 - asmlinkage void crypto_aegis128_aesni_dec( 35 - void *state, unsigned int length, const void *src, void *dst); 36 - 37 - asmlinkage void crypto_aegis128_aesni_enc_tail( 38 - void *state, unsigned int length, const void *src, void *dst); 39 - 40 - asmlinkage void crypto_aegis128_aesni_dec_tail( 41 - void *state, unsigned int length, const void *src, void *dst); 42 - 43 - asmlinkage void crypto_aegis128_aesni_final( 44 - void *state, void *tag_xor, unsigned int cryptlen, 45 - unsigned int assoclen); 46 - 47 26 struct aegis_block { 48 27 u8 bytes[AEGIS128_BLOCK_SIZE] __aligned(AEGIS128_BLOCK_ALIGN); 49 28 }; ··· 34 55 struct aegis_ctx { 35 56 struct aegis_block key; 36 57 }; 58 + 59 + asmlinkage void aegis128_aesni_init(struct aegis_state *state, 60 + const struct aegis_block *key, 61 + const u8 iv[AEGIS128_NONCE_SIZE]); 62 + 63 + asmlinkage void aegis128_aesni_ad(struct aegis_state *state, const u8 *data, 64 + unsigned int len); 65 + 66 + asmlinkage void aegis128_aesni_enc(struct aegis_state *state, const u8 *src, 67 + u8 *dst, unsigned int len); 68 + 69 + asmlinkage void aegis128_aesni_dec(struct aegis_state *state, const u8 *src, 70 + u8 *dst, unsigned int len); 71 + 72 + asmlinkage void aegis128_aesni_enc_tail(struct aegis_state *state, 73 + const u8 *src, u8 *dst, 74 + unsigned int len); 75 + 76 + asmlinkage void aegis128_aesni_dec_tail(struct aegis_state *state, 77 + const u8 *src, u8 *dst, 78 + unsigned int len); 79 + 80 + asmlinkage void aegis128_aesni_final(struct aegis_state *state, 81 + struct aegis_block *tag_xor, 82 + unsigned int assoclen, 83 + unsigned int cryptlen); 37 84 38 85 static void crypto_aegis128_aesni_process_ad( 39 86 struct aegis_state *state, struct scatterlist *sg_src, ··· 80 75 if (pos > 0) { 81 76 unsigned int fill = AEGIS128_BLOCK_SIZE - pos; 82 77 memcpy(buf.bytes + pos, src, fill); 83 - crypto_aegis128_aesni_ad(state, 84 - AEGIS128_BLOCK_SIZE, 85 - buf.bytes); 78 + aegis128_aesni_ad(state, buf.bytes, 79 + AEGIS128_BLOCK_SIZE); 86 80 pos = 0; 87 81 left -= fill; 88 82 src += fill; 89 83 } 90 84 91 - crypto_aegis128_aesni_ad(state, left, src); 85 + aegis128_aesni_ad(state, src, left); 92 86 93 87 src += left & ~(AEGIS128_BLOCK_SIZE - 1); 94 88 left &= AEGIS128_BLOCK_SIZE - 1; ··· 104 100 105 101 if (pos > 0) { 106 102 memset(buf.bytes + pos, 0, AEGIS128_BLOCK_SIZE - pos); 107 - crypto_aegis128_aesni_ad(state, AEGIS128_BLOCK_SIZE, buf.bytes); 103 + aegis128_aesni_ad(state, buf.bytes, AEGIS128_BLOCK_SIZE); 108 104 } 109 105 } 110 106 ··· 114 110 { 115 111 while (walk->nbytes >= AEGIS128_BLOCK_SIZE) { 116 112 if (enc) 117 - crypto_aegis128_aesni_enc( 118 - state, 119 - round_down(walk->nbytes, 120 - AEGIS128_BLOCK_SIZE), 121 - walk->src.virt.addr, 122 - walk->dst.virt.addr); 113 + aegis128_aesni_enc(state, walk->src.virt.addr, 114 + walk->dst.virt.addr, 115 + round_down(walk->nbytes, 116 + AEGIS128_BLOCK_SIZE)); 123 117 else 124 - crypto_aegis128_aesni_dec( 125 - state, 126 - round_down(walk->nbytes, 127 - AEGIS128_BLOCK_SIZE), 128 - walk->src.virt.addr, 129 - walk->dst.virt.addr); 118 + aegis128_aesni_dec(state, walk->src.virt.addr, 119 + walk->dst.virt.addr, 120 + round_down(walk->nbytes, 121 + AEGIS128_BLOCK_SIZE)); 130 122 skcipher_walk_done(walk, walk->nbytes % AEGIS128_BLOCK_SIZE); 131 123 } 132 124 133 125 if (walk->nbytes) { 134 126 if (enc) 135 - crypto_aegis128_aesni_enc_tail(state, walk->nbytes, 136 - walk->src.virt.addr, 137 - walk->dst.virt.addr); 127 + aegis128_aesni_enc_tail(state, walk->src.virt.addr, 128 + walk->dst.virt.addr, 129 + walk->nbytes); 138 130 else 139 - crypto_aegis128_aesni_dec_tail(state, walk->nbytes, 140 - walk->src.virt.addr, 141 - walk->dst.virt.addr); 131 + aegis128_aesni_dec_tail(state, walk->src.virt.addr, 132 + walk->dst.virt.addr, 133 + walk->nbytes); 142 134 skcipher_walk_done(walk, 0); 143 135 } 144 136 } ··· 186 186 187 187 kernel_fpu_begin(); 188 188 189 - crypto_aegis128_aesni_init(&state, ctx->key.bytes, req->iv); 189 + aegis128_aesni_init(&state, &ctx->key, req->iv); 190 190 crypto_aegis128_aesni_process_ad(&state, req->src, req->assoclen); 191 191 crypto_aegis128_aesni_process_crypt(&state, &walk, enc); 192 - crypto_aegis128_aesni_final(&state, tag_xor, req->assoclen, cryptlen); 192 + aegis128_aesni_final(&state, tag_xor, req->assoclen, cryptlen); 193 193 194 194 kernel_fpu_end(); 195 195 }