/* mpiutil.ac - Utility functions for MPI * Copyright (C) 1998, 1999 Free Software Foundation, Inc. * * This file is part of GnuPG. * * GnuPG is free software; you can redistribute it and/or modify * it under the terms of 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. * * GnuPG 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 a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include "mpi-internal.h" /* Constants allocated right away at startup. */ static MPI constants[MPI_NUMBER_OF_CONSTANTS]; /* Initialize the MPI subsystem. This is called early and allows to * do some initialization without taking care of threading issues. */ static int __init mpi_init(void) { … } postcore_initcall(mpi_init); /* Return a constant MPI descripbed by NO which is one of the * MPI_C_xxx macros. There is no need to copy this returned value; it * may be used directly. */ MPI mpi_const(enum gcry_mpi_constants no) { … } EXPORT_SYMBOL_GPL(…); /**************** * Note: It was a bad idea to use the number of limbs to allocate * because on a alpha the limbs are large but we normally need * integers of n bits - So we should change this to bits (or bytes). * * But mpi_alloc is used in a lot of places :-) */ MPI mpi_alloc(unsigned nlimbs) { … } EXPORT_SYMBOL_GPL(…); mpi_ptr_t mpi_alloc_limb_space(unsigned nlimbs) { … } void mpi_free_limb_space(mpi_ptr_t a) { … } void mpi_assign_limb_space(MPI a, mpi_ptr_t ap, unsigned nlimbs) { … } /**************** * Resize the array of A to NLIMBS. the additional space is cleared * (set to 0) [done by m_realloc()] */ int mpi_resize(MPI a, unsigned nlimbs) { … } void mpi_clear(MPI a) { … } EXPORT_SYMBOL_GPL(…); void mpi_free(MPI a) { … } EXPORT_SYMBOL_GPL(…); /**************** * Note: This copy function should not interpret the MPI * but copy it transparently. */ MPI mpi_copy(MPI a) { … } /**************** * This function allocates an MPI which is optimized to hold * a value as large as the one given in the argument and allocates it * with the same flags as A. */ MPI mpi_alloc_like(MPI a) { … } /* Set U into W and release U. If W is NULL only U will be released. */ void mpi_snatch(MPI w, MPI u) { … } MPI mpi_set(MPI w, MPI u) { … } EXPORT_SYMBOL_GPL(…); MPI mpi_set_ui(MPI w, unsigned long u) { … } EXPORT_SYMBOL_GPL(…); MPI mpi_alloc_set_ui(unsigned long u) { … } /**************** * Swap the value of A and B, when SWAP is 1. * Leave the value when SWAP is 0. * This implementation should be constant-time regardless of SWAP. */ void mpi_swap_cond(MPI a, MPI b, unsigned long swap) { … } MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …;