diff options
author | David Walter Seikel | 2011-06-27 15:59:06 +1000 |
---|---|---|
committer | David Walter Seikel | 2011-06-27 15:59:06 +1000 |
commit | 92bd9b2503e7dd927f416cb9b17f169ea925fa56 (patch) | |
tree | f0f3776cfc0c6e6224db66f5678387c580095f16 /linden/indra/libgcrypt/libgcrypt-1.2.2/mpi/mpi-bit.c | |
parent | Make use of the new packaging stuff from upstream. (diff) | |
download | meta-impy-92bd9b2503e7dd927f416cb9b17f169ea925fa56.zip meta-impy-92bd9b2503e7dd927f416cb9b17f169ea925fa56.tar.gz meta-impy-92bd9b2503e7dd927f416cb9b17f169ea925fa56.tar.bz2 meta-impy-92bd9b2503e7dd927f416cb9b17f169ea925fa56.tar.xz |
Clean up line endings, execute bits, and other bits of errant nonsense from Windows.
Diffstat (limited to 'linden/indra/libgcrypt/libgcrypt-1.2.2/mpi/mpi-bit.c')
-rw-r--r--[-rwxr-xr-x] | linden/indra/libgcrypt/libgcrypt-1.2.2/mpi/mpi-bit.c | 514 |
1 files changed, 257 insertions, 257 deletions
diff --git a/linden/indra/libgcrypt/libgcrypt-1.2.2/mpi/mpi-bit.c b/linden/indra/libgcrypt/libgcrypt-1.2.2/mpi/mpi-bit.c index 00cfc1c..26853ef 100755..100644 --- a/linden/indra/libgcrypt/libgcrypt-1.2.2/mpi/mpi-bit.c +++ b/linden/indra/libgcrypt/libgcrypt-1.2.2/mpi/mpi-bit.c | |||
@@ -1,257 +1,257 @@ | |||
1 | /* mpi-bit.c - MPI bit level fucntions | 1 | /* mpi-bit.c - MPI bit level fucntions |
2 | * Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. | 2 | * Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. |
3 | * | 3 | * |
4 | * This file is part of Libgcrypt. | 4 | * This file is part of Libgcrypt. |
5 | * | 5 | * |
6 | * Libgcrypt is free software; you can redistribute it and/or modify | 6 | * Libgcrypt is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU Lesser General Public License as | 7 | * it under the terms of the GNU Lesser General Public License as |
8 | * published by the Free Software Foundation; either version 2.1 of | 8 | * published by the Free Software Foundation; either version 2.1 of |
9 | * the License, or (at your option) any later version. | 9 | * the License, or (at your option) any later version. |
10 | * | 10 | * |
11 | * Libgcrypt is distributed in the hope that it will be useful, | 11 | * Libgcrypt is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU Lesser General Public License for more details. | 14 | * GNU Lesser General Public License for more details. |
15 | * | 15 | * |
16 | * You should have received a copy of the GNU Lesser General Public | 16 | * You should have received a copy of the GNU Lesser General Public |
17 | * License along with this program; if not, write to the Free Software | 17 | * License along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <config.h> | 21 | #include <config.h> |
22 | #include <stdio.h> | 22 | #include <stdio.h> |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <assert.h> | 24 | #include <assert.h> |
25 | #include "mpi-internal.h" | 25 | #include "mpi-internal.h" |
26 | #include "longlong.h" | 26 | #include "longlong.h" |
27 | 27 | ||
28 | 28 | ||
29 | #ifdef MPI_INTERNAL_NEED_CLZ_TAB | 29 | #ifdef MPI_INTERNAL_NEED_CLZ_TAB |
30 | #ifdef __STDC__ | 30 | #ifdef __STDC__ |
31 | const | 31 | const |
32 | #endif | 32 | #endif |
33 | unsigned char | 33 | unsigned char |
34 | _gcry_clz_tab[] = | 34 | _gcry_clz_tab[] = |
35 | { | 35 | { |
36 | 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5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,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, |
44 | }; | 44 | }; |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | 47 | ||
48 | #define A_LIMB_1 ((mpi_limb_t)1) | 48 | #define A_LIMB_1 ((mpi_limb_t)1) |
49 | 49 | ||
50 | 50 | ||
51 | /**************** | 51 | /**************** |
52 | * Sometimes we have MSL (most significant limbs) which are 0; | 52 | * Sometimes we have MSL (most significant limbs) which are 0; |
53 | * this is for some reasons not good, so this function removes them. | 53 | * this is for some reasons not good, so this function removes them. |
54 | */ | 54 | */ |
55 | void | 55 | void |
56 | _gcry_mpi_normalize( gcry_mpi_t a ) | 56 | _gcry_mpi_normalize( gcry_mpi_t a ) |
57 | { | 57 | { |
58 | if( mpi_is_opaque(a) ) | 58 | if( mpi_is_opaque(a) ) |
59 | return; | 59 | return; |
60 | 60 | ||
61 | for( ; a->nlimbs && !a->d[a->nlimbs-1]; a->nlimbs-- ) | 61 | for( ; a->nlimbs && !a->d[a->nlimbs-1]; a->nlimbs-- ) |
62 | ; | 62 | ; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | 66 | ||
67 | /**************** | 67 | /**************** |
68 | * Return the number of bits in A. | 68 | * Return the number of bits in A. |
69 | */ | 69 | */ |
70 | unsigned int | 70 | unsigned int |
71 | gcry_mpi_get_nbits( gcry_mpi_t a ) | 71 | gcry_mpi_get_nbits( gcry_mpi_t a ) |
72 | { | 72 | { |
73 | unsigned n; | 73 | unsigned n; |
74 | 74 | ||
75 | if( mpi_is_opaque(a) ) { | 75 | if( mpi_is_opaque(a) ) { |
76 | return a->sign; /* which holds the number of bits */ | 76 | return a->sign; /* which holds the number of bits */ |
77 | } | 77 | } |
78 | 78 | ||
79 | _gcry_mpi_normalize( a ); | 79 | _gcry_mpi_normalize( a ); |
80 | if( a->nlimbs ) { | 80 | if( a->nlimbs ) { |
81 | mpi_limb_t alimb = a->d[a->nlimbs-1]; | 81 | mpi_limb_t alimb = a->d[a->nlimbs-1]; |
82 | if( alimb ) | 82 | if( alimb ) |
83 | count_leading_zeros( n, alimb ); | 83 | count_leading_zeros( n, alimb ); |
84 | else | 84 | else |
85 | n = BITS_PER_MPI_LIMB; | 85 | n = BITS_PER_MPI_LIMB; |
86 | n = BITS_PER_MPI_LIMB - n + (a->nlimbs-1) * BITS_PER_MPI_LIMB; | 86 | n = BITS_PER_MPI_LIMB - n + (a->nlimbs-1) * BITS_PER_MPI_LIMB; |
87 | } | 87 | } |
88 | else | 88 | else |
89 | n = 0; | 89 | n = 0; |
90 | return n; | 90 | return n; |
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | /**************** | 94 | /**************** |
95 | * Test whether bit N is set. | 95 | * Test whether bit N is set. |
96 | */ | 96 | */ |
97 | int | 97 | int |
98 | gcry_mpi_test_bit( gcry_mpi_t a, unsigned int n ) | 98 | gcry_mpi_test_bit( gcry_mpi_t a, unsigned int n ) |
99 | { | 99 | { |
100 | unsigned int limbno, bitno; | 100 | unsigned int limbno, bitno; |
101 | mpi_limb_t limb; | 101 | mpi_limb_t limb; |
102 | 102 | ||
103 | limbno = n / BITS_PER_MPI_LIMB; | 103 | limbno = n / BITS_PER_MPI_LIMB; |
104 | bitno = n % BITS_PER_MPI_LIMB; | 104 | bitno = n % BITS_PER_MPI_LIMB; |
105 | 105 | ||
106 | if( limbno >= a->nlimbs ) | 106 | if( limbno >= a->nlimbs ) |
107 | return 0; /* too far left: this is a 0 */ | 107 | return 0; /* too far left: this is a 0 */ |
108 | limb = a->d[limbno]; | 108 | limb = a->d[limbno]; |
109 | return (limb & (A_LIMB_1 << bitno))? 1: 0; | 109 | return (limb & (A_LIMB_1 << bitno))? 1: 0; |
110 | } | 110 | } |
111 | 111 | ||
112 | 112 | ||
113 | /**************** | 113 | /**************** |
114 | * Set bit N of A. | 114 | * Set bit N of A. |
115 | */ | 115 | */ |
116 | void | 116 | void |
117 | gcry_mpi_set_bit( gcry_mpi_t a, unsigned int n ) | 117 | gcry_mpi_set_bit( gcry_mpi_t a, unsigned int n ) |
118 | { | 118 | { |
119 | unsigned int limbno, bitno; | 119 | unsigned int limbno, bitno; |
120 | 120 | ||
121 | limbno = n / BITS_PER_MPI_LIMB; | 121 | limbno = n / BITS_PER_MPI_LIMB; |
122 | bitno = n % BITS_PER_MPI_LIMB; | 122 | bitno = n % BITS_PER_MPI_LIMB; |
123 | 123 | ||
124 | if( limbno >= a->nlimbs ) { /* resize */ | 124 | if( limbno >= a->nlimbs ) { /* resize */ |
125 | if( a->alloced >= limbno ) | 125 | if( a->alloced >= limbno ) |
126 | mpi_resize(a, limbno+1 ); | 126 | mpi_resize(a, limbno+1 ); |
127 | a->nlimbs = limbno+1; | 127 | a->nlimbs = limbno+1; |
128 | } | 128 | } |
129 | a->d[limbno] |= (A_LIMB_1<<bitno); | 129 | a->d[limbno] |= (A_LIMB_1<<bitno); |
130 | } | 130 | } |
131 | 131 | ||
132 | /**************** | 132 | /**************** |
133 | * Set bit N of A. and clear all bits above | 133 | * Set bit N of A. and clear all bits above |
134 | */ | 134 | */ |
135 | void | 135 | void |
136 | gcry_mpi_set_highbit( gcry_mpi_t a, unsigned int n ) | 136 | gcry_mpi_set_highbit( gcry_mpi_t a, unsigned int n ) |
137 | { | 137 | { |
138 | unsigned int limbno, bitno; | 138 | unsigned int limbno, bitno; |
139 | 139 | ||
140 | limbno = n / BITS_PER_MPI_LIMB; | 140 | limbno = n / BITS_PER_MPI_LIMB; |
141 | bitno = n % BITS_PER_MPI_LIMB; | 141 | bitno = n % BITS_PER_MPI_LIMB; |
142 | 142 | ||
143 | if( limbno >= a->nlimbs ) { /* resize */ | 143 | if( limbno >= a->nlimbs ) { /* resize */ |
144 | if( a->alloced >= limbno ) | 144 | if( a->alloced >= limbno ) |
145 | mpi_resize(a, limbno+1 ); | 145 | mpi_resize(a, limbno+1 ); |
146 | a->nlimbs = limbno+1; | 146 | a->nlimbs = limbno+1; |
147 | } | 147 | } |
148 | a->d[limbno] |= (A_LIMB_1<<bitno); | 148 | a->d[limbno] |= (A_LIMB_1<<bitno); |
149 | for( bitno++; bitno < BITS_PER_MPI_LIMB; bitno++ ) | 149 | for( bitno++; bitno < BITS_PER_MPI_LIMB; bitno++ ) |
150 | a->d[limbno] &= ~(A_LIMB_1 << bitno); | 150 | a->d[limbno] &= ~(A_LIMB_1 << bitno); |
151 | a->nlimbs = limbno+1; | 151 | a->nlimbs = limbno+1; |
152 | } | 152 | } |
153 | 153 | ||
154 | /**************** | 154 | /**************** |
155 | * clear bit N of A and all bits above | 155 | * clear bit N of A and all bits above |
156 | */ | 156 | */ |
157 | void | 157 | void |
158 | gcry_mpi_clear_highbit( gcry_mpi_t a, unsigned int n ) | 158 | gcry_mpi_clear_highbit( gcry_mpi_t a, unsigned int n ) |
159 | { | 159 | { |
160 | unsigned int limbno, bitno; | 160 | unsigned int limbno, bitno; |
161 | 161 | ||
162 | limbno = n / BITS_PER_MPI_LIMB; | 162 | limbno = n / BITS_PER_MPI_LIMB; |
163 | bitno = n % BITS_PER_MPI_LIMB; | 163 | bitno = n % BITS_PER_MPI_LIMB; |
164 | 164 | ||
165 | if( limbno >= a->nlimbs ) | 165 | if( limbno >= a->nlimbs ) |
166 | return; /* not allocated, so need to clear bits :-) */ | 166 | return; /* not allocated, so need to clear bits :-) */ |
167 | 167 | ||
168 | for( ; bitno < BITS_PER_MPI_LIMB; bitno++ ) | 168 | for( ; bitno < BITS_PER_MPI_LIMB; bitno++ ) |
169 | a->d[limbno] &= ~(A_LIMB_1 << bitno); | 169 | a->d[limbno] &= ~(A_LIMB_1 << bitno); |
170 | a->nlimbs = limbno+1; | 170 | a->nlimbs = limbno+1; |
171 | } | 171 | } |
172 | 172 | ||
173 | /**************** | 173 | /**************** |
174 | * Clear bit N of A. | 174 | * Clear bit N of A. |
175 | */ | 175 | */ |
176 | void | 176 | void |
177 | gcry_mpi_clear_bit( gcry_mpi_t a, unsigned int n ) | 177 | gcry_mpi_clear_bit( gcry_mpi_t a, unsigned int n ) |
178 | { | 178 | { |
179 | unsigned int limbno, bitno; | 179 | unsigned int limbno, bitno; |
180 | 180 | ||
181 | limbno = n / BITS_PER_MPI_LIMB; | 181 | limbno = n / BITS_PER_MPI_LIMB; |
182 | bitno = n % BITS_PER_MPI_LIMB; | 182 | bitno = n % BITS_PER_MPI_LIMB; |
183 | 183 | ||
184 | if( limbno >= a->nlimbs ) | 184 | if( limbno >= a->nlimbs ) |
185 | return; /* don't need to clear this bit, it's to far to left */ | 185 | return; /* don't need to clear this bit, it's to far to left */ |
186 | a->d[limbno] &= ~(A_LIMB_1 << bitno); | 186 | a->d[limbno] &= ~(A_LIMB_1 << bitno); |
187 | } | 187 | } |
188 | 188 | ||
189 | 189 | ||
190 | /**************** | 190 | /**************** |
191 | * Shift A by N bits to the right | 191 | * Shift A by N bits to the right |
192 | * FIXME: should use alloc_limb if X and A are same. | 192 | * FIXME: should use alloc_limb if X and A are same. |
193 | */ | 193 | */ |
194 | void | 194 | void |
195 | gcry_mpi_rshift( gcry_mpi_t x, gcry_mpi_t a, unsigned n ) | 195 | gcry_mpi_rshift( gcry_mpi_t x, gcry_mpi_t a, unsigned n ) |
196 | { | 196 | { |
197 | mpi_ptr_t xp; | 197 | mpi_ptr_t xp; |
198 | mpi_size_t xsize; | 198 | mpi_size_t xsize; |
199 | 199 | ||
200 | xsize = a->nlimbs; | 200 | xsize = a->nlimbs; |
201 | x->sign = a->sign; | 201 | x->sign = a->sign; |
202 | RESIZE_IF_NEEDED(x, xsize); | 202 | RESIZE_IF_NEEDED(x, xsize); |
203 | xp = x->d; | 203 | xp = x->d; |
204 | 204 | ||
205 | if( xsize ) { | 205 | if( xsize ) { |
206 | _gcry_mpih_rshift( xp, a->d, xsize, n); | 206 | _gcry_mpih_rshift( xp, a->d, xsize, n); |
207 | MPN_NORMALIZE( xp, xsize); | 207 | MPN_NORMALIZE( xp, xsize); |
208 | } | 208 | } |
209 | x->nlimbs = xsize; | 209 | x->nlimbs = xsize; |
210 | } | 210 | } |
211 | 211 | ||
212 | 212 | ||
213 | /**************** | 213 | /**************** |
214 | * Shift A by COUNT limbs to the left | 214 | * Shift A by COUNT limbs to the left |
215 | * This is used only within the MPI library | 215 | * This is used only within the MPI library |
216 | */ | 216 | */ |
217 | void | 217 | void |
218 | _gcry_mpi_lshift_limbs( gcry_mpi_t a, unsigned int count ) | 218 | _gcry_mpi_lshift_limbs( gcry_mpi_t a, unsigned int count ) |
219 | { | 219 | { |
220 | mpi_ptr_t ap = a->d; | 220 | mpi_ptr_t ap = a->d; |
221 | int n = a->nlimbs; | 221 | int n = a->nlimbs; |
222 | int i; | 222 | int i; |
223 | 223 | ||
224 | if( !count || !n ) | 224 | if( !count || !n ) |
225 | return; | 225 | return; |
226 | 226 | ||
227 | RESIZE_IF_NEEDED( a, n+count ); | 227 | RESIZE_IF_NEEDED( a, n+count ); |
228 | 228 | ||
229 | for( i = n-1; i >= 0; i-- ) | 229 | for( i = n-1; i >= 0; i-- ) |
230 | ap[i+count] = ap[i]; | 230 | ap[i+count] = ap[i]; |
231 | for(i=0; i < count; i++ ) | 231 | for(i=0; i < count; i++ ) |
232 | ap[i] = 0; | 232 | ap[i] = 0; |
233 | a->nlimbs += count; | 233 | a->nlimbs += count; |
234 | } | 234 | } |
235 | 235 | ||
236 | 236 | ||
237 | /**************** | 237 | /**************** |
238 | * Shift A by COUNT limbs to the right | 238 | * Shift A by COUNT limbs to the right |
239 | * This is used only within the MPI library | 239 | * This is used only within the MPI library |
240 | */ | 240 | */ |
241 | void | 241 | void |
242 | _gcry_mpi_rshift_limbs( gcry_mpi_t a, unsigned int count ) | 242 | _gcry_mpi_rshift_limbs( gcry_mpi_t a, unsigned int count ) |
243 | { | 243 | { |
244 | mpi_ptr_t ap = a->d; | 244 | mpi_ptr_t ap = a->d; |
245 | mpi_size_t n = a->nlimbs; | 245 | mpi_size_t n = a->nlimbs; |
246 | unsigned int i; | 246 | unsigned int i; |
247 | 247 | ||
248 | if( count >= n ) { | 248 | if( count >= n ) { |
249 | a->nlimbs = 0; | 249 | a->nlimbs = 0; |
250 | return; | 250 | return; |
251 | } | 251 | } |
252 | 252 | ||
253 | for( i = 0; i < n - count; i++ ) | 253 | for( i = 0; i < n - count; i++ ) |
254 | ap[i] = ap[i+count]; | 254 | ap[i] = ap[i+count]; |
255 | ap[i] = 0; | 255 | ap[i] = 0; |
256 | a->nlimbs -= count; | 256 | a->nlimbs -= count; |
257 | } | 257 | } |