Dependencies:   mbed

Committer:
robertcook
Date:
Wed Jun 13 18:39:46 2012 +0000
Revision:
0:32a0996dff0f

        

Who changed what in which revision?

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