1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Blowfish Cipher Algorithm (x86_64)
5 * Copyright (C) 2011 Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
8 #include <linux/linkage.h>
10 .file "blowfish-x86_64-asm.S"
13 /* structure of crypto context */
15 #define s0 ((16 + 2) * 4)
16 #define s1 ((16 + 2 + (1 * 256)) * 4)
17 #define s2 ((16 + 2 + (2 * 256)) * 4)
18 #define s3 ((16 + 2 + (3 * 256)) * 4)
56 /***********************************************************************
58 ***********************************************************************/
64 movl s0(CTX,RT0,4), RT0d; \
65 addl s1(CTX,RT1,4), RT0d; \
69 xorl s2(CTX,RT1,4), RT0d; \
70 addl s3(CTX,RT2,4), RT0d; \
73 #define add_roundkey_enc(n) \
74 xorq p+4*(n)(CTX), RX0;
76 #define round_enc(n) \
77 add_roundkey_enc(n); \
82 #define add_roundkey_dec(n) \
83 movq p+4*(n-1)(CTX), RT0; \
87 #define round_dec(n) \
88 add_roundkey_dec(n); \
93 #define read_block() \
98 #define write_block() \
102 #define xor_block() \
106 SYM_FUNC_START(__blowfish_enc_blk)
111 * %rcx: bool, if true: xor output
129 add_roundkey_enc(16);
142 SYM_FUNC_END(__blowfish_enc_blk)
144 SYM_FUNC_START(blowfish_dec_blk)
174 SYM_FUNC_END(blowfish_dec_blk)
176 /**********************************************************************
177 4-way blowfish, four blocks parallel
178 **********************************************************************/
180 /* F() for 4-way. Slower when used alone/1-way, but faster when used
181 * parallel/4-way (tested on AMD Phenom II & Intel Xeon E7330).
184 movzbl x ## bh, RT1d; \
185 movzbl x ## bl, RT3d; \
187 movzbl x ## bh, RT0d; \
188 movzbl x ## bl, RT2d; \
190 movl s0(CTX,RT0,4), RT0d; \
191 addl s1(CTX,RT2,4), RT0d; \
192 xorl s2(CTX,RT1,4), RT0d; \
193 addl s3(CTX,RT3,4), RT0d; \
196 #define add_preloaded_roundkey4() \
202 #define preload_roundkey_enc(n) \
203 movq p+4*(n)(CTX), RKEY;
205 #define add_roundkey_enc4(n) \
206 add_preloaded_roundkey4(); \
207 preload_roundkey_enc(n + 2);
209 #define round_enc4(n) \
210 add_roundkey_enc4(n); \
222 #define preload_roundkey_dec(n) \
223 movq p+4*((n)-1)(CTX), RKEY; \
226 #define add_roundkey_dec4(n) \
227 add_preloaded_roundkey4(); \
228 preload_roundkey_dec(n - 2);
230 #define round_dec4(n) \
231 add_roundkey_dec4(n); \
243 #define read_block4() \
260 #define write_block4() \
273 #define xor_block4() \
286 SYM_FUNC_START(__blowfish_enc_blk_4way)
291 * %rcx: bool, if true: xor output
301 preload_roundkey_enc(0);
313 add_preloaded_roundkey4();
333 SYM_FUNC_END(__blowfish_enc_blk_4way)
335 SYM_FUNC_START(blowfish_dec_blk_4way)
348 preload_roundkey_dec(17);
359 add_preloaded_roundkey4();
368 SYM_FUNC_END(blowfish_dec_blk_4way)