Coverage Report

Created: 2026-02-09 06:47

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
9.60k
{
50
9.60k
  mp_limb_t size = ecc_size (pub->ecc);
51
9.60k
  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
9.60k
  mp_limb_t *scratch;
56
9.60k
  int res;
57
58
19.1k
#define rp scratch
59
19.1k
#define sp (scratch + size)
60
9.60k
#define scratch_out (scratch + 2*size)
61
62
9.60k
  if (mpz_sgn (signature->r) <= 0 || mpz_size (signature->r) > size
63
9.59k
      || mpz_sgn (signature->s) <= 0 || mpz_size (signature->s) > size)
64
8
    return 0;
65
66
9.59k
  scratch = gmp_alloc_limbs (itch);
67
  
68
9.59k
  mpz_limbs_copy (rp, signature->r, size);
69
9.59k
  mpz_limbs_copy (sp, signature->s, size);
70
71
9.59k
  res = ecc_ecdsa_verify (pub->ecc, pub->p, length, digest, rp, sp, scratch_out);
72
73
9.59k
  gmp_free_limbs (scratch, itch);
74
75
9.59k
  return res;
76
9.60k
#undef rp
77
9.60k
#undef sp
78
9.60k
#undef scratch_out
79
9.60k
}