3 * $Id: mp-io.c,v 1.1 1999/11/17 18:02:16 mdw Exp $
5 * Loading and storing of multiprecision integers
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.1 1999/11/17 18:02:16 mdw
34 * New multiprecision integer arithmetic suite.
38 /*----- Header files ------------------------------------------------------*/
42 /*----- Main code ---------------------------------------------------------*/
44 /* --- @mp_octets@ --- *
46 * Arguments: @const mp *m@ = a multiprecision integer
48 * Returns: The number of octets required to represent @m@.
50 * Use: Calculates the external storage required for a multiprecision
54 size_t mp_octets(const mp
*m
)
57 MPX_OCTETS(sz
, m
->v
, m
->vl
);
61 /* --- @mp_loadl@ --- *
63 * Arguments: @mp *d@ = destination
64 * @const void *pv@ = pointer to source data
65 * @size_t sz@ = size of the source data
67 * Returns: Resulting multiprecision number.
69 * Use: Loads a multiprecision number from an array of octets. The
70 * first byte in the array is the least significant. More
71 * formally, if the bytes are %$b_0, b_1, \ldots, b_{n-1}$%
72 * then the result is %$N = \sum_{0 \le i < n} b_i 2^{8i}$%.
75 mp
*mp_loadl(mp
*d
, const void *pv
, size_t sz
)
77 MP_MODIFY(d
, MPW_RQ(sz
));
78 mpx_loadl(d
->v
, d
->vl
, pv
, sz
);
83 /* --- @mp_storel@ --- *
85 * Arguments: @const mp *m@ = source
86 * @void *pv@ = pointer to output array
87 * @size_t sz@ = size of the output array
91 * Use: Stores a multiprecision number in an array of octets. The
92 * first byte in the array is the least significant. If the
93 * array is too small to represent the number, high-order bits
94 * are truncated; if the array is too large, high order bytes
95 * are filled with zeros. More formally, if the number is
96 * %$N = \sum{0 \le i} b_i 2^{8i}$% where %$0 \le b_i < 256$%,
97 * then the array is %$b_0, b_1, \ldots, b_{n-1}$%.
100 void mp_storel(const mp
*m
, void *pv
, size_t sz
)
102 mpx_storel(m
->v
, m
->vl
, pv
, sz
);
105 /* --- @mp_loadb@ --- *
107 * Arguments: @mp *d@ = destination
108 * @const void *pv@ = pointer to source data
109 * @size_t sz@ = size of the source data
111 * Returns: Resulting multiprecision number.
113 * Use: Loads a multiprecision number from an array of octets. The
114 * last byte in the array is the least significant. More
115 * formally, if the bytes are %$b_{n-1}, b_{n-2}, \ldots, b_0$%
116 * then the result is %$N = \sum_{0 \le i < n} b_i 2^{8i}$%.
119 mp
*mp_loadb(mp
*d
, const void *pv
, size_t sz
)
121 MP_MODIFY(d
, MPW_RQ(sz
));
122 mpx_loadb(d
->v
, d
->vl
, pv
, sz
);
127 /* --- @mp_storeb@ --- *
129 * Arguments: @const mp *m@ = source
130 * @void *pv@ = pointer to output array
131 * @size_t sz@ = size of the output array
135 * Use: Stores a multiprecision number in an array of octets. The
136 * last byte in the array is the least significant. If the
137 * array is too small to represent the number, high-order bits
138 * are truncated; if the array is too large, high order bytes
139 * are filled with zeros. More formally, if the number is
140 * %$N = \sum{0 \le i} b_i 2^{8i}$% where %$0 \le b_i < 256$%,
141 * then the array is %$b_{n-1}, b_{n-2}, \ldots, b_0$%.
144 void mp_storeb(const mp
*m
, void *pv
, size_t sz
)
146 mpx_storeb(m
->v
, m
->vl
, pv
, sz
);
149 /*----- That's all, folks -------------------------------------------------*/