The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
rand.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /** Functions to get randomness
19  *
20  * @file src/lib/util/rand.h
21  *
22  * @copyright 1999-2017 The FreeRADIUS server project
23  */
24 RCSIDH(rand_h, "$Id: ab20de60ada0a887443803d944e823eafd1c35d4 $")
25 
26 #include <freeradius-devel/build.h>
27 #include <freeradius-devel/missing.h>
28 
29 #include <stddef.h>
30 #include <stdint.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /* random numbers in isaac.c */
37 /* context of random number generator */
38 typedef struct {
40  uint32_t randrsl[256];
41  uint32_t randmem[256];
45 } fr_randctx;
46 
47 /** Smaller fast random number generator.
48  *
49  * From George Marsaglia's Multiply with Carry (MWC) algorithm.
50  *
51  * The two seeds here should be initialized by calling fr_rand(),
52  * or for tests, via some static values.
53  */
54 typedef struct {
55  uint32_t a, b;
57 
58 void fr_isaac(fr_randctx *ctx);
59 void fr_isaac_init(fr_randctx *ctx, int flag);
60 /** @hidecallergraph */
61 uint32_t fr_rand(void); /* like rand(), but better. */
62 
63 void fr_rand_init(void);
64 void fr_rand_buffer(void *start, size_t length) CC_HINT(nonnull);
65 void fr_rand_str(uint8_t *out, size_t len, char class);
66 void fr_rand_mixin(void const *, size_t ) CC_HINT(nonnull);
68 
69 #ifdef __cplusplus
70 }
71 #endif
#define RCSIDH(h, id)
Definition: build.h:445
unsigned int uint32_t
Definition: merged_model.c:33
unsigned char uint8_t
Definition: merged_model.c:30
void fr_rand_mixin(void const *, size_t)
Mix data into the random number generator.
Definition: rand.c:80
uint32_t randb
Definition: rand.h:43
uint32_t fr_fast_rand(fr_fast_rand_t *ctx)
Definition: rand.c:280
void fr_isaac_init(fr_randctx *ctx, int flag)
Definition: isaac.c:85
void fr_rand_init(void)
Definition: rand.c:34
void fr_isaac(fr_randctx *ctx)
Definition: isaac.c:46
uint32_t randc
Definition: rand.h:44
void fr_rand_str(uint8_t *out, size_t len, char class)
Generate a random string.
Definition: rand.c:164
uint32_t randcnt
Definition: rand.h:39
uint32_t fr_rand(void)
Return a 32-bit random number.
Definition: rand.c:106
void fr_rand_buffer(void *start, size_t length)
Definition: rand.c:126
uint32_t randa
Definition: rand.h:42
uint32_t a
Definition: rand.h:55
Smaller fast random number generator.
Definition: rand.h:54
int nonnull(2, 5))
static size_t char ** out
Definition: value.h:984