readme
来自「支持SSL v2/v3, TLS, PKCS #5, PKCS #7, PKCS」· 代码 · 共 240 行
TXT
240 行
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 theGPL.Additional MPI utilities------------------------The files 'mpprime.h' and 'mpprime.c' define some useful extensions tothe MPI library for dealing with prime numbers (in particular, testingfor divisbility, and the Rabin-Miller probabilistic primality test).The files 'mplogic.h' and 'mplogic.c' define extensions to the MPIlibrary for doing bitwise logical operations and shifting.This document assumes you have read the help file for the MPI libraryand understand its conventions.Divisibility (mpprime.h)------------To test a number for divisibility by another number:mpp_divis(a, b) - test if b|ampp_divis_d(a, d) - test if d|aEach of these functions returns MP_YES if its initial argument isdivisible by its second, or MP_NO if it is not. Other errors may bereturned as appropriate (such as MP_RANGE if you try to test fordivisibility by zero).Randomness (mpprime.h)----------To generate random data:mpp_random(a) - fill a with random datampp_random_size(a, p) - fill a with p digits of random dataThe mpp_random_size() function increases the precision of a to atleast p, then fills all those digits randomly. The mp_random()function fills a to its current precision (as determined by the numberof significant digits, USED(a))Note that these functions simply use the C library's rand() functionto fill a with random digits up to its precision. This should beadequate for primality testing, but should not be used forcryptographic applications where truly random values are required forsecurity. You should call srand() in your driver program in order to seed therandom generator; this function doesn't call it.Primality Testing (mpprime.h)-----------------mpp_divis_vector(a, v, s, w) - is a divisible by any of the s values in v, and if so, w = which.mpp_divis_primes(a, np) - is a divisible by any of the first np primes?mpp_fermat(a, w) - is a pseudoprime with respect to witness w?mpp_pprime(a, nt) - run nt iterations of Rabin-Miller on a.The mpp_divis_vector() function tests a for divisibility by eachmember of an array of digits. The array is v, the size of that arrayis s. Returns MP_YES if a is divisible, and stores the index of theoffending digit in w. Returns MP_NO if a is not divisible by any ofthe digits in the array.A small table of primes is compiled into the library (typically thefirst 128 primes, although you can change this by editing the file'primes.c' before you build). The global variable prime_tab_sizecontains the number of primes in the table, and the values themselvesare in the array prime_tab[], which is an array of mp_digit.The mpp_divis_primes() function is basically just a wrapper aroundmpp_divis_vector() that uses prime_tab[] as the test vector. The npparameter is a pointer to an mp_digit -- on input, it should specifythe number of primes to be tested against. If a is divisible by anyof the primes, MP_YES is returned and np is given the prime value thatdivided a (you can use this if you're factoring, for example).Otherwise, MP_NO is returned and np is untouched.The function mpp_fermat() performs Fermat's test, using w as awitness. This test basically relies on the fact that if a is prime,and w is relatively prime to a, then: w^a = w (mod a)That is, w^(a - 1) = 1 (mod a)The function returns MP_YES if the test passes, MP_NO if it fails. Ifw is relatively prime to a, and the test fails, a is definitelycomposite. If w is relatively prime to a and the test passes, then ais either prime, or w is a false witness (the probability of thishappening depends on the choice of w and of a ... consult a numbertheory textbook for more information about this). Note: If (w, a) != 1, the output of this test is meaningless.----The function mpp_pprime() performs the Rabin-Miller probabilisticprimality test for nt rounds. If all the tests pass, MP_YES isreturned, and a is probably prime. The probability that an answer ofMP_YES is incorrect is no greater than 1 in 4^nt, and in fact isusually much less than that (this is a pessimistic estimate). If anytest fails, MP_NO is returned, and a is definitely composite.Bruce Schneier recommends at least 5 iterations of this test for mostcryptographic applications; Knuth suggests that 25 are reasonable.Run it as many times as you feel are necessary.See the programs 'makeprime.c' and 'isprime.c' for reasonable examplesof how to use these functions for primality testing.Bitwise Logic (mplogic.c)-------------The four commonest logical operations are implemented as:mpl_not(a, b) - Compute bitwise (one's) complement, b = ~ampl_and(a, b, c) - Compute bitwise AND, c = a & bmpl_or(a, b, c) - Compute bitwise OR, c = a | bmpl_xor(a, b, c) - Compute bitwise XOR, c = a ^ bLeft and right shifts are available as well. These take a number toshift, a destination, and a shift amount. The shift amount must be adigit value between 0 and DIGIT_BIT inclusive; if it is not, MP_RANGEwill be returned and the shift will not happen.mpl_rsh(a, b, d) - Compute logical right shift, b = a >> dmpl_lsh(a, b, d) - Compute logical left shift, b = a << dSince these are logical shifts, they fill with zeroes (the libraryuses a signed magnitude representation, so there are no sign bits toextend anyway).Command-line Utilities----------------------A handful of interesting command-line utilities are provided. Theseare:lap.c - Find the order of a mod m. Usage is 'lap <a> <m>'. This uses a dumb algorithm, so don't use it for a really big modulus.invmod.c - Find the inverse of a mod m, if it exists. Usage is 'invmod <a> <m>'sieve.c - A simple bitmap-based implementation of the Sieve of Eratosthenes. Used to generate the table of primes in primes.c. Usage is 'sieve <nbits>'prng.c - Uses the routines in bbs_rand.{h,c} to generate one or more 32-bit pseudo-random integers. This is mainly an example, not intended for use in a cryptographic application (the system time is the only source of entropy used)dec2hex.c - Convert decimal to hexadecimalhex2dec.c - Convert hexadecimal to decimalbasecvt.c - General radix conversion tool (supports 2-64)isprime.c - Probabilistically test an integer for primality using the Rabin-Miller pseudoprime test combined with division by small primes.primegen.c - Generate primes at random.exptmod.c - Perform modular exponentiationptab.pl - A Perl script to munge the output of the sieve program into a compilable C structure.Other Files-----------PRIMES - Some randomly generated numbers which are prime with extremely high probability.README - You're reading me already.About the Author----------------This software was written by Michael J. Fromberger. You can contactthe author as follows:E-mail: <sting@linguist.dartmouth.edu>Postal: 8000 Cummings Hall, Thayer School of Engineering Dartmouth College, Hanover, New Hampshire, USAPGP key: http://linguist.dartmouth.edu/~sting/keys/mjf.html 9736 188B 5AFA 23D6 D6AA BE0D 5856 4525 289D 9907Last updated: $Id: README,v 1.1 2000/07/14 00:44:52 nelsonb%netscape.com Exp $
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?