Coverage Report

Created: 2025-03-18 06:55

/src/nettle/umac-nh-n.c
Line
Count
Source (jump to first uncovered line)
1
/* umac-nh-n.c
2
3
   Copyright (C) 2013 Niels Möller
4
5
   This file is part of GNU Nettle.
6
7
   GNU Nettle is free software: you can redistribute it and/or
8
   modify it under the terms of either:
9
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.
13
14
   or
15
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.
19
20
   or both in parallel, as here.
21
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.
26
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/.
30
*/
31
32
#if HAVE_CONFIG_H
33
# include "config.h"
34
#endif
35
36
#include <assert.h>
37
#include <string.h>
38
39
#include "umac.h"
40
#include "umac-internal.h"
41
#include "macros.h"
42
43
/* For fat builds */
44
#if HAVE_NATIVE_umac_nh_n
45
void
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
49
#endif
50
51
void
52
_nettle_umac_nh_n (uint64_t *out, unsigned n, const uint32_t *key,
53
       unsigned length, const uint8_t *msg)
54
0
{
55
0
  assert (length > 0);
56
0
  assert (length <= 1024);
57
0
  assert (length % 32 == 0);
58
59
0
  memset(out, 0, n*sizeof(*out));
60
  
61
0
  for (;length > 0; length -= 32, msg += 32, key += 8)
62
0
    {
63
0
      uint32_t a0, a1, b0, b1;
64
0
      unsigned i;
65
0
      a0 = LE_READ_UINT32 (msg);
66
0
      a1 = LE_READ_UINT32 (msg + 4);
67
0
      b0 = LE_READ_UINT32 (msg + 16);
68
0
      b1 = LE_READ_UINT32 (msg + 20);
69
0
      for (i = 0; i < n; i++)
70
0
  out[i] += (uint64_t) (a0 + key[0+4*i]) * (b0 + key[4+4*i])
71
0
    + (uint64_t) (a1 + key[1+4*i]) * (b1 + key[5+4*i]);
72
0
      a0 = LE_READ_UINT32 (msg + 8);
73
0
      a1 = LE_READ_UINT32 (msg + 12);
74
0
      b0 = LE_READ_UINT32 (msg + 24);
75
0
      b1 = LE_READ_UINT32 (msg + 28);
76
0
      for (i = 0; i < n; i++)
77
0
  out[i] += (uint64_t) (a0 + key[2+4*i]) * (b0 + key[6+4*i])
78
0
    + (uint64_t) (a1 + key[3+4*i]) * (b1 + key[7+4*i]);      
79
0
    }
80
0
}