openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/libgcrypt/1.8.4-r0/libgcrypt-1.8.4/mpi/ec.c
static void ec_p_init(mpi_ec_t ctx, enum gcry_mpi_ec_models model,
                      enum ecc_dialects dialect, int flags, gcry_mpi_t p,
                      gcry_mpi_t a, gcry_mpi_t b)
{
    int i;
    static int use_barrett;

    if (!use_barrett)
    {
        if (getenv("GCRYPT_BARRETT"))
            use_barrett = 1;
        else
            use_barrett = -1;
    }

    /* Fixme: Do we want to check some constraints? e.g.  a < p  */

    ctx->model = model;
    ctx->dialect = dialect;
    ctx->flags = flags;
    if (dialect == ECC_DIALECT_ED25519)
        ctx->nbits = 256;
    else
        ctx->nbits = mpi_get_nbits(p);
    ctx->p = mpi_copy(p);
    ctx->a = mpi_copy(a);
    ctx->b = mpi_copy(b);

    ctx->t.p_barrett =
        use_barrett > 0 ? _gcry_mpi_barrett_init(ctx->p, 0) : NULL;

    _gcry_mpi_ec_get_reset(ctx);

    if (model == MPI_EC_MONTGOMERY)
    {
        for (i = 0; i < DIM(ctx->t.scratch) && curve25519_bad_points[i]; i++)
            ctx->t.scratch[i] = scanval(curve25519_bad_points[i]);
    }
    else
    {
        /* Allocate scratch variables.  */
        for (i = 0; i < DIM(ctx->t.scratch); i++)
            ctx->t.scratch[i] = mpi_alloc_like(ctx->p);
    }

    /* Prepare for fast reduction.  */
    /* FIXME: need a test for NIST values.  However it does not gain us
       any real advantage, for 384 bits it is actually slower than using
       mpi_mulm.  */
    /*   ctx->nist_nbits = mpi_get_nbits (ctx->p); */
    /*   if (ctx->nist_nbits == 192) */
    /*     { */
    /*       for (i=0; i < 4; i++) */
    /*         ctx->s[i] = mpi_new (192); */
    /*       ctx->c    = mpi_new (192*2); */
    /*     } */
    /*   else if (ctx->nist_nbits == 384) */
    /*     { */
    /*       for (i=0; i < 10; i++) */
    /*         ctx->s[i] = mpi_new (384); */
    /*       ctx->c    = mpi_new (384*2); */
    /*     } */
}
/* This function initialized a context for elliptic curve based on the
   field GF(p).  P is the prime specifying this field, A is the first
   coefficient.  CTX is expected to be zeroized.  */
This function initialized a context for elliptic curve based on the
field GF(p).  P is the prime specifying this field, A is the first
coefficient.  CTX is expected to be zeroized.
This function initialized a context for elliptic curve based on the field GF ( p ) . P is the prime specifying this field A is the first coefficient . CTX is expected to be zeroized .
static void ec_p_init(mpi_ec_t ctx, enum gcry_mpi_ec_models model,
                      enum ecc_dialects dialect, int flags, gcry_mpi_t p,
                      gcry_mpi_t a, gcry_mpi_t b)
{
    int i;
    static int use_barrett;
    if (!use_barrett)
    {
        if (getenv("GCRYPT_BARRETT"))
            use_barrett = 1;
        else
            use_barrett = -1;
    }
    ctx->model = model;
    ctx->dialect = dialect;
    ctx->flags = flags;
    if (dialect == ECC_DIALECT_ED25519)
        ctx->nbits = 256;
    else
        ctx->nbits = mpi_get_nbits(p);
    ctx->p = mpi_copy(p);
    ctx->a = mpi_copy(a);
    ctx->b = mpi_copy(b);
    ctx->t.p_barrett =
        use_barrett > 0 ? _gcry_mpi_barrett_init(ctx->p, 0) : NULL;
    _gcry_mpi_ec_get_reset(ctx);
    if (model == MPI_EC_MONTGOMERY)
    {
        for (i = 0; i < DIM(ctx->t.scratch) && curve25519_bad_points[i]; i++)
            ctx->t.scratch[i] = scanval(curve25519_bad_points[i]);
    }
    else
    {
        for (i = 0; i < DIM(ctx->t.scratch); i++)
            ctx->t.scratch[i] = mpi_alloc_like(ctx->p);
    }
}
static void ec_p_init ( mpi_ec_t ctx , enum gcry_mpi_ec_models model , enum ecc_dialects dialect , int flags , gcry_mpi_t p , gcry_mpi_t a , gcry_mpi_t b ) { int i ; static int use_barrett ; if ( ! use_barrett ) { if ( getenv ( " " ) ) use_barrett = 1 ; else use_barrett = -1 ; } ctx -> model = model ; ctx -> dialect = dialect ; ctx -> flags = flags ; if ( dialect == ECC_DIALECT_ED25519 ) ctx -> nbits = 256 ; else ctx -> nbits = mpi_get_nbits ( p ) ; ctx -> p = mpi_copy ( p ) ; ctx -> a = mpi_copy ( a ) ; ctx -> b = mpi_copy ( b ) ; ctx -> t . p_barrett = use_barrett > 0 ? _gcry_mpi_barrett_init ( ctx -> p , 0 ) : NULL ; _gcry_mpi_ec_get_reset ( ctx ) ; if ( model == MPI_EC_MONTGOMERY ) { for ( i = 0 ; i < DIM ( ctx -> t . scratch ) && curve25519_bad_points [ i ] ; i ++ ) ctx -> t . scratch [ i ] = scanval ( curve25519_bad_points [ i ] ) ; } else { for ( i = 0 ; i < DIM ( ctx -> t . scratch ) ; i ++ ) ctx -> t . scratch [ i ] = mpi_alloc_like ( ctx -> p ) ; } }
This function initialized a context for elliptic curve based on the
field GF(p).
This function initialized a context for elliptic curve based on the field GF ( p ) .
/* Fixme: Do we want to check some constraints? e.g.  a < p  */ /* Allocate scratch variables.  */ /* Prepare for fast reduction.  */ /* FIXME: need a test for NIST values.  However it does not gain us
       any real advantage, for 384 bits it is actually slower than using
       mpi_mulm.  */ /*   ctx->nist_nbits = mpi_get_nbits (ctx->p); */ /*   if (ctx->nist_nbits == 192) */ /*     { */ /*       for (i=0; i < 4; i++) */ /*         ctx->s[i] = mpi_new (192); */ /*       ctx->c    = mpi_new (192*2); */ /*     } */ /*   else if (ctx->nist_nbits == 384) */ /*     { */ /*       for (i=0; i < 10; i++) */ /*         ctx->s[i] = mpi_new (384); */ /*       ctx->c    = mpi_new (384*2); */ /*     } */