"Fossies" - the Fresh Open Source Software Archive 
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "huge.h" see the
Fossies "Dox" file reference documentation.
1 /*
2 ** huge.h
3 **
4 ** Arbitrary precision integer library from Python sources.
5 **
6 ** This is a minor modification of the file "huge-number.h" taken from
7 ** mirrordir-0.10.49 which in turn contains these copyrights ...
8 **
9 ** $Id: huge.h,v 1.1.1.1 2001/04/12 18:08:01 ndwinton Exp $
10 */
11
12 /* huge-number.h: arbitrary precision integer library from Python sources
13 This has nothing to do with cryptography.
14 Copyright (C) 1998 Paul Sheer
15
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 */
30
31 #ifndef _HUGE_H
32 #define _HUGE_H
33
34 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
35 /* this gives a roughly a 7/4 speed increase with powmod() */
36 #define SHIFT 31
37 typedef unsigned int digit;
38 typedef unsigned int wdigit; /* digit widened to parameter size */
39 typedef unsigned long long twodigits;
40 typedef long long stwodigits; /* signed variant of twodigits */
41 #else
42 #define SHIFT 15
43 typedef unsigned short digit;
44 typedef unsigned int wdigit;
45 typedef unsigned long twodigits;
46 typedef long stwodigits;
47 #endif
48
49 #define BASE ((digit)1 << SHIFT)
50 #define MASK ((int)(BASE - 1))
51
52 typedef struct huge_number {
53 long size; /* ob_size */
54 digit *d; /* ob_digit */
55 } Huge;
56
57 /* we want to wipe as we go along, so that secret keys cannot be read from memory: */
58 #define huge_free(x) \
59 { \
60 if (x) { \
61 memset (x, 0, sizeof (Huge) + \
62 sizeof (digit) * (((x)->size) >= 0 ? ((x)->size) : -((x)->size))); \
63 free (x); \
64 } \
65 (x) = 0; \
66 }
67
68 /* management */
69 Huge *huge_new (int size);
70 void huge_copy (Huge * a, Huge * b);
71 Huge *huge_dup (Huge * a);
72 /* void huge_free (Huge *a); */
73
74 /* type conversion */
75 Huge *huge_from_string (char *str, char **pend, int base);
76 Huge *huge_from_long (long ival);
77 Huge *huge_from_unsigned_long (unsigned long ival);
78 long huge_as_long (Huge * v);
79 unsigned long huge_as_unsigned_long (Huge * v);
80
81 /* bit manipulation */
82 Huge *huge_set_bit (Huge * v, int i);
83 void huge_clear_bit (Huge * v, int i);
84
85 /* octet stream */
86 Huge *huge_from_binary (unsigned char *s, int l);
87 char *huge_as_binary (Huge * a, int *l);
88
89 /* formatting */
90 char *huge_format (Huge * a, int base);
91 char *huge_oct (Huge * v);
92 char *huge_hex (Huge * v);
93 char *huge_dec (Huge * v);
94
95 /* comparison */
96 int huge_compare (Huge * a, Huge * b);
97 int huge_nonzero (Huge * v);
98
99 /* arithmetic */
100 Huge *huge_add (Huge * a, Huge * b);
101 Huge *huge_sub (Huge * a, Huge * b);
102 Huge *huge_mul (Huge * a, Huge * b);
103 Huge *huge_div (Huge * v, Huge * w);
104 Huge *huge_mod (Huge * v, Huge * w);
105 Huge *huge_divmod (Huge * v, Huge * w, Huge ** remainder /* may be null */ );
106 Huge *huge_invert (Huge * v);
107
108 /* exponentiation */
109 Huge *huge_pow (Huge * a, Huge * b);
110 Huge *huge_powmod (Huge * a, Huge * b, Huge * c);
111
112 /* unary */
113 Huge *huge_neg (Huge * v);
114 Huge *huge_abs (Huge * v);
115
116 /* shifting */
117 Huge *huge_rshift (Huge * a, int shiftby);
118 Huge *huge_lshift (Huge * a, int shiftby);
119
120 /* logical */
121 Huge *huge_and (Huge * a, Huge * b);
122 Huge *huge_xor (Huge * a, Huge * b);
123 Huge *huge_or (Huge * a, Huge * b);
124
125 /* log */
126 /* #define huge_log(x,y) xhuge_log(x,y,__FILE__,__LINE__) */
127 #define huge_log(x,y)
128 void xhuge_log(Huge *h, char *msg, char *file, int line);
129
130 #endif /* ! _HUGE_H */
131
132