2 * Blowfish Cipher Algorithm (x86_64)
4 * Copyright (C) 2011 Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 .file "blowfish-x86_64-asm.S"
26 /* structure of crypto context */
28 #define s0 ((16 + 2) * 4)
29 #define s1 ((16 + 2 + (1 * 256)) * 4)
30 #define s2 ((16 + 2 + (2 * 256)) * 4)
31 #define s3 ((16 + 2 + (3 * 256)) * 4)
75 /***********************************************************************
77 ***********************************************************************/
80 movzbl x ## bh, RT0d; \
81 movzbl x ## bl, RT1d; \
83 movl s0(CTX,RT0,4), k ## d; \
84 addl s1(CTX,RT1,4), k ## d; \
85 movzbl x ## bh, RT0d; \
86 movzbl x ## bl, RT1d; \
88 xorl s2(CTX,RT0,4), k ## d; \
89 addl s3(CTX,RT1,4), k ## d; \
92 #define add_roundkey_enc(n) \
93 xorq p+4*(n)(CTX), RX0;
95 #define round_enc(n) \
96 add_roundkey_enc(n); \
101 #define round_final_enc(n) \
102 xorq p+4*(n)(CTX), RX0;
104 #define add_roundkey_dec(n) \
105 movq p+4*(n-1)(CTX), RT0; \
109 #define round_dec(n) \
110 add_roundkey_dec(n); \
115 #define read_block() \
120 #define write_block() \
124 #define xor_block() \
129 .global __blowfish_enc_blk
130 .type __blowfish_enc_blk,@function;
155 add_roundkey_enc(16);
177 .global blowfish_dec_blk
178 .type blowfish_dec_blk,@function;
211 /**********************************************************************
212 4-way blowfish, four blocks parallel
213 **********************************************************************/
214 #define add_preloaded_roundkey4() \
220 #define preload_roundkey_enc(n) \
221 movq p+4*(n)(CTX), RKEY;
223 #define add_roundkey_enc4(n) \
224 add_preloaded_roundkey4(); \
225 preload_roundkey_enc(n + 2);
227 #define round_enc4(n) \
228 add_roundkey_enc4(n); \
240 #define preload_roundkey_dec(n) \
241 movq p+4*((n)-1)(CTX), RKEY; \
244 #define add_roundkey_dec4(n) \
245 add_preloaded_roundkey4(); \
246 preload_roundkey_dec(n - 2);
248 #define round_dec4(n) \
249 add_roundkey_dec4(n); \
261 #define read_block4() \
278 #define write_block4() \
291 #define xor_block4() \
305 .global __blowfish_enc_blk_4way
306 .type __blowfish_enc_blk_4way,@function;
308 __blowfish_enc_blk_4way:
317 preload_roundkey_enc(0);
333 add_preloaded_roundkey4();
356 .global blowfish_dec_blk_4way
357 .type blowfish_dec_blk_4way,@function;
359 blowfish_dec_blk_4way:
367 preload_roundkey_dec(17);
382 add_preloaded_roundkey4();