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 const char *name; /* Name of the curve or NULL. */
42 mpi_point_struct Q; /* Q = [d]G */
55 /* Set the value from S into D. */
57 point_set (mpi_point_t d, mpi_point_t s)
64 #define point_init(a) _gcry_mpi_point_init ((a))
65 #define point_free(a) _gcry_mpi_point_free_parts ((a))
68 /*-- ecc-curves.c --*/
69 gpg_err_code_t _gcry_ecc_fill_in_curve (unsigned int nbits,
71 elliptic_curve_t *curve,
72 unsigned int *r_nbits);
73 gpg_err_code_t _gcry_ecc_update_curve_param (const char *name,
74 enum gcry_mpi_ec_models *model,
75 enum ecc_dialects *dialect,
76 gcry_mpi_t *p, gcry_mpi_t *a,
77 gcry_mpi_t *b, gcry_mpi_t *g,
80 const char *_gcry_ecc_get_curve (gcry_sexp_t keyparms,
82 unsigned int *r_nbits);
83 gcry_sexp_t _gcry_ecc_get_param_sexp (const char *name);
86 void _gcry_ecc_curve_free (elliptic_curve_t *E);
87 elliptic_curve_t _gcry_ecc_curve_copy (elliptic_curve_t E);
88 const char *_gcry_ecc_model2str (enum gcry_mpi_ec_models model);
89 const char *_gcry_ecc_dialect2str (enum ecc_dialects dialect);
90 gcry_mpi_t _gcry_ecc_ec2os (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t p);
91 gcry_err_code_t _gcry_ecc_os2ec (mpi_point_t result, gcry_mpi_t value);
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);
99 gpg_err_code_t _gcry_ecc_ecdsa_sign (gcry_mpi_t input, ECC_secret_key *skey,
100 gcry_mpi_t r, gcry_mpi_t s,
101 int flags, int hashalgo);
102 gpg_err_code_t _gcry_ecc_ecdsa_verify (gcry_mpi_t input, ECC_public_key *pkey,
103 gcry_mpi_t r, gcry_mpi_t s);
105 /*-- ecc-eddsa.c --*/
106 gpg_err_code_t _gcry_ecc_eddsa_recover_x (gcry_mpi_t x, gcry_mpi_t y, int sign,
108 gpg_err_code_t _gcry_ecc_eddsa_encodepoint (mpi_point_t point, mpi_ec_t ctx,
109 gcry_mpi_t x, gcry_mpi_t y,
111 unsigned char **r_buffer,
112 unsigned int *r_buflen);
113 gpg_err_code_t _gcry_ecc_eddsa_ensure_compact (gcry_mpi_t value,
115 gpg_err_code_t _gcry_ecc_eddsa_decodepoint (gcry_mpi_t pk, mpi_ec_t ctx,
117 unsigned char **r_encpk,
118 unsigned int *r_encpklen);
119 gpg_err_code_t _gcry_ecc_eddsa_compute_h_d (unsigned char **r_digest,
120 gcry_mpi_t d, mpi_ec_t ec);
122 gpg_err_code_t _gcry_ecc_eddsa_genkey (ECC_secret_key *sk,
125 gcry_random_level_t random_level);
126 gpg_err_code_t _gcry_ecc_eddsa_sign (gcry_mpi_t input,
128 gcry_mpi_t r_r, gcry_mpi_t s,
129 int hashalgo, gcry_mpi_t pk);
130 gpg_err_code_t _gcry_ecc_eddsa_verify (gcry_mpi_t input,
132 gcry_mpi_t r, gcry_mpi_t s,
133 int hashalgo, gcry_mpi_t pkmpi);
136 gpg_err_code_t _gcry_ecc_gost_sign (gcry_mpi_t input, ECC_secret_key *skey,
137 gcry_mpi_t r, gcry_mpi_t s);
138 gpg_err_code_t _gcry_ecc_gost_verify (gcry_mpi_t input, ECC_public_key *pkey,
139 gcry_mpi_t r, gcry_mpi_t s);
142 #endif /*GCRY_ECC_COMMON_H*/