Lines Matching +full:- +full:a
1 /* mpiutil.ac - Utility functions for MPI
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * You should have received a copy of the GNU General Public License
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 #include "mpi-internal.h"
24 * Note: It was a bad idea to use the number of limbs to allocate
25 * because on a alpha the limbs are large but we normally need
26 * integers of n bits - So we should change this to bits (or bytes).
28 * But mpi_alloc is used in a lot of places :-)
32 MPI a; in mpi_alloc() local
34 a = kmalloc(sizeof *a, GFP_KERNEL); in mpi_alloc()
35 if (!a) in mpi_alloc()
36 return a; in mpi_alloc()
39 a->d = mpi_alloc_limb_space(nlimbs); in mpi_alloc()
40 if (!a->d) { in mpi_alloc()
41 kfree(a); in mpi_alloc()
45 a->d = NULL; in mpi_alloc()
48 a->alloced = nlimbs; in mpi_alloc()
49 a->nlimbs = 0; in mpi_alloc()
50 a->sign = 0; in mpi_alloc()
51 a->flags = 0; in mpi_alloc()
52 a->nbits = 0; in mpi_alloc()
53 return a; in mpi_alloc()
67 void mpi_free_limb_space(mpi_ptr_t a) in mpi_free_limb_space() argument
69 if (!a) in mpi_free_limb_space()
72 kfree_sensitive(a); in mpi_free_limb_space()
75 void mpi_assign_limb_space(MPI a, mpi_ptr_t ap, unsigned nlimbs) in mpi_assign_limb_space() argument
77 mpi_free_limb_space(a->d); in mpi_assign_limb_space()
78 a->d = ap; in mpi_assign_limb_space()
79 a->alloced = nlimbs; in mpi_assign_limb_space()
83 * Resize the array of A to NLIMBS. the additional space is cleared
86 int mpi_resize(MPI a, unsigned nlimbs) in mpi_resize() argument
90 if (nlimbs <= a->alloced) in mpi_resize()
93 if (a->d) { in mpi_resize()
96 return -ENOMEM; in mpi_resize()
97 memcpy(p, a->d, a->alloced * sizeof(mpi_limb_t)); in mpi_resize()
98 kfree_sensitive(a->d); in mpi_resize()
99 a->d = p; in mpi_resize()
101 a->d = kcalloc(nlimbs, sizeof(mpi_limb_t), GFP_KERNEL); in mpi_resize()
102 if (!a->d) in mpi_resize()
103 return -ENOMEM; in mpi_resize()
105 a->alloced = nlimbs; in mpi_resize()
109 void mpi_free(MPI a) in mpi_free() argument
111 if (!a) in mpi_free()
114 if (a->flags & 4) in mpi_free()
115 kfree_sensitive(a->d); in mpi_free()
117 mpi_free_limb_space(a->d); in mpi_free()
119 if (a->flags & ~7) in mpi_free()
121 kfree(a); in mpi_free()
129 MPI mpi_copy(MPI a) in mpi_copy() argument
134 if (a) { in mpi_copy()
135 b = mpi_alloc(a->nlimbs); in mpi_copy()
138 b->nlimbs = a->nlimbs; in mpi_copy()
139 b->sign = a->sign; in mpi_copy()
140 b->flags = a->flags; in mpi_copy()
141 b->flags &= ~(16|32); /* Reset the immutable and constant flags. */ in mpi_copy()
142 for (i = 0; i < b->nlimbs; i++) in mpi_copy()
143 b->d[i] = a->d[i]; in mpi_copy()