Coverage Report

Created: 2026-10-28 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/nettle/ecdsa-verify.c
Line
Count
Source
1
/* ecc-ecdsa-verify.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
/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
33
34
#if HAVE_CONFIG_H
35
# include "config.h"
36
#endif
37
38
#include <assert.h>
39
#include <stdlib.h>
40
41
#include "ecdsa.h"
42
43
#include "gmp-glue.h"
44
45
int
46
ecdsa_verify (const struct ecc_point *pub,
47
        size_t length, const uint8_t *digest,
48
        const struct dsa_signature *signature)
49
325
{
50
325
  mp_limb_t size = ecc_size (pub->ecc);
51
325
  mp_size_t itch = 2*size + ecc_ecdsa_verify_itch (pub->ecc);
52
  /* For ECC_MUL_A_WBITS == 0, at most 1512 bytes. With
53
     ECC_MUL_A_WBITS == 4, currently needs 67 * ecc->size, at most
54
     4824 bytes. Don't use stack allocation for this. */
55
325
  mp_limb_t *scratch;
56
325
  int res;
57
58
646
#define rp scratch
59
646
#define sp (scratch + size)
60
325
#define scratch_out (scratch + 2*size)
61
62
325
  if (mpz_sgn (signature->r) <= 0 || mpz_size (signature->r) > size
63
324
      || mpz_sgn (signature->s) <= 0 || mpz_size (signature->s) > size)
64
2
    return 0;
65
66
323
  scratch = gmp_alloc_limbs (itch);
67
  
68
323
  mpz_limbs_copy (rp, signature->r, size);
69
323
  mpz_limbs_copy (sp, signature->s, size);
70
71
323
  res = ecc_ecdsa_verify (pub->ecc, pub->p, length, digest, rp, sp, scratch_out);
72
73
323
  gmp_free_limbs (scratch, itch);
74
75
323
  return res;
76
325
#undef rp
77
325
#undef sp
78
325
#undef scratch_out
79
325
}