summaryrefslogtreecommitdiff
path: root/lib/nettle/gost/ecc-gost256cpa.c
blob: 74ea4d2685f175a337b95e94447d6c914ab3d2e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* ecc-gost256cpa.c

   Compile time constant (but machine dependent) tables.

   Copyright (C) 2013, 2014 Niels Möller

   This file is part of GNU Nettle.

   GNU Nettle is free software: you can redistribute it and/or
   modify it under the terms of either:

     * the GNU Lesser General Public License as published by the Free
       Software Foundation; either version 3 of the License, or (at your
       option) any later version.

   or

     * the GNU General Public License as published by the Free
       Software Foundation; either version 2 of the License, or (at your
       option) any later version.

   or both in parallel, as here.

   GNU Nettle is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received copies of the GNU General Public License and
   the GNU Lesser General Public License along with this program.  If
   not, see https://www.gnu.org/licenses/.
*/

/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */

#if HAVE_CONFIG_H
# include "config.h"
#endif

#include <gnutls_int.h>

#include <nettle/ecc.h>
#include "ecc-internal.h"
#include "ecc-gost-curve.h"

#define USE_REDC (ECC_REDC_SIZE != 0)

#if GMP_NUMB_BITS == 32
#include "ecc-gost256cpa-32.h"
#elif GMP_NUMB_BITS == 64
#include "ecc-gost256cpa-64.h"
#else
#error unsupported configuration
#endif

#if ECC_REDC_SIZE > 0
#  define ecc_256_redc ecc_pp1_redc
#elif ECC_REDC_SIZE == 0
#  define ecc_256_redc NULL
#else
# error Configuration error
#endif

#define ecc_256_modp ecc_mod
#define ecc_256_modq ecc_mod

static const struct ecc_curve _gnutls_gost_gc256b =
{
  {
    256,
    ECC_LIMB_SIZE,
    ECC_BMODP_SIZE,
    ECC_REDC_SIZE,
    ECC_MOD_INV_ITCH (ECC_LIMB_SIZE),
    0,

    ecc_p,
    ecc_Bmodp,
    ecc_Bmodp_shifted,
    ecc_redc_ppm1,

    ecc_pp1h,
    ecc_256_modp,
    USE_REDC ? ecc_256_redc : ecc_256_modp,
    ecc_mod_inv,
    NULL,
  },
  {
    256,
    ECC_LIMB_SIZE,
    ECC_BMODQ_SIZE,
    0,
    ECC_MOD_INV_ITCH (ECC_LIMB_SIZE),
    0,

    ecc_q,
    ecc_Bmodq,
    ecc_Bmodq_shifted,
    NULL,
    ecc_qp1h,

    ecc_256_modq,
    ecc_256_modq,
    ecc_mod_inv,
    NULL,
  },

  USE_REDC,
  ECC_PIPPENGER_K,
  ECC_PIPPENGER_C,

#ifdef HAVE_NETTLE_CURVE448_MUL
  ECC_ADD_JJA_ITCH (ECC_LIMB_SIZE),
#endif
  ECC_ADD_JJJ_ITCH (ECC_LIMB_SIZE),
#ifdef HAVE_NETTLE_CURVE448_MUL
  ECC_DUP_JJ_ITCH (ECC_LIMB_SIZE),
#endif
  ECC_MUL_A_ITCH (ECC_LIMB_SIZE),
  ECC_MUL_G_ITCH (ECC_LIMB_SIZE),
  ECC_J_TO_A_ITCH (ECC_LIMB_SIZE),

#ifdef HAVE_NETTLE_CURVE448_MUL
  ecc_add_jja,
#endif
  ecc_add_jjj,
#ifdef HAVE_NETTLE_CURVE448_MUL
  ecc_dup_jj,
#endif
  ecc_mul_a,
  ecc_mul_g,
  ecc_j_to_a,

  ecc_b,
  ecc_g,
#ifndef HAVE_NETTLE_CURVE448_MUL
  NULL,
#endif
  ecc_unit,
  ecc_table
};

const struct ecc_curve *nettle_get_gost_gc256b(void)
{
  return &_gnutls_gost_gc256b;
}