OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 /* This file implements moduluar exponentiation using Montgomery's | 5 /* This file implements moduluar exponentiation using Montgomery's |
6 * method for modular reduction. This file implements the method | 6 * method for modular reduction. This file implements the method |
7 * described as "Improvement 2" in the paper "A Cryptogrpahic Library for | 7 * described as "Improvement 2" in the paper "A Cryptogrpahic Library for |
8 * the Motorola DSP56000" by Stephen R. Dusse' and Burton S. Kaliski Jr. | 8 * the Motorola DSP56000" by Stephen R. Dusse' and Burton S. Kaliski Jr. |
9 * published in "Advances in Cryptology: Proceedings of EUROCRYPT '90" | 9 * published in "Advances in Cryptology: Proceedings of EUROCRYPT '90" |
10 * "Lecture Notes in Computer Science" volume 473, 1991, pg 230-244, | 10 * "Lecture Notes in Computer Science" volume 473, 1991, pg 230-244, |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 * in this current code the size of mp_weave_word must be four. The code that | 619 * in this current code the size of mp_weave_word must be four. The code that |
620 * makes this assumption explicity is called out. (on some platforms a write | 620 * makes this assumption explicity is called out. (on some platforms a write |
621 * of 4 bytes still requires a single read-modify-write operation. | 621 * of 4 bytes still requires a single read-modify-write operation. |
622 * | 622 * |
623 * This function is takes the identical parameters as the function above, | 623 * This function is takes the identical parameters as the function above, |
624 * however it lays out the final array differently. Where the previous function | 624 * however it lays out the final array differently. Where the previous function |
625 * treats the mpi_int as an byte array, this function treats it as an array of | 625 * treats the mpi_int as an byte array, this function treats it as an array of |
626 * mp_digits where each digit is stored in big endian order. | 626 * mp_digits where each digit is stored in big endian order. |
627 * | 627 * |
628 * since we need to interleave on a byte by byte basis, we need to collect | 628 * since we need to interleave on a byte by byte basis, we need to collect |
629 * several mpi structures together into a single uint32 before we write. We | 629 * several mpi structures together into a single PRUint32 before we write. We |
630 * also need to make sure the uint32 is arranged so that the first value of | 630 * also need to make sure the PRUint32 is arranged so that the first value of |
631 * the first array winds up in b[0]. This means construction of that uint32 | 631 * the first array winds up in b[0]. This means construction of that PRUint32 |
632 * is endian specific (even though the layout of the mp_digits in the array | 632 * is endian specific (even though the layout of the mp_digits in the array |
633 * is always big endian). | 633 * is always big endian). |
634 * | 634 * |
635 * The final data is stored as follows : | 635 * The final data is stored as follows : |
636 * | 636 * |
637 * Our same logical array p array, m is sizeof(mp_digit), | 637 * Our same logical array p array, m is sizeof(mp_digit), |
638 * N is still count and n is now b_size. If we define p[i].digit[j]0 as the | 638 * N is still count and n is now b_size. If we define p[i].digit[j]0 as the |
639 * most significant byte of the word p[i].digit[j], p[i].digit[j]1 as | 639 * most significant byte of the word p[i].digit[j], p[i].digit[j]1 as |
640 * the next most significant byte of p[i].digit[j], ... and p[i].digit[j]m-1 | 640 * the next most significant byte of p[i].digit[j], ... and p[i].digit[j]m-1 |
641 * is the least significant byte. | 641 * is the least significant byte. |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 | 1164 |
1165 CLEANUP: | 1165 CLEANUP: |
1166 mp_clear(&montBase); | 1166 mp_clear(&montBase); |
1167 mp_clear(&goodBase); | 1167 mp_clear(&goodBase); |
1168 /* Don't mp_clear mmm.N because it is merely a copy of modulus. | 1168 /* Don't mp_clear mmm.N because it is merely a copy of modulus. |
1169 ** Just zap it. | 1169 ** Just zap it. |
1170 */ | 1170 */ |
1171 memset(&mmm, 0, sizeof mmm); | 1171 memset(&mmm, 0, sizeof mmm); |
1172 return res; | 1172 return res; |
1173 } | 1173 } |
OLD | NEW |