3 Copyright (C) 2013 Niels Möller
5 This file is part of GNU Nettle.
7 GNU Nettle is free software: you can redistribute it and/or
8 modify it under the terms of either:
10 * the GNU Lesser General Public License as published by the Free
11 Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
16 * the GNU General Public License as published by the Free
17 Software Foundation; either version 2 of the License, or (at your
18 option) any later version.
20 or both in parallel, as here.
22 GNU Nettle is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 General Public License for more details.
27 You should have received copies of the GNU General Public License and
28 the GNU Lesser General Public License along with this program. If
29 not, see http://www.gnu.org/licenses/.
40 #include "umac-internal.h"
44 #if HAVE_NATIVE_umac_nh_n
46 _nettle_umac_nh_n_c (uint64_t *out, unsigned n, const uint32_t *key,
47 unsigned length, const uint8_t *msg);
48 #define _nettle_umac_nh_n _nettle_umac_nh_n_c
52 _umac_nh_n (uint64_t *out, unsigned n, const uint32_t *key,
53 unsigned length, const uint8_t *msg)
56 assert (length <= 1024);
57 assert (length % 32 == 0);
59 memset(out, 0, n*sizeof(*out));
61 for (;length > 0; length -= 32, msg += 32, key += 8)
63 uint32_t a0, a1, b0, b1;
65 a0 = LE_READ_UINT32 (msg);
66 a1 = LE_READ_UINT32 (msg + 4);
67 b0 = LE_READ_UINT32 (msg + 16);
68 b1 = LE_READ_UINT32 (msg + 20);
69 for (i = 0; i < n; i++)
70 out[i] += (uint64_t) (a0 + key[0+4*i]) * (b0 + key[4+4*i])
71 + (uint64_t) (a1 + key[1+4*i]) * (b1 + key[5+4*i]);
72 a0 = LE_READ_UINT32 (msg + 8);
73 a1 = LE_READ_UINT32 (msg + 12);
74 b0 = LE_READ_UINT32 (msg + 24);
75 b1 = LE_READ_UINT32 (msg + 28);
76 for (i = 0; i < n; i++)
77 out[i] += (uint64_t) (a0 + key[2+4*i]) * (b0 + key[6+4*i])
78 + (uint64_t) (a1 + key[3+4*i]) * (b1 + key[7+4*i]);