save loops

Dependencies:   mbed

Committer:
mbedalvaro
Date:
Tue Dec 02 08:29:59 2014 +0000
Revision:
1:3be7b7d050f4
Parent:
0:df6fdd9b99f0
updated

Who changed what in which revision?

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