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

📄 prime.h

📁 IBE是一种非对称密码技术
💻 H
📖 第 1 页 / 共 2 页
字号:
 * it is the responsibility of the caller to pass in a valid pointer.
 * <p>If this function cannot generate a prime, it will return
 * VT_ERROR_NO_PRIME_FOUND.
 *
 * @param primeSizeBits The size, in bits, of the prime to generate.
 * @param random A random object, the source of any random bytes needed.
 * @param SEED The buffer into which the function will place the FIPS
 * SEED value.
 * @param seedLen The address where the function will deposit the
 * length, in bytes, of SEED. That is, it will be the number of bytes
 * placed into the SEED buffer.
 * @param prime Where the resulting prime will be deposited.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
int VOLT_CALLING_CONV VoltGeneratePrimeX942 VOLT_PROTO_LIST ((
   unsigned int primeSizeBits,
   VtRandomObject random,
   unsigned char *SEED,
   unsigned int *seedLen,
   VoltMpInt *prime
));

/* Run the sieve test on the candidate, then candidate + 2, then + 4
 * and so on. How far up do we go before we give up and generate a new
 * starting point? That's the SIEVE_SIZE.
 */
#define VOLT_SIEVE_SIZE  1000

/* Test the primeCandidate using the Rabin-Miller test. If it is prime,
 * set isPrime to 1, if not, set it to 0.
 * <p>Pass the primeSizeBits so the subroutine does not need to
 * recompute it. It will come in handy knowing how big the random value
 * needs to be.
 * <p>Some standards call for an iteration count of 8 or 27 or 50. So
 * whoever is calling must indicate the iteration count. It must be at
 * least 8.
 *
 * @param primeCandidate The value to test.
 * @param primeSizeBits
 * @param iterationCount
 * @param random A random object, the source of any random bytes needed.
 * @param isPrime The result, set to 1 if prime, 0 if not.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
int VOLT_CALLING_CONV VoltRabinMillerTest VOLT_PROTO_LIST ((
   VoltMpInt *primeCandidate,
   unsigned int primeSizeBits,
   unsigned int iterationCount,
   VtRandomObject random,
   unsigned int *isPrime
));

/* The Rabin-Miller test is iterative. Try a random value, then another
 * and another and so on. How many random values? That's the
 * RABIN_MILLER_COUNT.
 * For generating primes for DSA parameters following the FIPS 186-2
 * document, the minimum count is 50.
 */
#define VOLT_RABIN_MILLER_COUNT_186_2  50

/* Test the primeCandidate using the Lucas test as described in X9.31.
 * If it is prime, set isPrime to 1, if not, set it to 0.
 * <p>This function does not check the validity of the arguments. It is
 * the responsibility of the caller to pass in a valid (created and
 * set) primeCandidate and a valid address for isPrime.
 *
 * @param primeCandidate The value to test.
 * @param isPrime The result, set to 1 if prime, 0 if not.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
int VOLT_CALLING_CONV VoltLucasTest VOLT_PROTO_LIST ((
   VoltMpInt *primeCandidate,
   unsigned int *isPrime
));

/* Check that prime - 1 is relatively prime with relativePrime.
 * <p>If they are relatively prime, set relPrime to 1 (true, yes), and
 * if they are not, set it to 0 (false, no).
 * <p>The caller must pass in two temp mpInts. This function will
 * change them and not restore them. By passing them, the function does
 * not need to create new ones all the time.
 *
 * @param mpCtx The MpCtx to use, both MpInts should have been built
 * using this ctx.
 * @param relativPrime The value against we're checking all prime
 * candidates.
 * @param prime The prime candidate, we'll check to see that prime - 1
 * is relatively prime with the relativePrime arg.
 * @param relPrime The address where the function will deposit the
 * result, 1 for true, 0 for false.
 * @param temp1 A temp mpInt for the function to use.
 * @param temp2 Another temp mpInt for the function to use.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
int VOLT_CALLING_CONV VoltCheckRelativePrime VOLT_PROTO_LIST ((
   VoltMpIntCtx *mpCtx,
   VoltMpInt *relativePrime,
   VoltMpInt *prime,
   VoltMpInt *temp1,
   VoltMpInt *temp2,
   unsigned int *relPrime
));

/* Add increment to the buffer.
 * <p>This function will take the four bytes of increment and add them
 * to the buffer, beginning with the least significant byte. In other
 * words, this adds a vector of length 4 (passed as a UInt32) to a
 * vector of length bufferLen.
 * <p>Some prime finding routines need this to digest a seed plus
 * counter.
 */
void VOLT_CALLING_CONV VoltAddValueToBuffer VOLT_PROTO_LIST ((
   unsigned char *buffer,
   unsigned int bufferLen,
   UInt32 increment
));

/* Perform sieving on the prime candidate.
 * <p>The sieve represents primeCandidate + increment. The increment is
 * 2 so that we represent only odd numbers.
 *    sieve[0] represents primeCandidate
 *    sieve[1] represents primeCandidate + 2
 *    sieve[2] represents primeCandidate + 4
 *       ...
 * <p> If primeCandidate is evenly divisible by 3, then it is not a
 * prime, no need to run a "costlier" test. But we also know that
 * primeCandidate + 3 and primeCandidate + 6 and so on are also
 * definitely not prime.
 * <p>If primeCandidate is evenly divisible by 5, then it is not a
 * prime, and so on.
 * <p>For all the entries in the sieve, set the value to 0 or 1. If 0,
 * we could not find a prime that evenly divides the candidate. If 1,
 * we did find a divisor. Later on we'll run a stricter test (such as
 * Rabin-Miller) on those entries with the 0. This way, we'll run the
 * time-consuming test fewer times.
 * <p>One more thing, we'll divide primeCandidate by 3. If it does not
 * divide evenly, we'll find the remainder. We can't set sieve[0] to 1,
 * but we know that 3 evenly divides candidate+(candidate-remainder).
 * Using this knowledge, we can still let some entries fal through the
 * sieve.
 *
 * @param primeCandidate The starting point for the sieve entriy
 * representations.
 * @param firstPrimes An array containing the first n odd primes.
 * @param firstPrimesLen How many of the first odd primes passed.
 * @param sieve An array of bytes we'll use. No need to initialize
 * their values.
 * @param sieveSize The number of entries in the sieve.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
int VOLT_CALLING_CONV VoltSieveCandidate VOLT_PROTO_LIST ((
   VoltMpInt *primeCandidate,
   unsigned int *firstPrimes,
   unsigned int firstPrimesLen,
   unsigned char *sieve,
   unsigned int sieveSize
));

/* These are the first n odd primes. Useful in sieving.
 */

/*
 * The first 53 can all be represented by a single unsigned char.
 */
#define FIRST_53_ODD_PRIMES { \
      3,     5,     7,    11,    13,    17,    19,    23, \
     29,    31,    37,    41,    43,    47,    53,    59, \
     61,    67,    71,    73,    79,    83,    89,    97, \
    101,   103,   107,   109,   113,   127,   131,   137, \
    139,   149,   151,   157,   163,   167,   173,   179, \
    181,   191,   193,   197,   199,   211,   223,   227, \
    229,   233,   239,   241,   251 \
}

/* If you are using the first 100 primes, they must reside in a type
 * larger than an unsigned char.
 */
#define FIRST_100_ODD_PRIMES { \
      3,     5,     7,    11,    13,    17,    19,    23, \
     29,    31,    37,    41,    43,    47,    53,    59, \
     61,    67,    71,    73,    79,    83,    89,    97, \
    101,   103,   107,   109,   113,   127,   131,   137, \
    139,   149,   151,   157,   163,   167,   173,   179, \
    181,   191,   193,   197,   199,   211,   223,   227, \
    229,   233,   239,   241,   251,   257,   263,   269, \
    271,   277,   281,   283,   293,   307,   311,   313, \
    317,   331,   337,   347,   349,   353,   359,   367, \
    373,   379,   383,   389,   397,   401,   409,   419, \
    421,   431,   433,   439,   443,   449,   457,   461, \
    463,   467,   479,   487,   491,   499,   503,   509, \
    521,   523,   541,   547 \
}

#ifdef __cplusplus
}
#endif

#endif /* _PRIME_H */

⌨️ 快捷键说明

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