Dependencies:   mbed

Committer:
gbeardall
Date:
Mon Oct 17 10:39:17 2011 +0000
Revision:
0:715023d993d6

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gbeardall 0:715023d993d6 1 /*****************************************************************************
gbeardall 0:715023d993d6 2 * randm.h - Random number generator header file.
gbeardall 0:715023d993d6 3 *
gbeardall 0:715023d993d6 4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
gbeardall 0:715023d993d6 5 * Copyright (c) 1998 Global Election Systems Inc.
gbeardall 0:715023d993d6 6 *
gbeardall 0:715023d993d6 7 * The authors hereby grant permission to use, copy, modify, distribute,
gbeardall 0:715023d993d6 8 * and license this software and its documentation for any purpose, provided
gbeardall 0:715023d993d6 9 * that existing copyright notices are retained in all copies and that this
gbeardall 0:715023d993d6 10 * notice and the following disclaimer are included verbatim in any
gbeardall 0:715023d993d6 11 * distributions. No written agreement, license, or royalty fee is required
gbeardall 0:715023d993d6 12 * for any of the authorized uses.
gbeardall 0:715023d993d6 13 *
gbeardall 0:715023d993d6 14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
gbeardall 0:715023d993d6 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
gbeardall 0:715023d993d6 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
gbeardall 0:715023d993d6 17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
gbeardall 0:715023d993d6 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
gbeardall 0:715023d993d6 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
gbeardall 0:715023d993d6 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
gbeardall 0:715023d993d6 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
gbeardall 0:715023d993d6 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
gbeardall 0:715023d993d6 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
gbeardall 0:715023d993d6 24 *
gbeardall 0:715023d993d6 25 ******************************************************************************
gbeardall 0:715023d993d6 26 * REVISION HISTORY
gbeardall 0:715023d993d6 27 *
gbeardall 0:715023d993d6 28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
gbeardall 0:715023d993d6 29 * Ported to lwIP.
gbeardall 0:715023d993d6 30 * 98-05-29 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
gbeardall 0:715023d993d6 31 * Extracted from avos.
gbeardall 0:715023d993d6 32 *****************************************************************************/
gbeardall 0:715023d993d6 33
gbeardall 0:715023d993d6 34 #ifndef RANDM_H
gbeardall 0:715023d993d6 35 #define RANDM_H
gbeardall 0:715023d993d6 36
gbeardall 0:715023d993d6 37 /***********************
gbeardall 0:715023d993d6 38 *** PUBLIC FUNCTIONS ***
gbeardall 0:715023d993d6 39 ***********************/
gbeardall 0:715023d993d6 40 /*
gbeardall 0:715023d993d6 41 * Initialize the random number generator.
gbeardall 0:715023d993d6 42 */
gbeardall 0:715023d993d6 43 void avRandomInit(void);
gbeardall 0:715023d993d6 44
gbeardall 0:715023d993d6 45 /*
gbeardall 0:715023d993d6 46 * Churn the randomness pool on a random event. Call this early and often
gbeardall 0:715023d993d6 47 * on random and semi-random system events to build randomness in time for
gbeardall 0:715023d993d6 48 * usage. For randomly timed events, pass a null pointer and a zero length
gbeardall 0:715023d993d6 49 * and this will use the system timer and other sources to add randomness.
gbeardall 0:715023d993d6 50 * If new random data is available, pass a pointer to that and it will be
gbeardall 0:715023d993d6 51 * included.
gbeardall 0:715023d993d6 52 */
gbeardall 0:715023d993d6 53 void avChurnRand(char *randData, u32_t randLen);
gbeardall 0:715023d993d6 54
gbeardall 0:715023d993d6 55 /*
gbeardall 0:715023d993d6 56 * Randomize our random seed value. To be called for truely random events
gbeardall 0:715023d993d6 57 * such as user operations and network traffic.
gbeardall 0:715023d993d6 58 */
gbeardall 0:715023d993d6 59 #if MD5_SUPPORT
gbeardall 0:715023d993d6 60 #define avRandomize() avChurnRand(NULL, 0)
gbeardall 0:715023d993d6 61 #else /* MD5_SUPPORT */
gbeardall 0:715023d993d6 62 void avRandomize(void);
gbeardall 0:715023d993d6 63 #endif /* MD5_SUPPORT */
gbeardall 0:715023d993d6 64
gbeardall 0:715023d993d6 65 /*
gbeardall 0:715023d993d6 66 * Use the random pool to generate random data. This degrades to pseudo
gbeardall 0:715023d993d6 67 * random when used faster than randomness is supplied using churnRand().
gbeardall 0:715023d993d6 68 * Thus it's important to make sure that the results of this are not
gbeardall 0:715023d993d6 69 * published directly because one could predict the next result to at
gbeardall 0:715023d993d6 70 * least some degree. Also, it's important to get a good seed before
gbeardall 0:715023d993d6 71 * the first use.
gbeardall 0:715023d993d6 72 */
gbeardall 0:715023d993d6 73 void avGenRand(char *buf, u32_t bufLen);
gbeardall 0:715023d993d6 74
gbeardall 0:715023d993d6 75 /*
gbeardall 0:715023d993d6 76 * Return a new random number.
gbeardall 0:715023d993d6 77 */
gbeardall 0:715023d993d6 78 u32_t avRandom(void);
gbeardall 0:715023d993d6 79
gbeardall 0:715023d993d6 80
gbeardall 0:715023d993d6 81 #endif /* RANDM_H */