Coverage Report

Created: 2025-07-23 06:43

/src/nettle/curve448-mul-g.c
Line
Count
Source
1
/* curve448-mul-g.c
2
3
   Copyright (C) 2017 Daiki Ueno
4
   Copyright (C) 2017 Red Hat, Inc.
5
6
   This file is part of GNU Nettle.
7
8
   GNU Nettle is free software: you can redistribute it and/or
9
   modify it under the terms of either:
10
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.
14
15
   or
16
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.
20
21
   or both in parallel, as here.
22
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.
27
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/.
31
*/
32
33
#if HAVE_CONFIG_H
34
# include "config.h"
35
#endif
36
37
#include <string.h>
38
39
#include "curve448.h"
40
41
#include "ecc.h"
42
#include "ecc-internal.h"
43
44
/* Intended to be compatible with NaCl's crypto_scalarmult_base. */
45
void
46
curve448_mul_g (uint8_t *r, const uint8_t *n)
47
887
{
48
887
  const struct ecc_curve *ecc = &_nettle_curve448;
49
887
  uint8_t t[CURVE448_SIZE];
50
887
  mp_limb_t *scratch;
51
887
  mp_size_t itch;
52
53
1.77k
#define ng scratch
54
3.54k
#define x (scratch + 3*ecc->p.size)
55
1.77k
#define scratch_out (scratch + 4*ecc->p.size)
56
57
887
  memcpy (t, n, sizeof(t));
58
887
  t[0] &= ~3;
59
887
  t[CURVE448_SIZE-1] = (t[CURVE448_SIZE-1] & 0x7f) | 0x80;
60
61
887
  itch = 5*ecc->p.size + ecc->mul_g_itch;
62
887
  scratch = gmp_alloc_limbs (itch);
63
64
887
  mpn_set_base256_le (x, ecc->p.size, t, CURVE448_SIZE);
65
66
887
  ecc_mul_g_eh (ecc, ng, x, scratch_out);
67
887
  curve448_eh_to_x (x, ng, scratch_out);
68
69
887
  mpn_get_base256_le (r, CURVE448_SIZE, x, ecc->p.size);
70
887
  gmp_free_limbs (scratch, itch);
71
887
#undef ng
72
887
#undef x
73
887
#undef scratch_out
74
887
}