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