Coverage Report

Created: 2024-11-25 06:31

/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
718
{
48
718
  const struct ecc_curve *ecc = &_nettle_curve448;
49
718
  uint8_t t[CURVE448_SIZE];
50
718
  mp_limb_t *scratch;
51
718
  mp_size_t itch;
52
53
1.43k
#define ng scratch
54
2.87k
#define x (scratch + 3*ecc->p.size)
55
1.43k
#define scratch_out (scratch + 4*ecc->p.size)
56
57
718
  memcpy (t, n, sizeof(t));
58
718
  t[0] &= ~3;
59
718
  t[CURVE448_SIZE-1] = (t[CURVE448_SIZE-1] & 0x7f) | 0x80;
60
61
718
  itch = 5*ecc->p.size + ecc->mul_g_itch;
62
718
  scratch = gmp_alloc_limbs (itch);
63
64
718
  mpn_set_base256_le (x, ecc->p.size, t, CURVE448_SIZE);
65
66
718
  ecc_mul_g_eh (ecc, ng, x, scratch_out);
67
718
  curve448_eh_to_x (x, ng, scratch_out);
68
69
718
  mpn_get_base256_le (r, CURVE448_SIZE, x, ecc->p.size);
70
718
  gmp_free_limbs (scratch, itch);
71
718
#undef ng
72
718
#undef x
73
718
#undef scratch_out
74
718
}