1 C -*- mode: asm; asm-comment-char: ?C; -*-
2 C nettle, low-level cryptographics library
4 C Copyright (C) 2010, Niels Möller
6 C The nettle library is free software; you can redistribute it and/or modify
7 C it under the terms of the GNU Lesser General Public License as published by
8 C the Free Software Foundation; either version 2.1 of the License, or (at your
9 C option) any later version.
11 C The nettle library is distributed in the hope that it will be useful, but
12 C WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 C or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 C License for more details.
16 C You should have received a copy of the GNU Lesser General Public License
17 C along with the nettle library; see the file COPYING.LIB. If not, write to
18 C the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 C Camellia state, 128-bit value in little endian order.
24 C L0, H0 corresponds to D1 in the spec and i0 in the C implementation.
25 C while L1, H1 corresponds to D2/i1.
37 define(<FRAME_L0>, <(%esp)>)
38 define(<FRAME_H0>, <4(%esp)>)
39 define(<FRAME_L1>, <8(%esp)>)
40 define(<FRAME_H1>, <12(%esp)>)
41 define(<FRAME_CNT>, <16(%esp)>)
44 define(<FRAME_CTX>, <40(%esp)>)
45 define(<FRAME_TABLE>, <44(%esp)>)
46 define(<FRAME_LENGTH>, <48(%esp)>)
47 define(<FRAME_DST>, <52(%esp)>)
48 define(<FRAME_SRC>, <56(%esp)>)
50 define(<SP1110>, <(T,$1,4)>)
51 define(<SP0222>, <1024(T,$1,4)>)
52 define(<SP3033>, <2048(T,$1,4)>)
53 define(<SP4404>, <3072(T,$1,4)>)
55 C ROUND(xl, xh, yl, yh, key-offset)
56 C xl and xh are rotated 16 bits at the end
57 C yl and yh are read from stack, and left in registers
92 C Six rounds, with inputs and outputs in registers.
99 ROUND(L0,H0,<L1>,<H1>,0)
102 ROUND(L1,H1,<L0>,<H0>,8)
105 ROUND(L0,H0,<L1>,<H1>,16)
108 ROUND(L1,H1,<L0>,<H0>,24)
111 ROUND(L0,H0,<L1>,<H1>,32)
112 ROUND(L1,H1,<L0>,<H0>,40)
117 C FL(x0, x1, key-offset)
119 movl $3 + 4(KEY), TMP
127 C FLINV(x0, x1, key-offset)
132 movl $3 + 4(KEY), TMP
138 .file "camellia-encrypt-internal.asm"
140 C _camellia_crypt(struct camellia_context *ctx,
141 C const struct camellia_table *T,
142 C unsigned length, uint8_t *dst,
146 PROLOGUE(_nettle_camellia_crypt)
147 C save all registers that need to be saved
148 pushl %ebx C 32(%esp)
149 pushl %ebp C 28(%esp)
150 pushl %esi C 24(%esp)
151 pushl %edi C 20(%esp)
155 movl FRAME_LENGTH, %ebp
160 C Load data, note that we'll happily do unaligned loads
175 C Whitening using first subkey
203 subl $16, FRAME_LENGTH
213 EPILOGUE(_nettle_camellia_crypt)