Blame lib/nettle/ecc/ecc-gost-gc256b.c

Packit Service 991b93
/* ecc-gost-gc256b.c
Packit Service 991b93
Packit Service 991b93
   Copyright (C) 2016-2020 Dmitry Eremin-Solenikov
Packit Service 991b93
Packit Service 991b93
   This file is part of GNU Nettle.
Packit Service 991b93
Packit Service 991b93
   GNU Nettle is free software: you can redistribute it and/or
Packit Service 991b93
   modify it under the terms of either:
Packit Service 991b93
Packit Service 991b93
     * the GNU Lesser General Public License as published by the Free
Packit Service 991b93
       Software Foundation; either version 3 of the License, or (at your
Packit Service 991b93
       option) any later version.
Packit Service 991b93
Packit Service 991b93
   or
Packit Service 991b93
Packit Service 991b93
     * the GNU General Public License as published by the Free
Packit Service 991b93
       Software Foundation; either version 2 of the License, or (at your
Packit Service 991b93
       option) any later version.
Packit Service 991b93
Packit Service 991b93
   or both in parallel, as here.
Packit Service 991b93
Packit Service 991b93
   GNU Nettle is distributed in the hope that it will be useful,
Packit Service 991b93
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 991b93
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 991b93
   General Public License for more details.
Packit Service 991b93
Packit Service 991b93
   You should have received copies of the GNU General Public License and
Packit Service 991b93
   the GNU Lesser General Public License along with this program.  If
Packit Service 991b93
   not, see http://www.gnu.org/licenses/.
Packit Service 991b93
*/
Packit Service 991b93
Packit Service 991b93
#if HAVE_CONFIG_H
Packit Service 991b93
# include "config.h"
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
#include <assert.h>
Packit Service 991b93
Packit Service 991b93
#include <nettle/ecc.h>
Packit Service 991b93
#include "ecc-gost-curve.h"
Packit Service 991b93
#include "ecc-internal.h"
Packit Service 991b93
Packit Service 991b93
#define USE_REDC 0
Packit Service 991b93
Packit Service 991b93
#if defined __clang__ || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
Packit Service 991b93
# pragma GCC diagnostic ignored "-Wunused-const-variable"
Packit Service 991b93
#endif
Packit Service 991b93
#if GMP_NUMB_BITS == 32
Packit Service 991b93
#include "ecc/ecc-gost-gc256b-32.h"
Packit Service 991b93
#elif GMP_NUMB_BITS == 64
Packit Service 991b93
#include "ecc/ecc-gost-gc256b-64.h"
Packit Service 991b93
#else
Packit Service 991b93
#error unsupported configuration
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
static void
Packit Service 991b93
ecc_gost_gc256b_modp (const struct ecc_modulo *m, mp_limb_t *rp)
Packit Service 991b93
{
Packit Service 991b93
  mp_size_t mn = m->size;
Packit Service 991b93
  mp_limb_t hi;
Packit Service 991b93
Packit Service 991b93
  hi = mpn_addmul_1(rp, rp + mn, mn, 0x269);
Packit Service 991b93
  hi = sec_add_1 (rp, rp, mn, hi * 0x269);
Packit Service 991b93
  hi = sec_add_1 (rp, rp, mn, hi * 0x269);
Packit Service 991b93
  assert(hi == 0);
Packit Service 991b93
}
Packit Service 991b93
Packit Service 991b93
#define ecc_gost_gc256b_modp ecc_gost_gc256b_modp
Packit Service 991b93
#define ecc_gost_gc256b_modq ecc_mod
Packit Service 991b93
Packit Service 991b93
const struct ecc_curve _nettle_gost_gc256b =
Packit Service 991b93
{
Packit Service 991b93
  {
Packit Service 991b93
    256,
Packit Service 991b93
    ECC_LIMB_SIZE,
Packit Service 991b93
    ECC_BMODP_SIZE,
Packit Service 991b93
    ECC_REDC_SIZE,
Packit Service 991b93
    ECC_MOD_INV_ITCH (ECC_LIMB_SIZE),
Packit Service 991b93
    0,
Packit Service 991b93
Packit Service 991b93
    ecc_p,
Packit Service 991b93
    ecc_Bmodp,
Packit Service 991b93
    ecc_Bmodp_shifted,
Packit Service 991b93
    ecc_redc_ppm1,
Packit Service 991b93
Packit Service 991b93
    ecc_pp1h,
Packit Service 991b93
    ecc_gost_gc256b_modp,
Packit Service 991b93
    ecc_gost_gc256b_modp,
Packit Service 991b93
    ecc_mod_inv,
Packit Service 991b93
    NULL,
Packit Service 991b93
  },
Packit Service 991b93
  {
Packit Service 991b93
    256,
Packit Service 991b93
    ECC_LIMB_SIZE,
Packit Service 991b93
    ECC_BMODQ_SIZE,
Packit Service 991b93
    0,
Packit Service 991b93
    ECC_MOD_INV_ITCH (ECC_LIMB_SIZE),
Packit Service 991b93
    0,
Packit Service 991b93
Packit Service 991b93
    ecc_q,
Packit Service 991b93
    ecc_Bmodq,
Packit Service 991b93
    ecc_Bmodq_shifted,
Packit Service 991b93
    NULL,
Packit Service 991b93
    ecc_qp1h,
Packit Service 991b93
Packit Service 991b93
    ecc_gost_gc256b_modq,
Packit Service 991b93
    ecc_gost_gc256b_modq,
Packit Service 991b93
    ecc_mod_inv,
Packit Service 991b93
    NULL,
Packit Service 991b93
  },
Packit Service 991b93
Packit Service 991b93
  USE_REDC,
Packit Service 991b93
  ECC_PIPPENGER_K,
Packit Service 991b93
  ECC_PIPPENGER_C,
Packit Service 991b93
Packit Service 991b93
  ECC_ADD_JJA_ITCH (ECC_LIMB_SIZE),
Packit Service 991b93
  ECC_ADD_JJJ_ITCH (ECC_LIMB_SIZE),
Packit Service 991b93
  ECC_DUP_JJ_ITCH (ECC_LIMB_SIZE),
Packit Service 991b93
  ECC_MUL_A_ITCH (ECC_LIMB_SIZE),
Packit Service 991b93
  ECC_MUL_G_ITCH (ECC_LIMB_SIZE),
Packit Service 991b93
  ECC_J_TO_A_ITCH (ECC_LIMB_SIZE),
Packit Service 991b93
Packit Service 991b93
  ecc_add_jja,
Packit Service 991b93
  ecc_add_jjj,
Packit Service 991b93
  ecc_dup_jj,
Packit Service 991b93
  ecc_mul_a,
Packit Service 991b93
  ecc_mul_g,
Packit Service 991b93
  ecc_j_to_a,
Packit Service 991b93
Packit Service 991b93
  ecc_b,
Packit Service 991b93
  ecc_unit,
Packit Service 991b93
  ecc_table
Packit Service 991b93
};
Packit Service 991b93
Packit Service 991b93
const struct ecc_curve *nettle_get_gost_gc256b(void)
Packit Service 991b93
{
Packit Service 991b93
  return &_nettle_gost_gc256b;
Packit Service 991b93
}