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/cipher/ecc-misc.c
gcry_err_code_t _gcry_ecc_os2ec(mpi_point_t result, gcry_mpi_t value)
{
    gcry_err_code_t rc;
    size_t n;
    const unsigned char* buf;
    unsigned char* buf_memory;
    gcry_mpi_t x, y;

    if (mpi_is_opaque(value))
    {
        unsigned int nbits;

        buf = mpi_get_opaque(value, &nbits);
        if (!buf)
            return GPG_ERR_INV_OBJ;
        n = (nbits + 7) / 8;
        buf_memory = NULL;
    }
    else
    {
        n = (mpi_get_nbits(value) + 7) / 8;
        buf_memory = xmalloc(n);
        rc = _gcry_mpi_print(GCRYMPI_FMT_USG, buf_memory, n, &n, value);
        if (rc)
        {
            xfree(buf_memory);
            return rc;
        }
        buf = buf_memory;
    }

    if (n < 1)
    {
        xfree(buf_memory);
        return GPG_ERR_INV_OBJ;
    }
    if (*buf != 4)
    {
        xfree(buf_memory);
        return GPG_ERR_NOT_IMPLEMENTED; /* No support for point compression.  */
    }
    if (((n - 1) % 2))
    {
        xfree(buf_memory);
        return GPG_ERR_INV_OBJ;
    }
    n = (n - 1) / 2;
    rc = _gcry_mpi_scan(&x, GCRYMPI_FMT_USG, buf + 1, n, NULL);
    if (rc)
    {
        xfree(buf_memory);
        return rc;
    }
    rc = _gcry_mpi_scan(&y, GCRYMPI_FMT_USG, buf + 1 + n, n, NULL);
    xfree(buf_memory);
    if (rc)
    {
        mpi_free(x);
        return rc;
    }

    mpi_set(result->x, x);
    mpi_set(result->y, y);
    mpi_set_ui(result->z, 1);

    mpi_free(x);
    mpi_free(y);

    return 0;
}
/* RESULT must have been initialized and is set on success to the
   point given by VALUE.  */
RESULT must have been initialized and is set on success to the
point given by VALUE.
RESULT must have been initialized and is set on success to the point given by VALUE .
gcry_err_code_t _gcry_ecc_os2ec(mpi_point_t result, gcry_mpi_t value)
{
    gcry_err_code_t rc;
    size_t n;
    const unsigned char* buf;
    unsigned char* buf_memory;
    gcry_mpi_t x, y;
    if (mpi_is_opaque(value))
    {
        unsigned int nbits;
        buf = mpi_get_opaque(value, &nbits);
        if (!buf)
            return GPG_ERR_INV_OBJ;
        n = (nbits + 7) / 8;
        buf_memory = NULL;
    }
    else
    {
        n = (mpi_get_nbits(value) + 7) / 8;
        buf_memory = xmalloc(n);
        rc = _gcry_mpi_print(GCRYMPI_FMT_USG, buf_memory, n, &n, value);
        if (rc)
        {
            xfree(buf_memory);
            return rc;
        }
        buf = buf_memory;
    }
    if (n < 1)
    {
        xfree(buf_memory);
        return GPG_ERR_INV_OBJ;
    }
    if (*buf != 4)
    {
        xfree(buf_memory);
        return GPG_ERR_NOT_IMPLEMENTED; 
    }
    if (((n - 1) % 2))
    {
        xfree(buf_memory);
        return GPG_ERR_INV_OBJ;
    }
    n = (n - 1) / 2;
    rc = _gcry_mpi_scan(&x, GCRYMPI_FMT_USG, buf + 1, n, NULL);
    if (rc)
    {
        xfree(buf_memory);
        return rc;
    }
    rc = _gcry_mpi_scan(&y, GCRYMPI_FMT_USG, buf + 1 + n, n, NULL);
    xfree(buf_memory);
    if (rc)
    {
        mpi_free(x);
        return rc;
    }
    mpi_set(result->x, x);
    mpi_set(result->y, y);
    mpi_set_ui(result->z, 1);
    mpi_free(x);
    mpi_free(y);
    return 0;
}
gcry_err_code_t _gcry_ecc_os2ec ( mpi_point_t result , gcry_mpi_t value ) { gcry_err_code_t rc ; size_t n ; const unsigned char * buf ; unsigned char * buf_memory ; gcry_mpi_t x , y ; if ( mpi_is_opaque ( value ) ) { unsigned int nbits ; buf = mpi_get_opaque ( value , & nbits ) ; if ( ! buf ) return GPG_ERR_INV_OBJ ; n = ( nbits + 7 ) / 8 ; buf_memory = NULL ; } else { n = ( mpi_get_nbits ( value ) + 7 ) / 8 ; buf_memory = xmalloc ( n ) ; rc = _gcry_mpi_print ( GCRYMPI_FMT_USG , buf_memory , n , & n , value ) ; if ( rc ) { xfree ( buf_memory ) ; return rc ; } buf = buf_memory ; } if ( n < 1 ) { xfree ( buf_memory ) ; return GPG_ERR_INV_OBJ ; } if ( * buf != 4 ) { xfree ( buf_memory ) ; return GPG_ERR_NOT_IMPLEMENTED ; } if ( ( ( n - 1 ) % 2 ) ) { xfree ( buf_memory ) ; return GPG_ERR_INV_OBJ ; } n = ( n - 1 ) / 2 ; rc = _gcry_mpi_scan ( & x , GCRYMPI_FMT_USG , buf + 1 , n , NULL ) ; if ( rc ) { xfree ( buf_memory ) ; return rc ; } rc = _gcry_mpi_scan ( & y , GCRYMPI_FMT_USG , buf + 1 + n , n , NULL ) ; xfree ( buf_memory ) ; if ( rc ) { mpi_free ( x ) ; return rc ; } mpi_set ( result -> x , x ) ; mpi_set ( result -> y , y ) ; mpi_set_ui ( result -> z , 1 ) ; mpi_free ( x ) ; mpi_free ( y ) ; return 0 ; }
RESULT must have been initialized and is set on success to the
point given by VALUE.
RESULT must have been initialized and is set on success to the point given by VALUE .
/* No support for point compression.  */