1 C nettle, low-level cryptographics library
3 C Copyright (C) 2013 Niels Möller
5 C The nettle library is free software; you can redistribute it and/or modify
6 C it under the terms of the GNU Lesser General Public License as published by
7 C the Free Software Foundation; either version 2.1 of the License, or (at your
8 C option) any later version.
10 C The nettle library is distributed in the hope that it will be useful, but
11 C WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 C or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13 C License for more details.
15 C You should have received a copy of the GNU Lesser General Public License
16 C along with the nettle library; see the file COPYING.LIB. If not, write to
17 C the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 define(<ITERS>, <%rsi>)
23 define(<LENGTH>, <%rcx>)
26 define(<XM0>, <%xmm0>)
27 define(<XM1>, <%xmm1>)
28 define(<XM2>, <%xmm2>)
29 define(<XM3>, <%xmm3>)
30 define(<XK0>, <%xmm4>)
31 define(<XK1>, <%xmm5>)
32 define(<XK2>, <%xmm6>)
33 define(<XK3>, <%xmm7>)
34 define(<XT0>, <%xmm8>)
35 define(<XT1>, <%xmm9>)
36 define(<XT2>, <%xmm10>)
37 define(<XT3>, <%xmm11>)
38 define(<XY0>, <%xmm12>)
39 define(<XY1>, <%xmm13>)
41 C Copy [0,1,2,3] to [1,1,3,3]
42 define(<HI2LO>, <pshufd <$>0xf5,>)
44 C FIXME: Would be nice if we could force the key array to be 16-byte
49 C umac_nh_n(uint64_t *out, unsigned n, const uint32_t *key,
50 C unsigned length, const uint8_t *msg)
53 PROLOGUE(_nettle_umac_nh_n)
65 C Leave XK2 untouched, and put permuted keys in XK0, XK1, XT2, XT3
69 punpcklqdq XT2, XK0 C [0,1,4,5]
70 punpckhqdq XT2, XK1 C [2,3,6,7]
72 punpcklqdq XK2, XT2 C [4,5, 8, 9]
73 punpckhqdq XK2, XT3 C [6,7,10,11]
81 pshufd $0xee, XT1, XM3 C [6,7,6,7]
82 pshufd $0x44, XT1, XM2 C [4,5,4,5]
83 pshufd $0xee, XT0, XM1 C [2,3,2,3]
84 pshufd $0x44, XT0, XM0 C [0,1,0,1]
109 punpcklqdq XT2, XK0 C [ 8, 9,12,13]
110 punpckhqdq XT2, XK1 C [10,11,14,15]
113 punpcklqdq XK2, XT2 C [12,13,16,17]
114 punpckhqdq XK2, XT3 C [14,15,18,19]
135 subl $32, XREG(LENGTH)
156 pshufd $0xee, XT1, XM3 C [6,7,6,7]
157 pshufd $0x44, XT1, XM2 C [4,5,4,5]
158 pshufd $0xee, XT0, XM1 C [2,3,2,3]
159 pshufd $0x44, XT0, XM0 C [0,1,0,1]
173 punpcklqdq XK1, XK0 C [0,1,4,5]
174 punpckhqdq XK1, XT0 C [2,3,6,7]
179 punpcklqdq XK2, XK1 C [4,5,8,9]
180 punpckhqdq XK2, XT0 C [6,7,10,11]
197 subl $32, XREG(LENGTH)
204 pshufd $0xe, XY1, XT0
213 C Explode message as [0,1,0,1] [2,3,2,3] [4,5,4,5] [6,7, 6, 7]
214 C Interleave keys as [0,1,4,5] [2,3,6,7] [4,5,8,9] [7,8,10,11]
220 pshufd $0xee, XM1, XM3 C [6,7,6,7]
221 pshufd $0x44, XM1, XM2 C [4,5,4,5]
222 pshufd $0xee, XM0, XM1 C [2,3,2,3]
223 pshufd $0x44, XM0, XM0 C [0,1,0,1]
228 punpcklqdq XK1, XK0 C [0,1,4,5]
229 punpckhqdq XK1, XT0 C [2,3,6,7]
234 punpcklqdq XK2, XK1 C [4,5,8,9]
235 punpckhqdq XK2, XT0 C [6,7,10,11]
252 subl $32, XREG(LENGTH)
262 EPILOGUE(_nettle_umac_nh_n)