hattori&ide

Dependencies:   mbed

Committer:
hattori_atsushi
Date:
Sun Dec 18 08:16:01 2022 +0000
Revision:
0:f77369cabd75
hattori

Who changed what in which revision?

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