diff options
| author | Joe Maples <joe@frap129.org> | 2016-08-24 20:49:45 +0000 |
|---|---|---|
| committer | Mister Oyster <oysterized@gmail.com> | 2017-04-11 10:57:05 +0200 |
| commit | becbea27c7aac02f38b2ff0b0793c49cdd84f1de (patch) | |
| tree | e056258742c1f41777e81c04c159b4a441c5c6b4 | |
| parent | 348fec78a63fc91b4d0bf2534d56b4f7cb7a27c1 (diff) | |
random: Add get_random_long fucntion
Signed-off-by: Joe Maples <joe@frap129.org>
| -rw-r--r-- | drivers/char/random.c | 22 | ||||
| -rw-r--r-- | include/linux/random.h | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c index 48aa67d80..29db712b1 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1745,6 +1745,28 @@ unsigned int get_random_int(void) EXPORT_SYMBOL(get_random_int); /* + * Same as get_random_int(), but returns unsigned long. + */ +unsigned long get_random_long(void) +{ + __u32 *hash; + unsigned long ret; + + if (arch_get_random_long(&ret)) + return ret; + + hash = get_cpu_var(get_random_int_hash); + + hash[0] += current->pid + jiffies + get_cycles(); + md5_transform(hash, random_int_secret); + ret = *(unsigned long *)hash; + put_cpu_var(get_random_int_hash); + + return ret; +} +EXPORT_SYMBOL(get_random_long); + +/* * randomize_range() returns a start address such that * * [...... <range> .....] diff --git a/include/linux/random.h b/include/linux/random.h index b05856e16..0fe49a14d 100644 --- a/include/linux/random.h +++ b/include/linux/random.h @@ -23,6 +23,7 @@ extern const struct file_operations random_fops, urandom_fops; #endif unsigned int get_random_int(void); +unsigned long get_random_long(void); unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len); u32 prandom_u32(void); |
