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>
32 .section .rodata.cst16.aegis256_const, "aM", @progbits, 32
35 .byte 0x00, 0x01, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d
36 .byte 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62
38 .byte 0xdb, 0x3d, 0x18, 0x55, 0x6d, 0xc2, 0x2f, 0xf1
39 .byte 0x20, 0x11, 0x31, 0x42, 0x73, 0xb5, 0x28, 0xdd
41 .section .rodata.cst16.aegis256_counter, "aM", @progbits, 16
44 .byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
45 .byte 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
50 * __load_partial: internal ABI
113 ENDPROC(__load_partial)
116 * __store_partial: internal ABI
171 ENDPROC(__store_partial)
175 aesenc STATE0, STATE5
176 aesenc STATE1, STATE0
177 aesenc STATE2, STATE1
178 aesenc STATE3, STATE2
179 aesenc STATE4, STATE3
214 movdqu 0x00(STATEP), STATE0
215 movdqu 0x10(STATEP), STATE1
216 movdqu 0x20(STATEP), STATE2
217 movdqu 0x30(STATEP), STATE3
218 movdqu 0x40(STATEP), STATE4
219 movdqu 0x50(STATEP), STATE5
222 .macro state_store s0 s1 s2 s3 s4 s5
223 movdqu \s5, 0x00(STATEP)
224 movdqu \s0, 0x10(STATEP)
225 movdqu \s1, 0x20(STATEP)
226 movdqu \s2, 0x30(STATEP)
227 movdqu \s3, 0x40(STATEP)
228 movdqu \s4, 0x50(STATEP)
232 state_store STATE0 STATE1 STATE2 STATE3 STATE4 STATE5
236 state_store STATE5 STATE0 STATE1 STATE2 STATE3 STATE4
240 state_store STATE4 STATE5 STATE0 STATE1 STATE2 STATE3
244 state_store STATE3 STATE4 STATE5 STATE0 STATE1 STATE2
248 state_store STATE2 STATE3 STATE4 STATE5 STATE0 STATE1
252 state_store STATE1 STATE2 STATE3 STATE4 STATE5 STATE0
256 * void crypto_aegis256_aesni_init(void *state, const void *key, const void *iv);
258 ENTRY(crypto_aegis256_aesni_init)
262 movdqa 0x00(%rsi), MSG
263 movdqa 0x10(%rsi), T1
268 movdqu 0x00(%rdx), T2
269 movdqu 0x10(%rdx), T3
275 /* load the constants: */
276 movdqa .Laegis256_const_0, STATE3
277 movdqa .Laegis256_const_1, STATE2
281 /* update 10 times with IV and KEY: */
303 ENDPROC(crypto_aegis256_aesni_init)
306 movdq\a (\i * 0x10)(SRC), MSG
314 * void crypto_aegis256_aesni_ad(void *state, unsigned int length,
317 ENTRY(crypto_aegis256_aesni_ad)
386 ENDPROC(crypto_aegis256_aesni_ad)
388 .macro crypt m s0 s1 s2 s3 s4 s5
398 crypt \m STATE0 STATE1 STATE2 STATE3 STATE4 STATE5
402 crypt \m STATE5 STATE0 STATE1 STATE2 STATE3 STATE4
406 crypt \m STATE4 STATE5 STATE0 STATE1 STATE2 STATE3
410 crypt \m STATE3 STATE4 STATE5 STATE0 STATE1 STATE2
414 crypt \m STATE2 STATE3 STATE4 STATE5 STATE0 STATE1
418 crypt \m STATE1 STATE2 STATE3 STATE4 STATE5 STATE0
421 .macro encrypt_block a i
422 movdq\a (\i * 0x10)(SRC), MSG
425 movdq\a T0, (\i * 0x10)(DST)
434 .macro decrypt_block a i
435 movdq\a (\i * 0x10)(SRC), MSG
437 movdq\a MSG, (\i * 0x10)(DST)
447 * void crypto_aegis256_aesni_enc(void *state, unsigned int length,
448 * const void *src, void *dst);
450 ENTRY(crypto_aegis256_aesni_enc)
522 ENDPROC(crypto_aegis256_aesni_enc)
525 * void crypto_aegis256_aesni_enc_tail(void *state, unsigned int length,
526 * const void *src, void *dst);
528 ENTRY(crypto_aegis256_aesni_enc_tail)
533 /* encrypt message: */
547 ENDPROC(crypto_aegis256_aesni_enc_tail)
550 * void crypto_aegis256_aesni_dec(void *state, unsigned int length,
551 * const void *src, void *dst);
553 ENTRY(crypto_aegis256_aesni_dec)
625 ENDPROC(crypto_aegis256_aesni_dec)
628 * void crypto_aegis256_aesni_dec_tail(void *state, unsigned int length,
629 * const void *src, void *dst);
631 ENTRY(crypto_aegis256_aesni_dec_tail)
636 /* decrypt message: */
644 /* mask with byte count: */
650 movdqa .Laegis256_counter, T1
660 ENDPROC(crypto_aegis256_aesni_dec_tail)
663 * void crypto_aegis256_aesni_final(void *state, void *tag_xor,
664 * u64 assoclen, u64 cryptlen);
666 ENTRY(crypto_aegis256_aesni_final)
671 /* prepare length block: */
676 psllq $3, MSG /* multiply by 8 (to get bit count) */
703 ENDPROC(crypto_aegis256_aesni_final)