1 /* ec-context.h - Private definitions for CONTEXT_TYPE_EC.
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_EC_CONTEXT_H
21 #define GCRY_EC_CONTEXT_H
23 /* This context is used with all our EC functions. */
26 enum gcry_mpi_ec_models model; /* The model describing this curve. */
28 enum ecc_dialects dialect; /* The ECC dialect used with the curve. */
30 int flags; /* Public key flags (not always used). */
32 unsigned int nbits; /* Number of bits. */
34 /* Domain parameters. Note that they may not all be set and if set
35 the MPIs may be flaged as constant. */
36 gcry_mpi_t p; /* Prime specifying the field GF(p). */
37 gcry_mpi_t a; /* First coefficient of the Weierstrass equation. */
38 gcry_mpi_t b; /* Second coefficient of the Weierstrass equation. */
39 gcry_mpi_point_t G; /* Base point (generator). */
40 gcry_mpi_t n; /* Order of G. */
42 /* The actual key. May not be set. */
43 gcry_mpi_point_t Q; /* Public key. */
44 gcry_mpi_t d; /* Private key. */
47 /* This structure is private to mpi/ec.c! */
50 unsigned int a_is_pminus3:1;
51 unsigned int two_inv_p:1;
52 } valid; /* Flags to help setting the helper vars below. */
54 int a_is_pminus3; /* True if A = P - 3. */
58 mpi_barrett_t p_barrett;
60 /* Scratch variables. */
61 gcry_mpi_t scratch[11];
63 /* Helper for fast reduction. */
64 /* int nist_nbits; /\* If this is a NIST curve, the # of bits. *\/ */
65 /* gcry_mpi_t s[10]; */
72 void _gcry_mpi_ec_get_reset (mpi_ec_t ec);
75 /*-- cipher/ecc-curves.c --*/
76 gcry_mpi_t _gcry_ecc_get_mpi (const char *name, mpi_ec_t ec, int copy);
77 gcry_mpi_point_t _gcry_ecc_get_point (const char *name, mpi_ec_t ec);
78 gpg_err_code_t _gcry_ecc_set_mpi (const char *name,
79 gcry_mpi_t newvalue, mpi_ec_t ec);
80 gpg_err_code_t _gcry_ecc_set_point (const char *name,
81 gcry_mpi_point_t newvalue, mpi_ec_t ec);
84 #endif /*GCRY_EC_CONTEXT_H*/