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
int _gcry_mpi_ec_get_affine(gcry_mpi_t x, gcry_mpi_t y, mpi_point_t point,
                            mpi_ec_t ctx)
{
    if (!mpi_cmp_ui(point->z, 0))
        return -1;

    switch (ctx->model)
    {
        case MPI_EC_WEIERSTRASS: /* Using Jacobian coordinates.  */
        {
            gcry_mpi_t z1, z2, z3;

            z1 = mpi_new(0);
            z2 = mpi_new(0);
            ec_invm(z1, point->z, ctx); /* z1 = z^(-1) mod p  */
            ec_mulm(z2, z1, z1, ctx);   /* z2 = z^(-2) mod p  */

            if (x)
                ec_mulm(x, point->x, z2, ctx);

            if (y)
            {
                z3 = mpi_new(0);
                ec_mulm(z3, z2, z1, ctx); /* z3 = z^(-3) mod p  */
                ec_mulm(y, point->y, z3, ctx);
                mpi_free(z3);
            }

            mpi_free(z2);
            mpi_free(z1);
        }
            return 0;

        case MPI_EC_MONTGOMERY:
        {
            if (x)
                mpi_set(x, point->x);

            if (y)
            {
                log_fatal("%s: Getting Y-coordinate on %s is not supported\n",
                          "_gcry_mpi_ec_get_affine", "Montgomery");
                return -1;
            }
        }
            return 0;

        case MPI_EC_EDWARDS:
        {
            gcry_mpi_t z;

            z = mpi_new(0);
            ec_invm(z, point->z, ctx);

            if (x)
                ec_mulm(x, point->x, z, ctx);
            if (y)
                ec_mulm(y, point->y, z, ctx);

            _gcry_mpi_release(z);
        }
            return 0;

        default:
            return -1;
    }
}
/* Compute the affine coordinates from the projective coordinates in
   POINT.  Set them into X and Y.  If one coordinate is not required,
   X or Y may be passed as NULL.  CTX is the usual context. Returns: 0
   on success or !0 if POINT is at infinity.  */
Compute the affine coordinates from the projective coordinates in
POINT.  Set them into X and Y.  If one coordinate is not required,
X or Y may be passed as NULL.  CTX is the usual context. Returns: 0
on success or !0 if POINT is at infinity.
Compute the affine coordinates from the projective coordinates in POINT . Set them into X and Y . If one coordinate is not required X or Y may be passed as NULL . CTX is the usual context . Returns : 0 on success or !0 if POINT is at infinity .
int _gcry_mpi_ec_get_affine(gcry_mpi_t x, gcry_mpi_t y, mpi_point_t point,
                            mpi_ec_t ctx)
{
    if (!mpi_cmp_ui(point->z, 0))
        return -1;
    switch (ctx->model)
    {
        case MPI_EC_WEIERSTRASS: 
        {
            gcry_mpi_t z1, z2, z3;
            z1 = mpi_new(0);
            z2 = mpi_new(0);
            ec_invm(z1, point->z, ctx); 
            ec_mulm(z2, z1, z1, ctx);   
            if (x)
                ec_mulm(x, point->x, z2, ctx);
            if (y)
            {
                z3 = mpi_new(0);
                ec_mulm(z3, z2, z1, ctx); 
                ec_mulm(y, point->y, z3, ctx);
                mpi_free(z3);
            }
            mpi_free(z2);
            mpi_free(z1);
        }
            return 0;
        case MPI_EC_MONTGOMERY:
        {
            if (x)
                mpi_set(x, point->x);
            if (y)
            {
                log_fatal("%s: Getting Y-coordinate on %s is not supported\n",
                          "_gcry_mpi_ec_get_affine", "Montgomery");
                return -1;
            }
        }
            return 0;
        case MPI_EC_EDWARDS:
        {
            gcry_mpi_t z;
            z = mpi_new(0);
            ec_invm(z, point->z, ctx);
            if (x)
                ec_mulm(x, point->x, z, ctx);
            if (y)
                ec_mulm(y, point->y, z, ctx);
            _gcry_mpi_release(z);
        }
            return 0;
        default:
            return -1;
    }
}
int _gcry_mpi_ec_get_affine ( gcry_mpi_t x , gcry_mpi_t y , mpi_point_t point , mpi_ec_t ctx ) { if ( ! mpi_cmp_ui ( point -> z , 0 ) ) return -1 ; switch ( ctx -> model ) { case MPI_EC_WEIERSTRASS : { gcry_mpi_t z1 , z2 , z3 ; z1 = mpi_new ( 0 ) ; z2 = mpi_new ( 0 ) ; ec_invm ( z1 , point -> z , ctx ) ; ec_mulm ( z2 , z1 , z1 , ctx ) ; if ( x ) ec_mulm ( x , point -> x , z2 , ctx ) ; if ( y ) { z3 = mpi_new ( 0 ) ; ec_mulm ( z3 , z2 , z1 , ctx ) ; ec_mulm ( y , point -> y , z3 , ctx ) ; mpi_free ( z3 ) ; } mpi_free ( z2 ) ; mpi_free ( z1 ) ; } return 0 ; case MPI_EC_MONTGOMERY : { if ( x ) mpi_set ( x , point -> x ) ; if ( y ) { log_fatal ( " \n " , " " , " " ) ; return -1 ; } } return 0 ; case MPI_EC_EDWARDS : { gcry_mpi_t z ; z = mpi_new ( 0 ) ; ec_invm ( z , point -> z , ctx ) ; if ( x ) ec_mulm ( x , point -> x , z , ctx ) ; if ( y ) ec_mulm ( y , point -> y , z , ctx ) ; _gcry_mpi_release ( z ) ; } return 0 ; default : return -1 ; } }
Compute the affine coordinates from the projective coordinates in
POINT.
Compute the affine coordinates from the projective coordinates in POINT .
/* Using Jacobian coordinates.  */ /* z1 = z^(-1) mod p  */ /* z2 = z^(-2) mod p  */ /* z3 = z^(-3) mod p  */