Mercurial > dropbear
comparison libtomcrypt/src/prngs/rng_make_prng.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 | 0cbe8f6dbf9e |
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 rng_make_prng.c | |
15 portable way to get secure random bits to feed a PRNG (Tom St Denis) | |
16 */ | |
17 | |
18 /** | |
19 Create a PRNG from a RNG | |
20 @param bits Number of bits of entropy desired (64 ... 1024) | |
21 @param wprng Index of which PRNG to setup | |
22 @param prng [out] PRNG state to initialize | |
23 @param callback A pointer to a void function for when the RNG is slow, this can be NULL | |
24 @return CRYPT_OK if successful | |
25 */ | |
26 int rng_make_prng(int bits, int wprng, prng_state *prng, | |
27 void (*callback)(void)) | |
28 { | |
29 unsigned char buf[256]; | |
30 int err; | |
31 | |
32 LTC_ARGCHK(prng != NULL); | |
33 | |
34 /* check parameter */ | |
35 if ((err = prng_is_valid(wprng)) != CRYPT_OK) { | |
36 return err; | |
37 } | |
38 | |
39 if (bits < 64 || bits > 1024) { | |
40 return CRYPT_INVALID_PRNGSIZE; | |
41 } | |
42 | |
43 if ((err = prng_descriptor[wprng].start(prng)) != CRYPT_OK) { | |
44 return err; | |
45 } | |
46 | |
47 bits = ((bits/8)+((bits&7)!=0?1:0)) * 2; | |
48 if (rng_get_bytes(buf, (unsigned long)bits, callback) != (unsigned long)bits) { | |
49 return CRYPT_ERROR_READPRNG; | |
50 } | |
51 | |
52 if ((err = prng_descriptor[wprng].add_entropy(buf, (unsigned long)bits, prng)) != CRYPT_OK) { | |
53 return err; | |
54 } | |
55 | |
56 if ((err = prng_descriptor[wprng].ready(prng)) != CRYPT_OK) { | |
57 return err; | |
58 } | |
59 | |
60 #ifdef LTC_CLEAN_STACK | |
61 zeromem(buf, sizeof(buf)); | |
62 #endif | |
63 return CRYPT_OK; | |
64 } | |
65 | |
66 | |
67 /* $Source: /cvs/libtom/libtomcrypt/src/prngs/rng_make_prng.c,v $ */ | |
68 /* $Revision: 1.3 $ */ | |
69 /* $Date: 2005/05/05 14:35:59 $ */ |