Imported Upstream version 1.6.2
[platform/upstream/libgcrypt.git] / src / ec-context.h
1 /* ec-context.h - Private definitions for CONTEXT_TYPE_EC.
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_EC_CONTEXT_H
21 #define GCRY_EC_CONTEXT_H
22
23 /* This context is used with all our EC functions. */
24 struct mpi_ec_ctx_s
25 {
26   enum gcry_mpi_ec_models model; /* The model describing this curve.  */
27
28   enum ecc_dialects dialect;     /* The ECC dialect used with the curve.  */
29
30   int flags;                     /* Public key flags (not always used).  */
31
32   unsigned int nbits;            /* Number of bits.  */
33
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.  */
41
42   /* The actual key.  May not be set.  */
43   gcry_mpi_point_t Q;   /* Public key.   */
44   gcry_mpi_t d;         /* Private key.  */
45
46
47   /* This structure is private to mpi/ec.c! */
48   struct {
49     struct {
50       unsigned int a_is_pminus3:1;
51       unsigned int two_inv_p:1;
52     } valid; /* Flags to help setting the helper vars below.  */
53
54     int a_is_pminus3;  /* True if A = P - 3. */
55
56     gcry_mpi_t two_inv_p;
57
58     mpi_barrett_t p_barrett;
59
60     /* Scratch variables.  */
61     gcry_mpi_t scratch[11];
62
63     /* Helper for fast reduction.  */
64     /*   int nist_nbits; /\* If this is a NIST curve, the # of bits.  *\/ */
65     /*   gcry_mpi_t s[10]; */
66     /*   gcry_mpi_t c; */
67   } t;
68 };
69
70
71 /*-- mpi/ec.c --*/
72 void _gcry_mpi_ec_get_reset (mpi_ec_t ec);
73
74
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);
82
83
84 #endif /*GCRY_EC_CONTEXT_H*/