Coverage Report

Created: 2023-03-26 07:33

/src/nettle/ed448-shake256-sign.c
Line
Count
Source (jump to first uncovered line)
1
/* ed448-shake256-sign.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 "eddsa.h"
38
39
#include "ecc-internal.h"
40
#include "eddsa-internal.h"
41
#include "sha3.h"
42
43
void
44
ed448_shake256_sign (const uint8_t *pub,
45
         const uint8_t *priv,
46
         size_t length, const uint8_t *msg,
47
         uint8_t *signature)
48
0
{
49
0
  const struct ecc_curve *ecc = &_nettle_curve448;
50
0
  const struct ecc_eddsa *eddsa = &_nettle_ed448_shake256;
51
0
  mp_size_t itch = ecc->q.size + _eddsa_sign_itch (ecc);
52
0
  mp_limb_t *scratch = gmp_alloc_limbs (itch);
53
0
#define k2 scratch
54
0
#define scratch_out (scratch + ecc->q.size)
55
0
  struct sha3_256_ctx ctx;
56
0
  uint8_t digest[ED448_SIGNATURE_SIZE];
57
58
0
  sha3_256_init (&ctx);
59
0
  _eddsa_expand_key (ecc, eddsa, &ctx, priv, digest, k2);
60
61
0
  _eddsa_sign (ecc, eddsa, &ctx,
62
0
         pub, digest + ED448_KEY_SIZE, k2,
63
0
         length, msg, signature, scratch_out);
64
65
0
  gmp_free_limbs (scratch, itch);
66
0
#undef k1
67
0
#undef k2
68
0
#undef scratch_out
69
0
}