Lines Matching +full:multi +full:- +full:purpose

1 /* mpicoder.c  -  Coder for the external representation of MPIs
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
27 #include "mpi-internal.h"
32 * mpi_read_raw_data - Read a raw byte stream as a positive integer
46 nbytes--; in mpi_read_raw_data()
55 nbits -= count_leading_zeros(buffer[0]) - (BITS_PER_LONG - 8); in mpi_read_raw_data()
61 val->nbits = nbits; in mpi_read_raw_data()
62 val->sign = 0; in mpi_read_raw_data()
63 val->nlimbs = nlimbs; in mpi_read_raw_data()
66 i = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB; in mpi_read_raw_data()
68 for (j = nlimbs; j > 0; j--) { in mpi_read_raw_data()
75 val->d[j - 1] = a; in mpi_read_raw_data()
89 return ERR_PTR(-EINVAL); in mpi_read_from_buffer()
94 return ERR_PTR(-EINVAL); in mpi_read_from_buffer()
101 return ERR_PTR(-EINVAL); in mpi_read_from_buffer()
106 return ERR_PTR(-ENOMEM); in mpi_read_from_buffer()
118 for (i = a->nlimbs - 1; i >= 0; i--) { in count_lzeros()
119 alimb = a->d[i]; in count_lzeros()
131 * mpi_read_buffer() - read MPI to a buffer provided by user (msb first)
133 * @a: a multi precision integer
138 * the data to-be-written on -EOVERFLOW in case buf_len was too
159 return -EINVAL; in mpi_read_buffer()
162 *sign = a->sign; in mpi_read_buffer()
166 if (buf_len < n - lzeros) { in mpi_read_buffer()
167 *nbytes = n - lzeros; in mpi_read_buffer()
168 return -EOVERFLOW; in mpi_read_buffer()
172 *nbytes = n - lzeros; in mpi_read_buffer()
174 for (i = a->nlimbs - 1 - lzeros / BYTES_PER_MPI_LIMB, in mpi_read_buffer()
176 i >= 0; i--) { in mpi_read_buffer()
178 alimb = cpu_to_be32(a->d[i]); in mpi_read_buffer()
180 alimb = cpu_to_be64(a->d[i]); in mpi_read_buffer()
184 memcpy(p, (u8 *)&alimb + lzeros, BYTES_PER_MPI_LIMB - lzeros); in mpi_read_buffer()
185 p += BYTES_PER_MPI_LIMB - lzeros; in mpi_read_buffer()
193 * mpi_get_buffer() - Returns an allocated buffer with the MPI (msb first).
198 * @a: a multi precision integer.
234 * mpi_write_to_sgl() - Funnction exports MPI to an sgl (msb first)
239 * @a: a multi precision integer
265 *sign = a->sign; in mpi_write_to_sgl()
268 return -EOVERFLOW; in mpi_write_to_sgl()
272 return -EINVAL; in mpi_write_to_sgl()
280 i = min_t(unsigned, nbytes - n, buf_len); in mpi_write_to_sgl()
283 nbytes -= i; in mpi_write_to_sgl()
285 buf_len -= i; in mpi_write_to_sgl()
293 for (i = a->nlimbs - 1; i >= 0; i--) { in mpi_write_to_sgl()
295 alimb = a->d[i] ? cpu_to_be32(a->d[i]) : 0; in mpi_write_to_sgl()
297 alimb = a->d[i] ? cpu_to_be64(a->d[i]) : 0; in mpi_write_to_sgl()
305 if (!--buf_len) { in mpi_write_to_sgl()
319 * mpi_read_raw_from_sgl() - Function allocates an MPI and populates it with
352 len--; in mpi_read_raw_from_sgl()
363 nbytes -= lzeros; in mpi_read_raw_from_sgl()
369 nbytes -= lzeros; in mpi_read_raw_from_sgl()
378 nbits -= count_leading_zeros(*buff) - (BITS_PER_LONG - 8); in mpi_read_raw_from_sgl()
387 val->nbits = nbits; in mpi_read_raw_from_sgl()
388 val->sign = 0; in mpi_read_raw_from_sgl()
389 val->nlimbs = nlimbs; in mpi_read_raw_from_sgl()
394 j = nlimbs - 1; in mpi_read_raw_from_sgl()
396 z = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB; in mpi_read_raw_from_sgl()
402 nbytes -= len; in mpi_read_raw_from_sgl()
408 val->d[j--] = a; in mpi_read_raw_from_sgl()