OLD | NEW |
1 /* | 1 /* |
2 * ***** BEGIN LICENSE BLOCK ***** | 2 * ***** BEGIN LICENSE BLOCK ***** |
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
4 * | 4 * |
5 * The contents of this file are subject to the Mozilla Public License Version | 5 * The contents of this file are subject to the Mozilla Public License Version |
6 * 1.1 (the "License"); you may not use this file except in compliance with | 6 * 1.1 (the "License"); you may not use this file except in compliance with |
7 * the License. You may obtain a copy of the License at | 7 * the License. You may obtain a copy of the License at |
8 * http://www.mozilla.org/MPL/ | 8 * http://www.mozilla.org/MPL/ |
9 * | 9 * |
10 * Software distributed under the License is distributed on an "AS IS" basis, | 10 * Software distributed under the License is distributed on an "AS IS" basis, |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 | 352 |
353 /* The algorithm does the reduction in place in r, | 353 /* The algorithm does the reduction in place in r, |
354 * if a != r, copy a into r first so reduction can be done in r | 354 * if a != r, copy a into r first so reduction can be done in r |
355 */ | 355 */ |
356 if (a != r) { | 356 if (a != r) { |
357 MP_CHECKOK( mp_copy(a, r) ); | 357 MP_CHECKOK( mp_copy(a, r) ); |
358 } | 358 } |
359 z = MP_DIGITS(r); | 359 z = MP_DIGITS(r); |
360 | 360 |
361 /* start reduction */ | 361 /* start reduction */ |
362 dN = p[0] / MP_DIGIT_BITS; | 362 /*dN = p[0] / MP_DIGIT_BITS; */ |
| 363 dN = p[0] >> MP_DIGIT_BITS_LOG_2; |
363 used = MP_USED(r); | 364 used = MP_USED(r); |
364 | 365 |
365 for (j = used - 1; j > dN;) { | 366 for (j = used - 1; j > dN;) { |
366 | 367 |
367 zz = z[j]; | 368 zz = z[j]; |
368 if (zz == 0) { | 369 if (zz == 0) { |
369 j--; continue; | 370 j--; continue; |
370 } | 371 } |
371 z[j] = 0; | 372 z[j] = 0; |
372 | 373 |
373 for (k = 1; p[k] > 0; k++) { | 374 for (k = 1; p[k] > 0; k++) { |
374 /* reducing component t^p[k] */ | 375 /* reducing component t^p[k] */ |
375 n = p[0] - p[k]; | 376 n = p[0] - p[k]; |
376 d0 = n % MP_DIGIT_BITS; | 377 /*d0 = n % MP_DIGIT_BITS; */ |
| 378 d0 = n & MP_DIGIT_BITS_MASK; |
377 d1 = MP_DIGIT_BITS - d0; | 379 d1 = MP_DIGIT_BITS - d0; |
378 n /= MP_DIGIT_BITS; | 380 /*n /= MP_DIGIT_BITS; */ |
| 381 n >>= MP_DIGIT_BITS_LOG_2; |
379 z[j-n] ^= (zz>>d0); | 382 z[j-n] ^= (zz>>d0); |
380 if (d0) | 383 if (d0) |
381 z[j-n-1] ^= (zz<<d1); | 384 z[j-n-1] ^= (zz<<d1); |
382 } | 385 } |
383 | 386 |
384 /* reducing component t^0 */ | 387 /* reducing component t^0 */ |
385 n = dN; | 388 n = dN; |
386 d0 = p[0] % MP_DIGIT_BITS; | 389 /*d0 = p[0] % MP_DIGIT_BITS;*/ |
| 390 d0 = p[0] & MP_DIGIT_BITS_MASK; |
387 d1 = MP_DIGIT_BITS - d0; | 391 d1 = MP_DIGIT_BITS - d0; |
388 z[j-n] ^= (zz >> d0); | 392 z[j-n] ^= (zz >> d0); |
389 if (d0) | 393 if (d0) |
390 z[j-n-1] ^= (zz << d1); | 394 z[j-n-1] ^= (zz << d1); |
391 | 395 |
392 } | 396 } |
393 | 397 |
394 /* final round of reduction */ | 398 /* final round of reduction */ |
395 while (j == dN) { | 399 while (j == dN) { |
396 | 400 |
397 d0 = p[0] % MP_DIGIT_BITS; | 401 /* d0 = p[0] % MP_DIGIT_BITS; */ |
| 402 d0 = p[0] & MP_DIGIT_BITS_MASK; |
398 zz = z[dN] >> d0; | 403 zz = z[dN] >> d0; |
399 if (zz == 0) break; | 404 if (zz == 0) break; |
400 d1 = MP_DIGIT_BITS - d0; | 405 d1 = MP_DIGIT_BITS - d0; |
401 | 406 |
402 /* clear up the top d1 bits */ | 407 /* clear up the top d1 bits */ |
403 if (d0) z[dN] = (z[dN] << d1) >> d1; | 408 if (d0) { |
| 409 » z[dN] = (z[dN] << d1) >> d1; |
| 410 » } else { |
| 411 » z[dN] = 0; |
| 412 » } |
404 *z ^= zz; /* reduction t^0 component */ | 413 *z ^= zz; /* reduction t^0 component */ |
405 | 414 |
406 for (k = 1; p[k] > 0; k++) { | 415 for (k = 1; p[k] > 0; k++) { |
407 /* reducing component t^p[k]*/ | 416 /* reducing component t^p[k]*/ |
408 n = p[k] / MP_DIGIT_BITS; | 417 /* n = p[k] / MP_DIGIT_BITS; */ |
409 d0 = p[k] % MP_DIGIT_BITS; | 418 n = p[k] >> MP_DIGIT_BITS_LOG_2; |
| 419 /* d0 = p[k] % MP_DIGIT_BITS; */ |
| 420 d0 = p[k] & MP_DIGIT_BITS_MASK; |
410 d1 = MP_DIGIT_BITS - d0; | 421 d1 = MP_DIGIT_BITS - d0; |
411 z[n] ^= (zz << d0); | 422 z[n] ^= (zz << d0); |
412 tmp = zz >> d1; | 423 tmp = zz >> d1; |
413 if (d0 && tmp) | 424 if (d0 && tmp) |
414 z[n+1] ^= tmp; | 425 z[n+1] ^= tmp; |
415 } | 426 } |
416 } | 427 } |
417 | 428 |
418 s_mp_clamp(r); | 429 s_mp_clamp(r); |
419 CLEANUP: | 430 CLEANUP: |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 | 605 |
595 mp_zero(a); | 606 mp_zero(a); |
596 for (i = 0; p[i] > 0; i++) { | 607 for (i = 0; p[i] > 0; i++) { |
597 MP_CHECKOK( mpl_set_bit(a, p[i], 1) ); | 608 MP_CHECKOK( mpl_set_bit(a, p[i], 1) ); |
598 } | 609 } |
599 MP_CHECKOK( mpl_set_bit(a, 0, 1) ); | 610 MP_CHECKOK( mpl_set_bit(a, 0, 1) ); |
600 | 611 |
601 CLEANUP: | 612 CLEANUP: |
602 return res; | 613 return res; |
603 } | 614 } |
OLD | NEW |