1 C x86/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/.
35 C Camellia state, 128-bit value in little endian order.
36 C L0, H0 corresponds to D1 in the spec and i0 in the C implementation.
37 C while L1, H1 corresponds to D2/i1.
49 define(<FRAME_L0>, <(%esp)>)
50 define(<FRAME_H0>, <4(%esp)>)
51 define(<FRAME_L1>, <8(%esp)>)
52 define(<FRAME_H1>, <12(%esp)>)
53 define(<FRAME_CNT>, <16(%esp)>)
56 define(<FRAME_NKEYS>, <40(%esp)>)
57 define(<FRAME_KEYS>, <44(%esp)>)
58 define(<FRAME_TABLE>, <48(%esp)>)
59 define(<FRAME_LENGTH>, <52(%esp)>)
60 define(<FRAME_DST>, <56(%esp)>)
61 define(<FRAME_SRC>, <60(%esp)>)
63 define(<SP1110>, <(T,$1,4)>)
64 define(<SP0222>, <1024(T,$1,4)>)
65 define(<SP3033>, <2048(T,$1,4)>)
66 define(<SP4404>, <3072(T,$1,4)>)
68 C ROUND(xl, xh, yl, yh, key-offset)
69 C xl and xh are rotated 16 bits at the end
70 C yl and yh are read from stack, and left in registers
105 C Six rounds, with inputs and outputs in registers.
112 ROUND(L0,H0,<L1>,<H1>,0)
115 ROUND(L1,H1,<L0>,<H0>,8)
118 ROUND(L0,H0,<L1>,<H1>,16)
121 ROUND(L1,H1,<L0>,<H0>,24)
124 ROUND(L0,H0,<L1>,<H1>,32)
125 ROUND(L1,H1,<L0>,<H0>,40)
130 C FL(x0, x1, key-offset)
132 movl $3 + 4(KEY), TMP
140 C FLINV(x0, x1, key-offset)
145 movl $3 + 4(KEY), TMP
151 .file "camellia-crypt-internal.asm"
153 C _camellia_crypt(unsigned nkeys, const uint64_t *keys,
154 C const struct camellia_table *T,
155 C size_t length, uint8_t *dst,
159 PROLOGUE(_nettle_camellia_crypt)
160 C save all registers that need to be saved
161 pushl %ebx C 32(%esp)
162 pushl %ebp C 28(%esp)
163 pushl %esi C 24(%esp)
164 pushl %edi C 20(%esp)
168 movl FRAME_LENGTH, %ebp
173 C Load data, note that we'll happily do unaligned loads
185 movl FRAME_NKEYS, TMP
215 subl $16, FRAME_LENGTH
225 EPILOGUE(_nettle_camellia_crypt)