1 C x86_64/camellia-crypt-internal.asm
4 Copyright (C) 2010, Niels Möller
6 This file is part of GNU Nettle.
8 GNU Nettle is free software: you can redistribute it and/or
9 modify it under the terms of either:
11 * the GNU Lesser General Public License as published by the Free
12 Software Foundation; either version 3 of the License, or (at your
13 option) any later version.
17 * the GNU General Public License as published by the Free
18 Software Foundation; either version 2 of the License, or (at your
19 option) any later version.
21 or both in parallel, as here.
23 GNU Nettle is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 General Public License for more details.
28 You should have received copies of the GNU General Public License and
29 the GNU Lesser General Public License along with this program. If
30 not, see http://www.gnu.org/licenses/.
33 C Performance, cycles per block
37 C Camellia-128 415 347
38 C Camellia-256 543 461
42 define(<NKEYS>, <%rdi>)
43 define(<KEYS>, <%rsi>)
44 define(<TABLE>, <%rdx>)
45 define(<LENGTH>, <%rcx>)
51 define(<I1>, <%rbx>) C callee-save
52 define(<KEY>, <%r13>) C callee-save
53 define(<TMP>, <%rbp>) C callee-save
56 define(<IR>, <%r12>) C callee-save
58 define(<SP1110>, <(TABLE,$1,4)>)
59 define(<SP0222>, <1024(TABLE,$1,4)>)
60 define(<SP3033>, <2048(TABLE,$1,4)>)
61 define(<SP4404>, <3072(TABLE,$1,4)>)
63 C ROUND(x, y, key-offset)
66 movzbl LREG($1), XREG(TMP)
67 movl SP1110(TMP), XREG(IR)
68 movzbl HREG($1), XREG(TMP)
69 xorl SP4404(TMP), XREG(IR)
73 movzbl LREG($1), XREG(TMP)
74 movl SP4404(TMP), XREG(IL)
75 movzbl HREG($1), XREG(TMP)
76 xorl SP3033(TMP), XREG(IL)
80 movzbl LREG($1), XREG(TMP)
81 xorl SP3033(TMP), XREG(IR)
82 movzbl HREG($1), XREG(TMP)
83 xorl SP0222(TMP), XREG(IR)
87 movzbl LREG($1), XREG(TMP)
88 xorl SP0222(TMP), XREG(IL)
89 movzbl HREG($1), XREG(TMP)
90 xorl SP1110(TMP), XREG(IL)
95 xorl XREG(IL), XREG(IR)
97 xorl XREG(IR), XREG(IL)
108 andl $2 + 4(KEY), XREG(TMP)
110 C xorl XREG(TMP), XREG($1)
112 movl $2(KEY), XREG(TMP)
113 orl XREG($1), XREG(TMP)
117 C FLINV(x0, key-offset)
119 movl $2(KEY), XREG(TMP)
120 orl XREG($1), XREG(TMP)
125 andl $2 + 4(KEY), XREG(TMP)
127 C xorl XREG(TMP), XREG($1)
131 .file "camellia-crypt-internal.asm"
133 C _camellia_crypt(unsigned nkeys, const uint64_t *keys,
134 C const struct camellia_table *T,
135 C size_t length, uint8_t *dst,
139 PROLOGUE(_nettle_camellia_crypt)
151 C Load data, note that we'll happily do unaligned loads
157 mov XREG(NKEYS), XREG(CNT)
160 C Whitening using first subkey
202 EPILOGUE(_nettle_camellia_crypt)