1 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2 /* All Rights Reserved */
6 * Copyright (c) 1980 Regents of the University of California.
7 * All rights reserved. The Berkeley software License Agreement
8 * specifies the terms and conditions for redistribution.
10 /* Portions Copyright(c) 1988, Sun Microsystems Inc. */
11 /* All Rights Reserved */
14 * Copyright (c) 1997, by Sun Microsystems, Inc.
15 * All rights reserved.
18 #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
24 #include <sys/types.h>
30 _mp_move(MINT
*a
, MINT
*b
)
36 if ((i
= a
->len
) < 0) {
42 b
->val
= _mp_xalloc(i
, "_mp_move");
43 for (j
= 0; j
< i
; j
++) {
44 b
->val
[j
] = a
->val
[j
];
51 _mp_xalloc(int nint
, char *s
)
55 i
= malloc(sizeof (short) * ((unsigned)nint
+ 2)); /* ??? 2 ??? */
57 (void) fprintf(stderr
, "%s: %p\n", s
, i
);
60 _mp_fatal("mp: no free space");
68 (void) fprintf(stderr
, "%s\n", s
);
69 (void) fflush(stdout
);
78 (void) fprintf(stderr
, "xfree ");
91 if ((i
= a
->len
) == 0) {
97 for (j
= i
; j
> 0 && a
->val
[j
-1] == 0; j
--)
119 a
= malloc(sizeof (MINT
));
122 a
->val
= _mp_xalloc(1, "mp_itom1");
126 a
->val
= _mp_xalloc(1, "mp_itom2");
135 mp_mcmp(MINT
*a
, MINT
*b
)
142 if (a
->len
!= b
->len
) {
143 return (a
->len
- b
->len
);
153 * Convert hex digit to binary value
158 if (c
>= '0' && c
<= '9') {
160 } else if (c
>= 'a' && c
<= 'f') {
161 return (c
- 'a' + 10);
162 } else if (c
>= 'A' && c
<= 'F') {
163 return (c
- 'A' + 10);
171 * Convert hex key to MINT key
177 MINT
*m
= mp_itom(0);
181 sixteen
= mp_itom(16);
182 for (; *key
; key
++) {
188 mp_mult(m
, sixteen
, m
);
203 return ('a' - 10 + d
);
208 * Convert MINT key to hex key
213 MINT
*m
= mp_itom(0);
214 MINT
*zero
= mp_itom(0);
222 #define BASEBITS (8 * (unsigned int)sizeof (short) - 1)
229 hex
= malloc((size_t) ((size
* BASEBITS
+ 3)) / 4 + (size
? 1 : 2));
236 mp_sdiv(m
, 16, m
, &r
);
238 } while (mp_mcmp(m
, zero
) != 0);
243 for (p
--, s
= hex
; s
< p
; s
++, p
--) {
252 * Deallocate a multiple precision integer