1 /* ecc-common.h - Declarations of common ECC code
2 * Copyright (C) 2013 g10 Code GmbH
4 * This file is part of Libgcrypt.
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.
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.
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/>.
20 #ifndef GCRY_ECC_COMMON_H
21 #define GCRY_ECC_COMMON_H
24 /* Definition of a curve. */
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 gcry_mpi_t h; /* Cofactor. */
36 const char *name; /* Name of the curve or NULL. */
43 mpi_point_struct Q; /* Q = [d]G */
56 /* Set the value from S into D. */
58 point_set (mpi_point_t d, mpi_point_t s)
65 #define point_init(a) _gcry_mpi_point_init ((a))
66 #define point_free(a) _gcry_mpi_point_free_parts ((a))
69 /*-- ecc-curves.c --*/
70 gpg_err_code_t _gcry_ecc_fill_in_curve (unsigned int nbits,
72 elliptic_curve_t *curve,
73 unsigned int *r_nbits);
74 gpg_err_code_t _gcry_ecc_update_curve_param (const char *name,
75 enum gcry_mpi_ec_models *model,
76 enum ecc_dialects *dialect,
77 gcry_mpi_t *p, gcry_mpi_t *a,
78 gcry_mpi_t *b, gcry_mpi_t *g,
79 gcry_mpi_t *n, gcry_mpi_t *h);
81 const char *_gcry_ecc_get_curve (gcry_sexp_t keyparms,
83 unsigned int *r_nbits);
84 gcry_sexp_t _gcry_ecc_get_param_sexp (const char *name);
87 void _gcry_ecc_curve_free (elliptic_curve_t *E);
88 elliptic_curve_t _gcry_ecc_curve_copy (elliptic_curve_t E);
89 const char *_gcry_ecc_model2str (enum gcry_mpi_ec_models model);
90 const char *_gcry_ecc_dialect2str (enum ecc_dialects dialect);
91 gcry_mpi_t _gcry_ecc_ec2os (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t p);
93 mpi_point_t _gcry_ecc_compute_public (mpi_point_t Q, mpi_ec_t ec,
94 mpi_point_t G, gcry_mpi_t d);
100 gpg_err_code_t _gcry_ecc_ecdsa_sign (gcry_mpi_t input, ECC_secret_key *skey,
101 gcry_mpi_t r, gcry_mpi_t s,
102 int flags, int hashalgo);
103 gpg_err_code_t _gcry_ecc_ecdsa_verify (gcry_mpi_t input, ECC_public_key *pkey,
104 gcry_mpi_t r, gcry_mpi_t s);
106 /*-- ecc-eddsa.c --*/
107 gpg_err_code_t _gcry_ecc_eddsa_recover_x (gcry_mpi_t x, gcry_mpi_t y, int sign,
109 gpg_err_code_t _gcry_ecc_eddsa_encodepoint (mpi_point_t point, mpi_ec_t ctx,
110 gcry_mpi_t x, gcry_mpi_t y,
112 unsigned char **r_buffer,
113 unsigned int *r_buflen);
114 gpg_err_code_t _gcry_ecc_eddsa_ensure_compact (gcry_mpi_t value,
118 gpg_err_code_t _gcry_ecc_eddsa_compute_h_d (unsigned char **r_digest,
119 gcry_mpi_t d, mpi_ec_t ec);
121 gpg_err_code_t _gcry_ecc_eddsa_genkey (ECC_secret_key *sk,
125 gpg_err_code_t _gcry_ecc_eddsa_sign (gcry_mpi_t input,
127 gcry_mpi_t r_r, gcry_mpi_t s,
128 int hashalgo, gcry_mpi_t pk);
129 gpg_err_code_t _gcry_ecc_eddsa_verify (gcry_mpi_t input,
131 gcry_mpi_t r, gcry_mpi_t s,
132 int hashalgo, gcry_mpi_t pkmpi);
135 gpg_err_code_t _gcry_ecc_gost_sign (gcry_mpi_t input, ECC_secret_key *skey,
136 gcry_mpi_t r, gcry_mpi_t s);
137 gpg_err_code_t _gcry_ecc_gost_verify (gcry_mpi_t input, ECC_public_key *pkey,
138 gcry_mpi_t r, gcry_mpi_t s);
141 #endif /*GCRY_ECC_COMMON_H*/