Coverage Report

Created: 2024-06-28 06:39

/src/nettle-with-mini-gmp/umac-l3.c
Line
Count
Source
1
/* umac-l3.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 "umac.h"
37
#include "umac-internal.h"
38
39
#include "bswap-internal.h"
40
41
/* 2^36 - 5 */
42
27.5k
#define P 0x0000000FFFFFFFFBULL
43
44
void
45
_nettle_umac_l3_init (unsigned size, uint64_t *k)
46
1.19k
{
47
1.19k
  unsigned i;
48
25.6k
  for (i = 0; i < size; i++)
49
24.4k
    {
50
24.4k
      uint64_t w = k[i];
51
24.4k
      w = bswap64_if_le (w);
52
24.4k
      k[i] = w % P;
53
24.4k
    }
54
1.19k
}
55
56
static uint64_t
57
umac_l3_word (const uint64_t *k, uint64_t w)
58
6.12k
{
59
6.12k
  unsigned i;
60
6.12k
  uint64_t y;
61
62
  /* Since it's easiest to process the input word from the low end,
63
   * loop over keys in reverse order. */
64
65
30.6k
  for (i = y = 0; i < 4; i++, w >>= 16)
66
24.4k
    y += (w & 0xffff) * k[3-i];
67
68
6.12k
  return y;
69
6.12k
}
70
71
uint32_t
72
_nettle_umac_l3 (const uint64_t *key, const uint64_t *m)
73
3.06k
{
74
3.06k
  uint32_t y = (umac_l3_word (key, m[0])
75
3.06k
    + umac_l3_word (key + 4, m[1])) % P;
76
77
3.06k
  return bswap32_if_le (y);
78
3.06k
}