4 Copyright (C) 2013 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/.
34 define(<ITERS>, <%rsi>)
36 define(<LENGTH>, <%rcx>)
39 define(<XM0>, <%xmm0>)
40 define(<XM1>, <%xmm1>)
41 define(<XM2>, <%xmm2>)
42 define(<XM3>, <%xmm3>)
43 define(<XK0>, <%xmm4>)
44 define(<XK1>, <%xmm5>)
45 define(<XK2>, <%xmm6>)
46 define(<XK3>, <%xmm7>)
47 define(<XT0>, <%xmm8>)
48 define(<XT1>, <%xmm9>)
49 define(<XT2>, <%xmm10>)
50 define(<XT3>, <%xmm11>)
51 define(<XY0>, <%xmm12>)
52 define(<XY1>, <%xmm13>)
54 C Copy [0,1,2,3] to [1,1,3,3]
55 define(<HI2LO>, <pshufd <$>0xf5,>)
57 C FIXME: Would be nice if we could force the key array to be 16-byte
62 C umac_nh_n(uint64_t *out, unsigned n, const uint32_t *key,
63 C unsigned length, const uint8_t *msg)
66 PROLOGUE(_nettle_umac_nh_n)
78 C Leave XK2 untouched, and put permuted keys in XK0, XK1, XT2, XT3
82 punpcklqdq XT2, XK0 C [0,1,4,5]
83 punpckhqdq XT2, XK1 C [2,3,6,7]
85 punpcklqdq XK2, XT2 C [4,5, 8, 9]
86 punpckhqdq XK2, XT3 C [6,7,10,11]
94 pshufd $0xee, XT1, XM3 C [6,7,6,7]
95 pshufd $0x44, XT1, XM2 C [4,5,4,5]
96 pshufd $0xee, XT0, XM1 C [2,3,2,3]
97 pshufd $0x44, XT0, XM0 C [0,1,0,1]
122 punpcklqdq XT2, XK0 C [ 8, 9,12,13]
123 punpckhqdq XT2, XK1 C [10,11,14,15]
126 punpcklqdq XK2, XT2 C [12,13,16,17]
127 punpckhqdq XK2, XT3 C [14,15,18,19]
148 subl $32, XREG(LENGTH)
169 pshufd $0xee, XT1, XM3 C [6,7,6,7]
170 pshufd $0x44, XT1, XM2 C [4,5,4,5]
171 pshufd $0xee, XT0, XM1 C [2,3,2,3]
172 pshufd $0x44, XT0, XM0 C [0,1,0,1]
186 punpcklqdq XK1, XK0 C [0,1,4,5]
187 punpckhqdq XK1, XT0 C [2,3,6,7]
192 punpcklqdq XK2, XK1 C [4,5,8,9]
193 punpckhqdq XK2, XT0 C [6,7,10,11]
210 subl $32, XREG(LENGTH)
217 pshufd $0xe, XY1, XT0
226 C Explode message as [0,1,0,1] [2,3,2,3] [4,5,4,5] [6,7, 6, 7]
227 C Interleave keys as [0,1,4,5] [2,3,6,7] [4,5,8,9] [7,8,10,11]
233 pshufd $0xee, XM1, XM3 C [6,7,6,7]
234 pshufd $0x44, XM1, XM2 C [4,5,4,5]
235 pshufd $0xee, XM0, XM1 C [2,3,2,3]
236 pshufd $0x44, XM0, XM0 C [0,1,0,1]
241 punpcklqdq XK1, XK0 C [0,1,4,5]
242 punpckhqdq XK1, XT0 C [2,3,6,7]
247 punpcklqdq XK2, XK1 C [4,5,8,9]
248 punpckhqdq XK2, XT0 C [6,7,10,11]
265 subl $32, XREG(LENGTH)
275 EPILOGUE(_nettle_umac_nh_n)