Coverage Report

Created: 2022-12-08 06:10

/src/libgcrypt/cipher/ecc-common.h
Line
Count
Source (jump to first uncovered line)
1
/* ecc-common.h - Declarations of common ECC code
2
 * Copyright (C) 2013 g10 Code GmbH
3
 *
4
 * This file is part of Libgcrypt.
5
 *
6
 * Libgcrypt is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as
8
 * published by the Free Software Foundation; either version 2.1 of
9
 * the License, or (at your option) any later version.
10
 *
11
 * Libgcrypt is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
#ifndef GCRY_ECC_COMMON_H
21
#define GCRY_ECC_COMMON_H
22
23
24
/* Definition of a curve.  */
25
typedef struct
26
{
27
  enum gcry_mpi_ec_models model;/* The model descrinbing this curve.  */
28
  enum ecc_dialects dialect;    /* The dialect used with the curve.   */
29
  gcry_mpi_t p;         /* Prime specifying the field GF(p).  */
30
  gcry_mpi_t a;         /* First coefficient of the Weierstrass equation.  */
31
  gcry_mpi_t b;         /* Second coefficient of the Weierstrass equation.
32
                           or d as used by Twisted Edwards curves.  */
33
  mpi_point_struct G;   /* Base point (generator).  */
34
  gcry_mpi_t n;         /* Order of G.  */
35
  unsigned int h;       /* Cofactor.  */
36
  const char *name;     /* Name of the curve or NULL.  */
37
} elliptic_curve_t;
38
39
40
41
/* Set the value from S into D.  */
42
static inline void
43
point_set (mpi_point_t d, mpi_point_t s)
44
0
{
45
0
  mpi_set (d->x, s->x);
46
0
  mpi_set (d->y, s->y);
47
0
  mpi_set (d->z, s->z);
48
0
}
Unexecuted instantiation: ecc-curves.c:point_set
Unexecuted instantiation: ecc-ecdh.c:point_set
Unexecuted instantiation: ecc-eddsa.c:point_set
Unexecuted instantiation: ecc-misc.c:point_set
Unexecuted instantiation: ecc.c:point_set
Unexecuted instantiation: ecc-ecdsa.c:point_set
Unexecuted instantiation: ecc-gost.c:point_set
Unexecuted instantiation: ecc-sm2.c:point_set
49
50
48
#define point_init(a)  _gcry_mpi_point_init ((a))
51
48
#define point_free(a)  _gcry_mpi_point_free_parts ((a))
52
53
54
/*-- ecc-curves.c --*/
55
gpg_err_code_t _gcry_ecc_fill_in_curve (unsigned int nbits,
56
                                        const char *name,
57
                                        elliptic_curve_t *curve,
58
                                        unsigned int *r_nbits);
59
gpg_err_code_t _gcry_ecc_update_curve_param (const char *name,
60
                                             enum gcry_mpi_ec_models *model,
61
                                             enum ecc_dialects *dialect,
62
                                             gcry_mpi_t *p, gcry_mpi_t *a,
63
                                             gcry_mpi_t *b, gcry_mpi_t *g,
64
                                             gcry_mpi_t *n);
65
66
const char *_gcry_ecc_get_curve (gcry_sexp_t keyparms,
67
                                 int iterator,
68
                                 unsigned int *r_nbits);
69
gcry_sexp_t _gcry_ecc_get_param_sexp (const char *name);
70
71
/*-- ecc-misc.c --*/
72
void _gcry_ecc_curve_free (elliptic_curve_t *E);
73
elliptic_curve_t _gcry_ecc_curve_copy (elliptic_curve_t E);
74
const char *_gcry_ecc_model2str (enum gcry_mpi_ec_models model);
75
const char *_gcry_ecc_dialect2str (enum ecc_dialects dialect);
76
unsigned char *_gcry_ecc_ec2os_buf (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t p,
77
                                    unsigned int *r_length);
78
gcry_mpi_t   _gcry_ecc_ec2os (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t p);
79
80
mpi_point_t  _gcry_ecc_compute_public (mpi_point_t Q, mpi_ec_t ec);
81
gpg_err_code_t _gcry_ecc_mont_encodepoint (gcry_mpi_t x, unsigned int nbits,
82
                                           int with_prefix,
83
                                           unsigned char **r_buffer,
84
                                           unsigned int *r_buflen);
85
86
87
/*-- ecc.c --*/
88
89
/*-- ecc-ecdsa.c --*/
90
gpg_err_code_t _gcry_ecc_ecdsa_sign (gcry_mpi_t input, gcry_mpi_t k, mpi_ec_t ec,
91
                                     gcry_mpi_t r, gcry_mpi_t s,
92
                                     int flags, int hashalgo);
93
gpg_err_code_t _gcry_ecc_ecdsa_verify (gcry_mpi_t input, mpi_ec_t ec,
94
                                       gcry_mpi_t r, gcry_mpi_t s,
95
                                       int flags, int hashalgo);
96
97
/*-- ecc-eddsa.c --*/
98
gpg_err_code_t _gcry_ecc_eddsa_recover_x (gcry_mpi_t x, gcry_mpi_t y, int sign,
99
                                          mpi_ec_t ec);
100
gpg_err_code_t _gcry_ecc_eddsa_encodepoint (mpi_point_t point, mpi_ec_t ctx,
101
                                            gcry_mpi_t x, gcry_mpi_t y,
102
                                            int with_prefix,
103
                                            unsigned char **r_buffer,
104
                                            unsigned int *r_buflen);
105
gpg_err_code_t _gcry_ecc_eddsa_ensure_compact (gcry_mpi_t value,
106
                                               unsigned int nbits);
107
108
109
gpg_err_code_t _gcry_ecc_eddsa_compute_h_d (unsigned char **r_digest,
110
                                            mpi_ec_t ec);
111
112
gpg_err_code_t _gcry_ecc_eddsa_genkey (mpi_ec_t ec, int flags);
113
gpg_err_code_t _gcry_ecc_eddsa_sign (gcry_mpi_t input,
114
                                     mpi_ec_t ec,
115
                                     gcry_mpi_t r_r, gcry_mpi_t s,
116
                                     struct pk_encoding_ctx *ctx);
117
gpg_err_code_t _gcry_ecc_eddsa_verify (gcry_mpi_t input,
118
                                       mpi_ec_t ec,
119
                                       gcry_mpi_t r, gcry_mpi_t s,
120
                                       struct pk_encoding_ctx *ctx);
121
void reverse_buffer (unsigned char *buffer, unsigned int length);
122
123
124
/*-- ecc-gost.c --*/
125
gpg_err_code_t _gcry_ecc_gost_sign (gcry_mpi_t input, mpi_ec_t ec,
126
                                    gcry_mpi_t r, gcry_mpi_t s);
127
gpg_err_code_t _gcry_ecc_gost_verify (gcry_mpi_t input, mpi_ec_t ec,
128
                                      gcry_mpi_t r, gcry_mpi_t s);
129
130
131
/*-- ecc-sm2.c --*/
132
gpg_err_code_t _gcry_ecc_sm2_encrypt (gcry_sexp_t *r_ciph,
133
                                      gcry_mpi_t input, mpi_ec_t ec);
134
gpg_err_code_t _gcry_ecc_sm2_decrypt (gcry_sexp_t *r_plain,
135
                                      gcry_sexp_t data_list, mpi_ec_t ec);
136
gpg_err_code_t _gcry_ecc_sm2_sign (gcry_mpi_t input, mpi_ec_t ec,
137
                                   gcry_mpi_t r, gcry_mpi_t s,
138
                                   int flags, int hashalgo);
139
gpg_err_code_t _gcry_ecc_sm2_verify (gcry_mpi_t input, mpi_ec_t ec,
140
                                     gcry_mpi_t r, gcry_mpi_t s);
141
142
143
#endif /*GCRY_ECC_COMMON_H*/