comparison libtomcrypt/src/misc/mpi/rand_prime.c @ 293:9d110777f345 contrib-blacklist

propagate from branch 'au.asn.ucc.matt.dropbear' (head 7ad1775ed65e75dbece27fe6b65bf1a234db386a) to branch 'au.asn.ucc.matt.dropbear.contrib.blacklist' (head 1d86a4f0a401cc68c2670d821a2f6366c37af143)
author Matt Johnston <matt@ucc.asn.au>
date Fri, 10 Mar 2006 06:31:29 +0000
parents 1b9e69c058d2
children
comparison
equal deleted inserted replaced
247:c07de41b53d7 293:9d110777f345
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org
10 */
11 #include "tomcrypt.h"
12
13 /**
14 @file rand_prime.c
15 Generate a random prime, Tom St Denis
16 */
17 #ifdef MPI
18
19 struct rng_data {
20 prng_state *prng;
21 int wprng;
22 };
23
24 static int rand_prime_helper(unsigned char *dst, int len, void *dat)
25 {
26 return (int)prng_descriptor[((struct rng_data *)dat)->wprng].read(dst, len, ((struct rng_data *)dat)->prng);
27 }
28
29 int rand_prime(mp_int *N, long len, prng_state *prng, int wprng)
30 {
31 struct rng_data rng;
32 int type, err;
33
34 LTC_ARGCHK(N != NULL);
35
36 /* allow sizes between 2 and 256 bytes for a prime size */
37 if (len < 16 || len > 4096) {
38 return CRYPT_INVALID_PRIME_SIZE;
39 }
40
41 /* valid PRNG? Better be! */
42 if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
43 return err;
44 }
45
46 /* setup our callback data, then world domination! */
47 rng.prng = prng;
48 rng.wprng = wprng;
49
50 /* get type */
51 if (len < 0) {
52 type = LTM_PRIME_BBS;
53 len = -len;
54 } else {
55 type = 0;
56 }
57 type |= LTM_PRIME_2MSB_ON;
58
59 /* New prime generation makes the code even more cryptoish-insane. Do you know what this means!!!
60 -- Gir: Yeah, oh wait, er, no.
61 */
62 return mpi_to_ltc_error(mp_prime_random_ex(N, mp_prime_rabin_miller_trials(len), len, type, rand_prime_helper, &rng));
63 }
64
65 #endif
66
67
68 /* $Source: /cvs/libtom/libtomcrypt/src/misc/mpi/rand_prime.c,v $ */
69 /* $Revision: 1.3 $ */
70 /* $Date: 2005/05/05 14:35:59 $ */