Rik Van Dyck / Mbed 2 deprecated Project_Embedded_C

Dependencies:   mbed DS1307 Servo TextLCD

Committer:
rikvandyck
Date:
Thu Dec 04 10:44:07 2014 +0000
Revision:
0:e1edd52b1ee2
test

Who changed what in which revision?

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