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

📄 bnintern.doc

📁 包含哈希,对称以及非对称的经典算法 包含经典事例
💻 DOC
📖 第 1 页 / 共 2 页
字号:
bnInit_?? function.If only one word size is in use, you may link in the file bninit??.c,which provides a trivial bnInit function.  If multiple word sizes arein use, you must provide the appropriate bnInit function.  Seebn8086.c as an example.For maximum portability, you may just compile and link in the fileslbn00.c, bn00.c and bninit00.c, which determine, using the preprocessorat compile time, the best word size to use.  (The logic is actuallylocated in the file bnsize00.h, so that the three .c files cannot get outof sync.)The bignum buffers are allocated using the memory management routines inlbnmem.c.  These are word-size independent; they expect byte counts andexpect the system malloc() to return suitably aligned buffers.  Themain reason for this wrapper layer is to support any customized allocatorsthat the user might want to provide.* Other bn*.c filesbnprint.c is a simple routine for printing a bignum in hex.  It isprovided in a separate file so that its calls to stdio can be eliminatedfrom the link process if the capability is not needed.bntest??.c is a very useful regression test if you're implementingassembly primitives.  If it doesn't complain, you've probablygot it right.  It also does timing tests so you can see the effectsof any changes.* Other filessieve.c contains some primitives which use the bignum library to performsieving (trial division) of ranges of numbers looking for candidate primes.This involves two steps: using a sieve of Eratosthenes to generate theprimes up to 65536, and using that to do trial division on a range ofnumbers following a larger input number.  Note that this is designedfor large numbers, greater than 65536, since there is no check to seeif the input is one of the small primes; if it is divisible, it is assumedcomposite.prime.c uses sieve.c to generate primes.  It uses sieve.c to eliminatenumbers with trivial divisors, then does strong pseudoprimality testswith some small bases.  (Actually, the first test, to the base 2, isoptimized a bit to be faster when it fails, which is the common case,but 1/8 of the time it's not a strong pseudoprimality test, so an extra,strong, test is done in that case.)It prints progress indicators as it searches.  The algorithmsearches a range of numbers starting at a given prime, but it doesso in a "shuffled" order, inspired by algorithm M from Knuth.  (Therandom number generator to use for this is passed in; if no functionis given, the numbers are searched in sequential order and thereturns value will be the next prime >= the input value.)germain.c operates similarly, but generates Sophie Germain primes;that is, primes p such that (p-1)/2 is also prime.  It lacks theshuffling feature - searching is always sequential.jacobi.c computes the Jacobi symbol between a small integer and a BigNum.It's currently only ever used in germain.c.* SourcesObviously, a key source of information was Knuth, Volume 2,particularly on division algorithms.The greatest inspiration, however, was Arjen Lenstra's LIP(Large Integer Package), distributed with the RSA-129 effort.While very difficult to read (there is no internal documentation onsometimes very subtle algorithms), it showed me many useful tricks,notably the windowed exponentiation algorithm that saves so manymultiplies.  If you need a more general-purpose large-integer package,with only a minor speed penalty, the LIP package is almost certainlythe best available.  It implements a great range of efficientalgorithms.The second most important source was Torbjorn Granlund's gmp(GNU multi-precision) library.  A number of C coding tricks wereadapted from there.  I'd like to thank Torbjorn for some usefuldiscussions and letting me see his development work on GMP 2.0.Antoon Bosselaers, Rene' Govaerts and Joos Vandewalle, in their CRYPTO'93 paper, "Comparison of three modular reduction functions", broughtMontgomery reduction to my attention, for which I am grateful.Burt Kaliski's article in the September 1993 Dr. Dobb's Journal,"The Z80180 and Big-number Arithmetic" pointed out the advantages (andterminology) of product scanning to me, although the limitedexperiments I've done have shown no improvement from trying it in C.Hans Reisel's book, "Prime Numbers and Computer Methods for Factorization"was of great help in designing the prime testing, although some ofthe code in the book, notably the Jacobi function in Appendix 3,is an impressive example of why GOTO should be considered harmful.Papers by R. G. E. Pinch and others in Mathematics of Computation werealso very useful.Keith Geddes, Stephen Czapor and George Labahn's book "Algorithmsfor Computer Algebra", although it's mostly about polynomials,has some useful multi-precision math examples.Philip Zimmermann's mpi (multi-precision integer) library suggestedstoring the numbers in native byte order to facilitate assemblysubroutines, although the core modular multiplication algorithms areso confusing that I still don't understand them.  His boasting aboutthe speed of his library (albeit in 1986, before any of the above wereavailable for study) also inspired me to particular effort to soundlybeat it.  It also provoked a strong reaction from me against fixedbuffer sizes, and complaints about its implementation from Paul Leyland(interface) and Robert Silverman (prime searching) contributed usefullyto the design of this current library.I'd like to credit all of the above, plus the Berkeley MP package, withgiving me difficulty finding a short, unique distinguishing prefix formy library's functions.  (I have just, sigh, discovered that Eric Youngis using the same prefix for *his* library, although with thebn_function_name convention as opposed to the bnFunctionName one.)I'd like to thank the original implementor of Unix "dc" and "factor"for providing useful tools for verifying the correct operation ofmy library.* Future- Obviously, assembly-language subroutines for more platforms would  always be nice.- There's a special case in the division for a two-word denominator  which should be completed.- When the quotient of a division is big enough, compute an inverse of  the high word of the denominator and use multiplication by that  to do the divide.- A more efficient GCD algorithm would be nice to have.- More efficient modular inversion is possible.  Do it.- Extend modular inversion to deal with non-relatively-prime  inputs.  Produce y = inv(x,m) with y * x == gcd(x,m) mod m.- Try some product scanning in assembly.- Karatsuba's multiplication and squaring speedups would be nice.- I *don't* think that FFT-based algorithms are worth implementing yet,  but it's worth a little bit of study to make sure.- More general support for numbers in Montgomery form, so they can  be used by more than the bowels of lbnExpMod.- Provide an lbnExpMod optimized for small arguments > 2, using  conventional (or even Barrett) reduction of the multiplies, and  Montgomery reduction of the squarings.- Adding a Lucas-based prime test would be a real coup, although it's  hard to give rational reasons why it's necessary.  I have a number of  ideas on this already.  Find out if norm-1 (which is faster to  compute) suffices.- Split up the source code more to support linking with smaller subsets  of the library.

⌨️ 快捷键说明

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