2 * AES-NI + SSE2 implementation of AEGIS-128L
4 * Copyright (c) 2017-2018 Ondrej Mosnacek <omosnacek@gmail.com>
5 * Copyright (C) 2017-2018 Red Hat, Inc. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
12 #include <linux/linkage.h>
13 #include <asm/frame.h>
35 .section .rodata.cst16.aegis128l_const, "aM", @progbits, 32
38 .byte 0x00, 0x01, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d
39 .byte 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62
41 .byte 0xdb, 0x3d, 0x18, 0x55, 0x6d, 0xc2, 0x2f, 0xf1
42 .byte 0x20, 0x11, 0x31, 0x42, 0x73, 0xb5, 0x28, 0xdd
44 .section .rodata.cst16.aegis128l_counter, "aM", @progbits, 16
47 .byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
48 .byte 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
50 .byte 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
51 .byte 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
56 * __load_partial: internal ABI
61 * MSG0 - first message block
62 * MSG1 - second message block
129 ENDPROC(__load_partial)
132 * __store_partial: internal ABI
137 * T0 - first message block
138 * T1 - second message block
198 ENDPROC(__store_partial)
202 aesenc STATE0, STATE7
203 aesenc STATE1, STATE0
204 aesenc STATE2, STATE1
205 aesenc STATE3, STATE2
206 aesenc STATE4, STATE3
207 aesenc STATE5, STATE4
208 aesenc STATE6, STATE5
261 movdqu 0x00(STATEP), STATE0
262 movdqu 0x10(STATEP), STATE1
263 movdqu 0x20(STATEP), STATE2
264 movdqu 0x30(STATEP), STATE3
265 movdqu 0x40(STATEP), STATE4
266 movdqu 0x50(STATEP), STATE5
267 movdqu 0x60(STATEP), STATE6
268 movdqu 0x70(STATEP), STATE7
271 .macro state_store s0 s1 s2 s3 s4 s5 s6 s7
272 movdqu \s7, 0x00(STATEP)
273 movdqu \s0, 0x10(STATEP)
274 movdqu \s1, 0x20(STATEP)
275 movdqu \s2, 0x30(STATEP)
276 movdqu \s3, 0x40(STATEP)
277 movdqu \s4, 0x50(STATEP)
278 movdqu \s5, 0x60(STATEP)
279 movdqu \s6, 0x70(STATEP)
283 state_store STATE0 STATE1 STATE2 STATE3 STATE4 STATE5 STATE6 STATE7
287 state_store STATE7 STATE0 STATE1 STATE2 STATE3 STATE4 STATE5 STATE6
291 state_store STATE6 STATE7 STATE0 STATE1 STATE2 STATE3 STATE4 STATE5
295 state_store STATE5 STATE6 STATE7 STATE0 STATE1 STATE2 STATE3 STATE4
299 state_store STATE4 STATE5 STATE6 STATE7 STATE0 STATE1 STATE2 STATE3
303 state_store STATE3 STATE4 STATE5 STATE6 STATE7 STATE0 STATE1 STATE2
307 state_store STATE2 STATE3 STATE4 STATE5 STATE6 STATE7 STATE0 STATE1
311 state_store STATE1 STATE2 STATE3 STATE4 STATE5 STATE6 STATE7 STATE0
315 * void crypto_aegis128l_aesni_init(void *state, const void *key, const void *iv);
317 ENTRY(crypto_aegis128l_aesni_init)
333 /* load the constants: */
334 movdqa .Laegis128l_const_0, STATE2
335 movdqa .Laegis128l_const_1, STATE1
336 movdqa STATE1, STATE3
341 /* update 10 times with IV and KEY: */
357 ENDPROC(crypto_aegis128l_aesni_init)
360 movdq\a (\i * 0x20 + 0x00)(SRC), MSG0
361 movdq\a (\i * 0x20 + 0x10)(SRC), MSG1
369 * void crypto_aegis128l_aesni_ad(void *state, unsigned int length,
372 ENTRY(crypto_aegis128l_aesni_ad)
455 ENDPROC(crypto_aegis128l_aesni_ad)
457 .macro crypt m0 m1 s0 s1 s2 s3 s4 s5 s6 s7
472 crypt \m0 \m1 STATE0 STATE1 STATE2 STATE3 STATE4 STATE5 STATE6 STATE7
476 crypt \m0 \m1 STATE7 STATE0 STATE1 STATE2 STATE3 STATE4 STATE5 STATE6
480 crypt \m0 \m1 STATE6 STATE7 STATE0 STATE1 STATE2 STATE3 STATE4 STATE5
484 crypt \m0 \m1 STATE5 STATE6 STATE7 STATE0 STATE1 STATE2 STATE3 STATE4
488 crypt \m0 \m1 STATE4 STATE5 STATE6 STATE7 STATE0 STATE1 STATE2 STATE3
492 crypt \m0 \m1 STATE3 STATE4 STATE5 STATE6 STATE7 STATE0 STATE1 STATE2
496 crypt \m0 \m1 STATE2 STATE3 STATE4 STATE5 STATE6 STATE7 STATE0 STATE1
500 crypt \m0 \m1 STATE1 STATE2 STATE3 STATE4 STATE5 STATE6 STATE7 STATE0
503 .macro encrypt_block a i
504 movdq\a (\i * 0x20 + 0x00)(SRC), MSG0
505 movdq\a (\i * 0x20 + 0x10)(SRC), MSG1
509 movdq\a T0, (\i * 0x20 + 0x00)(DST)
510 movdq\a T1, (\i * 0x20 + 0x10)(DST)
519 .macro decrypt_block a i
520 movdq\a (\i * 0x20 + 0x00)(SRC), MSG0
521 movdq\a (\i * 0x20 + 0x10)(SRC), MSG1
523 movdq\a MSG0, (\i * 0x20 + 0x00)(DST)
524 movdq\a MSG1, (\i * 0x20 + 0x10)(DST)
534 * void crypto_aegis128l_aesni_enc(void *state, unsigned int length,
535 * const void *src, void *dst);
537 ENTRY(crypto_aegis128l_aesni_enc)
623 ENDPROC(crypto_aegis128l_aesni_enc)
626 * void crypto_aegis128l_aesni_enc_tail(void *state, unsigned int length,
627 * const void *src, void *dst);
629 ENTRY(crypto_aegis128l_aesni_enc_tail)
634 /* encrypt message: */
649 ENDPROC(crypto_aegis128l_aesni_enc_tail)
652 * void crypto_aegis128l_aesni_dec(void *state, unsigned int length,
653 * const void *src, void *dst);
655 ENTRY(crypto_aegis128l_aesni_dec)
741 ENDPROC(crypto_aegis128l_aesni_dec)
744 * void crypto_aegis128l_aesni_dec_tail(void *state, unsigned int length,
745 * const void *src, void *dst);
747 ENTRY(crypto_aegis128l_aesni_dec_tail)
752 /* decrypt message: */
761 /* mask with byte count: */
768 movdqa .Laegis128l_counter0, T2
769 movdqa .Laegis128l_counter1, T3
781 ENDPROC(crypto_aegis128l_aesni_dec_tail)
784 * void crypto_aegis128l_aesni_final(void *state, void *tag_xor,
785 * u64 assoclen, u64 cryptlen);
787 ENTRY(crypto_aegis128l_aesni_final)
792 /* prepare length block: */
797 psllq $3, MSG0 /* multiply by 8 (to get bit count) */
826 ENDPROC(crypto_aegis128l_aesni_final)