⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 redux.txt

📁 支持SSL v2/v3, TLS, PKCS #5, PKCS #7, PKCS #11, PKCS #12, S/MIME, X.509v3证书等安全协议或标准的开发库编译用到NSPR
💻 TXT
字号:
Modular ReductionUsually, modular reduction is accomplished by long division, using themp_div() or mp_mod() functions.  However, when performing modularexponentiation, you spend a lot of time reducing by the same modulusagain and again.  For this purpose, doing a full division for eachmultiplication is quite inefficient.For this reason, the mp_exptmod() function does not perform modularreductions in the usual way, but instead takes advantage of analgorithm due to Barrett, as described by Menezes, Oorschot andVanStone in their book _Handbook of Applied Cryptography_, publishedby the CRC Press (see Chapter 14 for details).  This method reducesmost of the computation of reduction to efficient shifting and maskingoperations, and avoids the multiple-precision division entirely.Here is a brief synopsis of Barrett reduction, as it is implemented inthis library.Let b denote the radix of the computation (one more than the maximumvalue that can be denoted by an mp_digit).  Let m be the modulus, andlet k be the number of significant digits of m.  Let x be the value tobe reduced modulo m.  By the Division Theorem, there exist uniqueintegers Q and R such that:	 x = Qm + R, 0 <= R < mBarrett reduction takes advantage of the fact that you can easilyapproximate Q to within two, given a value M such that:	                  2k	                 b	    M = floor( ----- )	                 mComputation of M requires a full-precision division step, so if youare only doing a single reduction by m, you gain no advantage.However, when multiple reductions by the same m are required, thisdivision need only be done once, beforehand.  Using this, we can usethe following equation to compute Q', an approximation of Q:                     x            floor( ------ ) M                      k-1                     bQ' = floor( ----------------- )                    k+1                   bThe divisions by b^(k-1) and b^(k+1) and the floor() functions can beefficiently implemented with shifts and masks, leaving only a singlemultiplication to be performed to get this approximation.  It can beshown that Q - 2 <= Q' <= Q, so in the worst case, we can get out withtwo additional subtractions to bring the value into line with theactual value of Q.Once we've got Q', we basically multiply that by m and subtract fromx, yielding:   x - Q'm = Qm + R - Q'mSince we know the constraint on Q', this is one of:      R      m + R      2m + RSince R < m by the Division Theorem, we can simply subtract off muntil we get a value in the correct range, which will happen with nomore than 2 subtractions:     v = x - Q'm     while(v >= m)       v = v - m     endwhileIn random performance trials, modular exponentiation using this methodof reduction gave around a 40% speedup over using the division forreduction.------------------------------------------------------------------The contents of this file are subject to the Mozilla PublicLicense Version 1.1 (the "License"); you may not use this fileexcept in compliance with the License. You may obtain a copy ofthe License at http://www.mozilla.org/MPL/Software distributed under the License is distributed on an "ASIS" basis, WITHOUT WARRANTY OF ANY KIND, either express orimplied. See the License for the specific language governingrights and limitations under the License.The Original Code is the MPI Arbitrary Precision Integer Arithmeticlibrary.The Initial Developer of the Original Code is Michael J. Fromberger <sting@linguist.dartmouth.edu>Portions created by Michael J. Fromberger are Copyright (C) 1998, 2000 Michael J. Fromberger. All Rights Reserved.Contributor(s):Alternatively, the contents of this file may be used under theterms of the GNU General Public License Version 2 or later (the"GPL"), in which case the provisions of the GPL are applicableinstead of those above.  If you wish to allow use of yourversion of this file only under the terms of the GPL and not toallow others to use your version of this file under the MPL,indicate your decision by deleting the provisions above andreplace them with the notice and other provisions required bythe GPL.  If you do not delete the provisions above, a recipientmay use your version of this file under either the MPL or the GPL.$Id: redux.txt,v 1.1 2000/07/14 00:44:36 nelsonb%netscape.com Exp $

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -