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